[ CLI ] Support --enable-asserts for aot-snapshot and exe compile modes
Fixes https://github.com/dart-lang/sdk/issues/53343 TEST=compile_test.dart Change-Id: Ic99988fe253b8c6dd2a03121ba7d0a525633c7cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361960 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
@@ -116,6 +116,7 @@ Future<ProcessResult> generateKernelHelper({
|
||||
List<String> extraGenKernelOptions = const [],
|
||||
String? nativeAssets,
|
||||
String? resourcesFile,
|
||||
bool enableAsserts = false,
|
||||
bool fromDill = false,
|
||||
bool aot = false,
|
||||
bool embedSources = false,
|
||||
@@ -132,6 +133,7 @@ Future<ProcessResult> generateKernelHelper({
|
||||
if (aot) '--aot',
|
||||
if (!embedSources) '--no-embed-sources',
|
||||
if (!linkPlatform) '--no-link-platform',
|
||||
if (enableAsserts) '--enable-asserts',
|
||||
...defines.map((d) => '-D$d'),
|
||||
if (packages != null) '--packages=$packages',
|
||||
if (nativeAssets != null) '--native-assets=$nativeAssets',
|
||||
@@ -147,6 +149,7 @@ Future<ProcessResult> generateAotSnapshotHelper(
|
||||
String kernelFile,
|
||||
String snapshotFile,
|
||||
String? debugFile,
|
||||
bool enableAsserts,
|
||||
List<String> extraGenSnapshotOptions) {
|
||||
return Process.run(genSnapshot, [
|
||||
'--snapshot-kind=app-aot-elf',
|
||||
@@ -154,6 +157,7 @@ Future<ProcessResult> generateAotSnapshotHelper(
|
||||
if (debugFile != null) '--save-debugging-info=$debugFile',
|
||||
if (debugFile != null) '--dwarf-stack-traces',
|
||||
if (debugFile != null) '--strip',
|
||||
if (enableAsserts) '--enable-asserts',
|
||||
...extraGenSnapshotOptions,
|
||||
kernelFile
|
||||
]);
|
||||
|
||||
@@ -71,6 +71,7 @@ Future<void> generateNative({
|
||||
String? nativeAssets,
|
||||
String? resourcesFile,
|
||||
String enableExperiment = '',
|
||||
bool enableAsserts = false,
|
||||
bool soundNullSafety = true,
|
||||
bool verbose = false,
|
||||
String verbosity = 'all',
|
||||
@@ -115,6 +116,7 @@ Future<void> generateNative({
|
||||
packages: packages,
|
||||
defines: defines,
|
||||
fromDill: await isKernelFile(sourcePath),
|
||||
enableAsserts: enableAsserts,
|
||||
enableExperiment: enableExperiment,
|
||||
targetOS: targetOS,
|
||||
extraGenKernelOptions: [
|
||||
@@ -144,6 +146,7 @@ Future<void> generateNative({
|
||||
kernelFile,
|
||||
snapshotFile,
|
||||
debugPath,
|
||||
enableAsserts,
|
||||
extraAotOptions,
|
||||
);
|
||||
|
||||
|
||||
@@ -410,8 +410,12 @@ class CompileNativeCommand extends CompileSubcommandCommand {
|
||||
help: defineOption.help,
|
||||
abbr: defineOption.abbr,
|
||||
valueHelp: defineOption.valueHelp,
|
||||
);
|
||||
argParser
|
||||
)
|
||||
..addFlag(
|
||||
'enable-asserts',
|
||||
negatable: false,
|
||||
help: 'Enable assert statements.',
|
||||
)
|
||||
..addOption(
|
||||
packagesOption.flag,
|
||||
abbr: packagesOption.abbr,
|
||||
@@ -510,6 +514,7 @@ Remove debugging information from the output and save it separately to the speci
|
||||
defines: args.multiOption(defineOption.flag),
|
||||
packages: args.option('packages'),
|
||||
enableExperiment: args.enabledExperiments.join(','),
|
||||
enableAsserts: args.flag('enable-asserts'),
|
||||
soundNullSafety: args.flag('sound-null-safety'),
|
||||
debugFile: args.option('save-debugging-info'),
|
||||
verbose: verbose,
|
||||
|
||||
@@ -27,6 +27,7 @@ const String unsoundNullSafetyError =
|
||||
'Error: the flag --no-sound-null-safety is not supported in Dart 3.';
|
||||
const String unsoundNullSafetyWarning =
|
||||
'Warning: the flag --no-sound-null-safety is deprecated and pending removal.';
|
||||
const String failedAssertionError = 'Failed assertion: line';
|
||||
String usingTargetOSMessageForPlatform(String targetOS) =>
|
||||
'Specializing Platform getters for target OS $targetOS.';
|
||||
final String usingTargetOSMessage =
|
||||
@@ -775,6 +776,37 @@ void main() {
|
||||
expect(result.exitCode, 0);
|
||||
}, skip: isRunningOnIA32);
|
||||
|
||||
test('Compile exe with asserts', () async {
|
||||
final p = project(mainSrc: '''
|
||||
void main() {
|
||||
assert(int.parse('1') == 2);
|
||||
}
|
||||
''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
|
||||
|
||||
final result = await p.run(
|
||||
[
|
||||
'compile',
|
||||
'exe',
|
||||
'--enable-asserts',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
// Only printed when -v/--verbose is used, not --verbosity.
|
||||
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
|
||||
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, 0);
|
||||
|
||||
final runResult = await Process.run(outFile, []);
|
||||
expect(runResult.stdout, isEmpty);
|
||||
expect(runResult.stderr, contains(failedAssertionError));
|
||||
}, skip: isRunningOnIA32);
|
||||
|
||||
test('Compile exe from kernel', () async {
|
||||
final p = project(mainSrc: '''
|
||||
void main() {}
|
||||
@@ -1037,6 +1069,41 @@ void main() {
|
||||
expect(result.exitCode, 0);
|
||||
}, skip: isRunningOnIA32);
|
||||
|
||||
test('Compile AOT snapshot with asserts', () async {
|
||||
final p = project(mainSrc: '''
|
||||
void main() {
|
||||
assert(int.parse('1') == 2);
|
||||
}
|
||||
''');
|
||||
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
|
||||
final outFile = path.canonicalize(path.join(p.dirPath, 'myaot'));
|
||||
|
||||
var result = await p.run(
|
||||
[
|
||||
'compile',
|
||||
'aot-snapshot',
|
||||
'--enable-asserts',
|
||||
'-o',
|
||||
outFile,
|
||||
inFile,
|
||||
],
|
||||
);
|
||||
|
||||
// Only printed when -v/--verbose is used, not --verbosity.
|
||||
expect(result.stdout, isNot(contains(usingTargetOSMessage)));
|
||||
expect(result.stdout, isNot(contains(soundNullSafetyMessage)));
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, 0);
|
||||
|
||||
final Directory binDir = File(Platform.resolvedExecutable).parent;
|
||||
result = await Process.run(
|
||||
path.join(binDir.path, 'dartaotruntime'),
|
||||
[outFile],
|
||||
);
|
||||
expect(result.stdout, isEmpty);
|
||||
expect(result.stderr, contains(failedAssertionError));
|
||||
}, skip: isRunningOnIA32);
|
||||
|
||||
test('Compile AOT snapshot from kernel', () async {
|
||||
final p = project(mainSrc: '''
|
||||
void main() {}
|
||||
|
||||
+7
-2
@@ -1030,9 +1030,14 @@ char* Dart::FeaturesString(IsolateGroup* isolate_group,
|
||||
|
||||
ADD_FLAG(tsan, kTargetUsesThreadSanitizer)
|
||||
|
||||
// Enabling assertions affects deopt ids.
|
||||
ADD_ISOLATE_GROUP_FLAG(asserts, enable_asserts, FLAG_enable_asserts);
|
||||
if (kind == Snapshot::kFullJIT) {
|
||||
// Enabling assertions affects deopt ids.
|
||||
//
|
||||
// This flag is only used at compile time for AOT, so it's only relevant
|
||||
// when running JIT snapshots. We can omit this flag for AOT snapshots so
|
||||
// feature verification won't fail if --enable-snapshots isn't provided
|
||||
// at runtime.
|
||||
ADD_ISOLATE_GROUP_FLAG(asserts, enable_asserts, FLAG_enable_asserts);
|
||||
ADD_ISOLATE_GROUP_FLAG(use_field_guards, use_field_guards,
|
||||
FLAG_use_field_guards);
|
||||
ADD_ISOLATE_GROUP_FLAG(use_osr, use_osr, FLAG_use_osr);
|
||||
|
||||
Reference in New Issue
Block a user