diff --git a/CHANGELOG.md b/CHANGELOG.md index 18decae008b..64cd46a64e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -171,6 +171,13 @@ #### Web Dev Compiler (DDC) - Removed deprecated command line flags `-k`, `--kernel`, and `--dart-sdk`. +#### Dart2js + +- Cleanup related to [#46100](https://github.com/dart-lang/sdk/issues/46100): + the internal dart2js snapshot fails unless it is called from a supported + interface, such as `dart compile js`, `flutter build`, or + `build_web_compilers`. This is not expected to be a visible change. + #### Formatter * Format `sync*` and `async*` functions with `=>` bodies. diff --git a/pkg/compiler/lib/src/dart2js.dart b/pkg/compiler/lib/src/dart2js.dart index f99409b19b9..2615a08dd8c 100644 --- a/pkg/compiler/lib/src/dart2js.dart +++ b/pkg/compiler/lib/src/dart2js.dart @@ -732,13 +732,6 @@ Future compile(List argv, parseCommandLine(handlers, argv); - if (invoker == null) { - warning("The 'dart2js' entrypoint script is deprecated, " - "please use 'dart compile js' instead."); - } else if (verbose != null && !wantHelp) { - print("Compiler invoked from: '$invoker'"); - } - final diagnostic = diagnosticHandler = FormattingDiagnosticHandler(); if (verbose != null) { diagnostic.verbose = verbose!; @@ -778,6 +771,22 @@ Future compile(List argv, helpAndExit(wantHelp, wantVersion, diagnostic.verbose); } + if (invoker == null) { + final message = "The 'dart2js' entrypoint script is deprecated, " + "please use 'dart compile js' instead."; + // Aside from asking for `-h`, dart2js fails when it is invoked from its + // snapshot directly and not using the supported workflows. However, we + // allow invoking dart2js from Dart sources to support the dart2js team + // local workflows and testing. + if (!Platform.script.path.endsWith(".dart")) { + _fail(message); + } else { + warning(message); + } + } else if (verbose != null) { + print("Compiler invoked from: '$invoker'"); + } + if (arguments.isEmpty && entryUri == null && inputDillUri == null && diff --git a/pkg/compiler/tool/modular_test_suite_helper.dart b/pkg/compiler/tool/modular_test_suite_helper.dart index 566cf764b29..66c486120c8 100644 --- a/pkg/compiler/tool/modular_test_suite_helper.dart +++ b/pkg/compiler/tool/modular_test_suite_helper.dart @@ -269,6 +269,7 @@ class ModularAnalysisStep extends IOModularStep { _dart2jsScript, Flags.soundNullSafety, if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot', + if (_options.useSdk) '--invoker=modular_test', // If we have sources, then we aren't building the SDK, otherwise we // assume we are building the sdk and pass in a full dill. if (sources.isNotEmpty) @@ -344,6 +345,7 @@ class ConcatenateDillsStep extends IOModularStep { _dart2jsScript, // TODO(sigmund): remove this dependency on libraries.json if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot', + if (_options.useSdk) '--invoker=modular_test', Flags.soundNullSafety, '${Flags.entryUri}=$fakeRoot${module.mainSource}', '${Flags.inputDill}=${toUri(module, dillId)}', @@ -405,6 +407,7 @@ class ComputeClosedWorldStep extends IOModularStep { _dart2jsScript, // TODO(sigmund): remove this dependency on libraries.json if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot', + if (_options.useSdk) '--invoker=modular_test', Flags.soundNullSafety, '${Flags.entryUri}=$fakeRoot${module.mainSource}', '${Flags.inputDill}=${toUri(module, fullDillId)}', @@ -455,6 +458,7 @@ class GlobalAnalysisStep extends IOModularStep { _dart2jsScript, // TODO(sigmund): remove this dependency on libraries.json if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot', + if (_options.useSdk) '--invoker=modular_test', Flags.soundNullSafety, '${Flags.entryUri}=$fakeRoot${module.mainSource}', '${Flags.inputDill}=${toUri(module, globalUpdatedDillId)}', @@ -509,6 +513,7 @@ class Dart2jsCodegenStep extends IOModularStep { '--packages=${sdkRoot.toFilePath()}/$packageConfigJsonPath', _dart2jsScript, if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot', + if (_options.useSdk) '--invoker=modular_test', Flags.soundNullSafety, '${Flags.entryUri}=$fakeRoot${module.mainSource}', '${Flags.inputDill}=${toUri(module, globalUpdatedDillId)}', @@ -563,6 +568,7 @@ class Dart2jsEmissionStep extends IOModularStep { '--packages=${sdkRoot.toFilePath()}/$packageConfigJsonPath', _dart2jsScript, if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot', + if (_options.useSdk) '--invoker=modular_test', Flags.soundNullSafety, '${Flags.entryUri}=$fakeRoot${module.mainSource}', '${Flags.inputDill}=${toUri(module, globalUpdatedDillId)}', diff --git a/utils/compiler/BUILD.gn b/utils/compiler/BUILD.gn index 758637f59a2..d8093f97cb0 100644 --- a/utils/compiler/BUILD.gn +++ b/utils/compiler/BUILD.gn @@ -63,6 +63,7 @@ application_snapshot("dart2js") { vm_args = [] main_dart = "$target_gen_dir/dart2js.dart" training_args = [ + "--invoker=gn_build", "--packages=" + rebase_path("../../.dart_tool/package_config.json", root_build_dir), "--libraries-spec=" + diff --git a/utils/dartdevc/BUILD.gn b/utils/dartdevc/BUILD.gn index 05418a6054e..32b51a71b7d 100644 --- a/utils/dartdevc/BUILD.gn +++ b/utils/dartdevc/BUILD.gn @@ -78,6 +78,7 @@ template("dart2js_compile") { args = [ "$abs_main", "-m", + "--invoker=gn_build", "-o$abs_output", "--no-source-maps", "--platform-binaries=" + rebase_path("$root_out_dir"),