[ CLI ] Make dart {compile,build} error exit codes consistent on Windows

Setting an error code of -1 on macOS and Linux results in an error code
of 255 being set since negative error codes are subtracted from 256.
However, an error code of -1 on Windows is not converted in the same
way, resulting in a difference of behavior between OSes.

This change updates -1 error codes to be 255 so they're the same on all
OSes.

Fixes https://github.com/dart-lang/sdk/issues/54857

Change-Id: Idcfbfab30d3cc31a9e4ca630b8d94caa03ef07b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351500
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Ben Konyi 2024-02-09 22:47:39 +00:00 committed by Commit Queue
parent adee0a2399
commit 670b9ba9cf
2 changed files with 9 additions and 7 deletions

View file

@ -23,6 +23,7 @@ class BuildCommand extends DartdevCommand {
static const String cmdName = 'build';
static const String outputOptionName = 'output';
static const String formatOptionName = 'format';
static const int genericErrorExitCode = 255;
BuildCommand({bool verbose = false})
: super(cmdName, 'Build a Dart application including native assets.',
@ -83,7 +84,7 @@ class BuildCommand extends DartdevCommand {
// Similar to Dart run. Possibly also in `dart compile`.
final sourceUri = Uri(path: args.rest[0].normalizeCanonicalizePath());
if (!checkFile(sourceUri.toFilePath())) {
return -1;
return genericErrorExitCode;
}
final outputUri = Uri.directory(

View file

@ -19,6 +19,7 @@ import '../native_assets.dart';
import '../sdk.dart';
import '../utils.dart';
const int genericErrorExitCode = 255;
const int compileErrorExitCode = 64;
class Option {
@ -199,7 +200,7 @@ class CompileKernelSnapshotCommand extends CompileSubcommandCommand {
final String sourcePath = args.rest[0];
if (!checkFile(sourcePath)) {
return -1;
return genericErrorExitCode;
}
// Determine output file name.
@ -215,7 +216,7 @@ class CompileKernelSnapshotCommand extends CompileSubcommandCommand {
if (!checkFileWriteable(outputFile)) {
log.stderr('Unable to open file $outputFile for writing snapshot.');
return -1;
return genericErrorExitCode;
}
final bool soundNullSafety = args['sound-null-safety'];
@ -311,7 +312,7 @@ class CompileJitSnapshotCommand extends CompileSubcommandCommand {
final String sourcePath = args.rest[0];
if (!checkFile(sourcePath)) {
return -1;
return genericErrorExitCode;
}
// Determine output file name.
@ -325,7 +326,7 @@ class CompileJitSnapshotCommand extends CompileSubcommandCommand {
if (!checkFileWriteable(outputFile)) {
log.stderr('Unable to open file $outputFile for writing snapshot.');
return -1;
return genericErrorExitCode;
}
final enabledExperiments = args.enabledExperiments;
@ -461,7 +462,7 @@ Remove debugging information from the output and save it separately to the speci
}
final String sourcePath = args.rest[0];
if (!checkFile(sourcePath)) {
return -1;
return genericErrorExitCode;
}
if (!args['sound-null-safety'] && !shouldAllowNoSoundNullSafety()) {
@ -697,7 +698,7 @@ class CompileWasmCommand extends CompileSubcommandCommand {
}
final String sourcePath = args.rest[0];
if (!checkFile(sourcePath)) {
return -1;
return genericErrorExitCode;
}
// Determine output file name.