Skip to content

Commit

Permalink
[dart2js] recommend using 'dart compile js'.
Browse files Browse the repository at this point in the history
This is the first deprecation step, moving towards having dart2js
under the more general dart command line interface.

Going forward 'dart compile js' is the recommended way to invoke
dart2js.

This CL adds:
* an internal flag used to detect how was dart2js invoked and
  provide a warning when invoked in an unsupported way.
* ensures the flag is provided in the dart cli, as well as our
  (developer's only) scripts. These scripts will likely move to a
  different location in the future. Note that the `dart2js_sdk*`
  scripts are not providing this flag (these are the script that get
  eventually shipped with our built SDK), as such, invokations of the
  dart2js binary will show the new warning.

Change-Id: I96e40ecf01598eadab20dfc59114f5fff7438084
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229062
Reviewed-by: Joshua Litt <[email protected]>
Commit-Queue: Sigmund Cherem <[email protected]>
  • Loading branch information
sigmundch authored and Commit Bot committed Jan 21, 2022
1 parent c007407 commit 8415b70
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
- `IdbFactory.supportsDatabaseNames` has been deprecated. It will always return
`false`.

### Tools

#### Dart command line

- **Breaking Change** [#46100](https://github.com/dart-lang/sdk/issues/46100):
The standalone `dart2js` tool has been
marked deprecated as previously announced.
Its replacement is the `dart compile js` command.
Should you find any issues, or missing features, in the replacement
command, kindly file [an issue][].

[an issue]: https://github.com/dart-lang/sdk/issues/new

## 2.16.0

### Core libraries
Expand Down
4 changes: 4 additions & 0 deletions pkg/compiler/lib/src/commandline_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class Flags {

static const String cfeInvocationModes = '--cfe-invocation-modes';

/// Flag to indicate how the compiler is invoked. Used to ensure
/// dart2js is only invoked from supported tools and through the Dart CLI.
static const String invoker = '--invoker';

/// Flag to stop after splitting the program.
static const String stopAfterProgramSplit = '--stop-after-program-split';

Expand Down
26 changes: 24 additions & 2 deletions pkg/compiler/lib/src/dart2js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Future<api.CompilationResult> compile(List<String> argv,
ReadStrategy readStrategy = ReadStrategy.fromDart;
WriteStrategy writeStrategy = WriteStrategy.toJs;
FeatureOptions features = FeatureOptions();
String invoker;

void passThrough(String argument) => options.add(argument);
void ignoreOption(String argument) {}
Expand Down Expand Up @@ -480,6 +481,10 @@ Future<api.CompilationResult> compile(List<String> argv,
passThrough(argument);
}

void setInvoker(String argument) {
invoker = extractParameter(argument);
}

void handleThrowOnError(String argument) {
throwOnError = true;
String parameter = extractParameter(argument, isOptionalArgument: true);
Expand Down Expand Up @@ -645,6 +650,7 @@ Future<api.CompilationResult> compile(List<String> argv,
OptionHandler(Flags.testMode, passThrough),
OptionHandler('${Flags.dumpSsa}=.+', passThrough),
OptionHandler('${Flags.cfeInvocationModes}=.+', passThrough),
OptionHandler('${Flags.invoker}=.+', setInvoker),
OptionHandler('${Flags.verbosity}=.+', passThrough),

// Experimental features.
Expand Down Expand Up @@ -694,6 +700,13 @@ 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) {
print("Compiler invoked from: '$invoker'");
}

// TODO(johnniwinther): Measure time for reading files.
SourceFileProvider inputProvider;
if (bazelPaths != null) {
Expand Down Expand Up @@ -1128,7 +1141,7 @@ void help() {
// before and after running the compiler. Another two lines may be
// used to print an error message.
print('''
Usage: dart2js [options] dartfile
Usage: dart compile js [options] dartfile
Compiles Dart to JavaScript.
Expand All @@ -1140,7 +1153,7 @@ Common options:

void verboseHelp() {
print(r'''
Usage: dart2js [options] dartfile
Usage: dart compile js [options] dartfile
Compiles Dart to JavaScript.
Expand Down Expand Up @@ -1352,6 +1365,15 @@ void helpAndFail(String message) {
fail(message);
}

void warning(String message) {
if (diagnosticHandler != null) {
diagnosticHandler.report(
null, null, -1, -1, message, api.Diagnostic.WARNING);
} else {
print('Warning: $message');
}
}

Future<void> main(List<String> arguments) async {
// Expand `@path/to/file`
// When running from bazel, argument of the form `@path/to/file` might be
Expand Down
1 change: 1 addition & 0 deletions pkg/dartdev/lib/src/commands/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class CompileJSCommand extends CompileSubcommandCommand {
[
'--libraries-spec=$librariesPath',
'--cfe-invocation-modes=compile',
'--invoker=dart_cli',
...argResults.arguments,
],
packageConfigOverride: null);
Expand Down
1 change: 1 addition & 0 deletions sdk/bin/dart2js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DART="$BIN_DIR/dart"
unset EXTRA_OPTIONS
declare -a EXTRA_OPTIONS

EXTRA_OPTIONS+=('--invoker=development_script')
if test -t 1; then
# Stdout is a terminal.
if test 8 -le `tput colors`; then
Expand Down

0 comments on commit 8415b70

Please sign in to comment.