[dart2js]: require dart2js to be invoked from an approved CLI

The dart2js snapshot is not meant to be invoked directly except from
a limited set of entry points (CLIs and internal build systems).
This change makes it an error to invoke it in unsupported ways.

Note: this change is not expected to be visible to end users.

Fixes #51695

Change-Id: I4013dd00b90bb3d54483e2f112e0ddfb8dc694e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289885
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Sigmund Cherem 2023-03-23 01:58:58 +00:00 committed by Commit Queue
parent 9231c6182c
commit f72782ce9b
5 changed files with 31 additions and 7 deletions

View file

@ -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.

View file

@ -732,13 +732,6 @@ Future<api.CompilationResult> compile(List<String> 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<api.CompilationResult> compile(List<String> 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 &&

View file

@ -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)}',

View file

@ -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=" +

View file

@ -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"),