Skip to content

Commit f72782c

Browse files
sigmundchCommit Queue
authored and
Commit Queue
committed
[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 <[email protected]> Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Sigmund Cherem <[email protected]>
1 parent 9231c61 commit f72782c

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@
171171
#### Web Dev Compiler (DDC)
172172
- Removed deprecated command line flags `-k`, `--kernel`, and `--dart-sdk`.
173173

174+
#### Dart2js
175+
176+
- Cleanup related to [#46100](https://github.com/dart-lang/sdk/issues/46100):
177+
the internal dart2js snapshot fails unless it is called from a supported
178+
interface, such as `dart compile js`, `flutter build`, or
179+
`build_web_compilers`. This is not expected to be a visible change.
180+
174181
#### Formatter
175182

176183
* Format `sync*` and `async*` functions with `=>` bodies.

pkg/compiler/lib/src/dart2js.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,6 @@ Future<api.CompilationResult> compile(List<String> argv,
732732

733733
parseCommandLine(handlers, argv);
734734

735-
if (invoker == null) {
736-
warning("The 'dart2js' entrypoint script is deprecated, "
737-
"please use 'dart compile js' instead.");
738-
} else if (verbose != null && !wantHelp) {
739-
print("Compiler invoked from: '$invoker'");
740-
}
741-
742735
final diagnostic = diagnosticHandler = FormattingDiagnosticHandler();
743736
if (verbose != null) {
744737
diagnostic.verbose = verbose!;
@@ -778,6 +771,22 @@ Future<api.CompilationResult> compile(List<String> argv,
778771
helpAndExit(wantHelp, wantVersion, diagnostic.verbose);
779772
}
780773

774+
if (invoker == null) {
775+
final message = "The 'dart2js' entrypoint script is deprecated, "
776+
"please use 'dart compile js' instead.";
777+
// Aside from asking for `-h`, dart2js fails when it is invoked from its
778+
// snapshot directly and not using the supported workflows. However, we
779+
// allow invoking dart2js from Dart sources to support the dart2js team
780+
// local workflows and testing.
781+
if (!Platform.script.path.endsWith(".dart")) {
782+
_fail(message);
783+
} else {
784+
warning(message);
785+
}
786+
} else if (verbose != null) {
787+
print("Compiler invoked from: '$invoker'");
788+
}
789+
781790
if (arguments.isEmpty &&
782791
entryUri == null &&
783792
inputDillUri == null &&

pkg/compiler/tool/modular_test_suite_helper.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ class ModularAnalysisStep extends IOModularStep {
269269
_dart2jsScript,
270270
Flags.soundNullSafety,
271271
if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot',
272+
if (_options.useSdk) '--invoker=modular_test',
272273
// If we have sources, then we aren't building the SDK, otherwise we
273274
// assume we are building the sdk and pass in a full dill.
274275
if (sources.isNotEmpty)
@@ -344,6 +345,7 @@ class ConcatenateDillsStep extends IOModularStep {
344345
_dart2jsScript,
345346
// TODO(sigmund): remove this dependency on libraries.json
346347
if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot',
348+
if (_options.useSdk) '--invoker=modular_test',
347349
Flags.soundNullSafety,
348350
'${Flags.entryUri}=$fakeRoot${module.mainSource}',
349351
'${Flags.inputDill}=${toUri(module, dillId)}',
@@ -405,6 +407,7 @@ class ComputeClosedWorldStep extends IOModularStep {
405407
_dart2jsScript,
406408
// TODO(sigmund): remove this dependency on libraries.json
407409
if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot',
410+
if (_options.useSdk) '--invoker=modular_test',
408411
Flags.soundNullSafety,
409412
'${Flags.entryUri}=$fakeRoot${module.mainSource}',
410413
'${Flags.inputDill}=${toUri(module, fullDillId)}',
@@ -455,6 +458,7 @@ class GlobalAnalysisStep extends IOModularStep {
455458
_dart2jsScript,
456459
// TODO(sigmund): remove this dependency on libraries.json
457460
if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot',
461+
if (_options.useSdk) '--invoker=modular_test',
458462
Flags.soundNullSafety,
459463
'${Flags.entryUri}=$fakeRoot${module.mainSource}',
460464
'${Flags.inputDill}=${toUri(module, globalUpdatedDillId)}',
@@ -509,6 +513,7 @@ class Dart2jsCodegenStep extends IOModularStep {
509513
'--packages=${sdkRoot.toFilePath()}/$packageConfigJsonPath',
510514
_dart2jsScript,
511515
if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot',
516+
if (_options.useSdk) '--invoker=modular_test',
512517
Flags.soundNullSafety,
513518
'${Flags.entryUri}=$fakeRoot${module.mainSource}',
514519
'${Flags.inputDill}=${toUri(module, globalUpdatedDillId)}',
@@ -563,6 +568,7 @@ class Dart2jsEmissionStep extends IOModularStep {
563568
'--packages=${sdkRoot.toFilePath()}/$packageConfigJsonPath',
564569
_dart2jsScript,
565570
if (_options.useSdk) '--libraries-spec=$_librarySpecForSnapshot',
571+
if (_options.useSdk) '--invoker=modular_test',
566572
Flags.soundNullSafety,
567573
'${Flags.entryUri}=$fakeRoot${module.mainSource}',
568574
'${Flags.inputDill}=${toUri(module, globalUpdatedDillId)}',

utils/compiler/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ application_snapshot("dart2js") {
6363
vm_args = []
6464
main_dart = "$target_gen_dir/dart2js.dart"
6565
training_args = [
66+
"--invoker=gn_build",
6667
"--packages=" +
6768
rebase_path("../../.dart_tool/package_config.json", root_build_dir),
6869
"--libraries-spec=" +

utils/dartdevc/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ template("dart2js_compile") {
7878
args = [
7979
"$abs_main",
8080
"-m",
81+
"--invoker=gn_build",
8182
"-o$abs_output",
8283
"--no-source-maps",
8384
"--platform-binaries=" + rebase_path("$root_out_dir"),

0 commit comments

Comments
 (0)