1- // Copyright (c) 2020 , the Dart project authors. Please see the AUTHORS file
1+ // Copyright (c) 2019 , the Dart project authors. Please see the AUTHORS file
22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
@@ -9,6 +9,7 @@ import 'package:dart2native/generate.dart';
99import 'package:path/path.dart' as path;
1010
1111import '../core.dart' ;
12+ import '../experiments.dart' ;
1213import '../sdk.dart' ;
1314import '../vm_interop_handler.dart' ;
1415
@@ -45,7 +46,8 @@ bool checkFile(String sourcePath) {
4546class CompileJSCommand extends CompileSubcommandCommand {
4647 static const String cmdName = 'js' ;
4748
48- CompileJSCommand () : super (cmdName, 'Compile Dart to JavaScript.' ) {
49+ CompileJSCommand ({bool verbose})
50+ : super (cmdName, 'Compile Dart to JavaScript.' ) {
4951 argParser
5052 ..addOption (
5153 commonOptions['outputFile' ].flag,
@@ -58,6 +60,7 @@ class CompileJSCommand extends CompileSubcommandCommand {
5860 abbr: 'm' ,
5961 negatable: false ,
6062 );
63+ addExperimentalFlags (argParser, verbose);
6164 }
6265
6366 @override
@@ -91,6 +94,8 @@ class CompileJSCommand extends CompileSubcommandCommand {
9194
9295 VmInteropHandler .run (sdk.dart2jsSnapshot, [
9396 '--libraries-spec=$librariesPath ' ,
97+ if (argResults.enabledExperiments.isNotEmpty)
98+ "--enable-experiment=${argResults .enabledExperiments .join (',' )}" ,
9499 ...argResults.arguments,
95100 ]);
96101
@@ -112,13 +117,15 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
112117 this .help,
113118 this .fileExt,
114119 this .formatName,
120+ bool verbose,
115121 }) : super (commandName, 'Compile Dart $help ' ) {
116122 argParser
117123 ..addOption (
118124 commonOptions['outputFile' ].flag,
119125 help: commonOptions['outputFile' ].help,
120126 abbr: commonOptions['outputFile' ].abbr,
121127 );
128+ addExperimentalFlags (argParser, verbose);
122129 }
123130
124131 @override
@@ -144,10 +151,14 @@ class CompileSnapshotCommand extends CompileSubcommandCommand {
144151 outputFile = '$inputWithoutDart .$fileExt ' ;
145152 }
146153
154+ final enabledExperiments = argResults.enabledExperiments;
147155 // Build arguments.
148156 List <String > args = [];
149157 args.add ('--snapshot-kind=$formatName ' );
150158 args.add ('--snapshot=${path .canonicalize (outputFile )}' );
159+ if (enabledExperiments.isNotEmpty) {
160+ args.add ("--enable-experiment=${enabledExperiments .join (',' )}" );
161+ }
151162 if (verbose) {
152163 args.add ('-v' );
153164 }
@@ -173,6 +184,7 @@ class CompileNativeCommand extends CompileSubcommandCommand {
173184 this .commandName,
174185 this .format,
175186 this .help,
187+ bool verbose,
176188 }) : super (commandName, 'Compile Dart $help ' ) {
177189 argParser
178190 ..addOption (
@@ -195,6 +207,8 @@ For example: dart compile $commandName --packages=/tmp/pkgs main.dart''')
195207 ..addOption ('save-debugging-info' , abbr: 'S' , valueHelp: 'path' , help: '''
196208Remove debugging information from the output and save it separately to the specified file.
197209<path> can be relative or absolute.''' );
210+
211+ addExperimentalFlags (argParser, verbose);
198212 }
199213
200214 @override
@@ -225,6 +239,7 @@ Remove debugging information from the output and save it separately to the speci
225239 defines: argResults['define' ],
226240 packages: argResults['packages' ],
227241 enableAsserts: argResults['enable-asserts' ],
242+ enableExperiment: argResults.enabledExperiments.join (',' ),
228243 debugFile: argResults['save-debugging-info' ],
229244 verbose: verbose,
230245 );
@@ -245,30 +260,36 @@ abstract class CompileSubcommandCommand extends DartdevCommand {
245260
246261class CompileCommand extends DartdevCommand {
247262 static const String cmdName = 'compile' ;
248-
249- CompileCommand () : super (cmdName, 'Compile Dart to various formats.' ) {
250- addSubcommand (CompileJSCommand ());
263+ CompileCommand ({bool verbose = false })
264+ : super (cmdName, 'Compile Dart to various formats.' ) {
265+ addSubcommand (CompileJSCommand (
266+ verbose: verbose,
267+ ));
251268 addSubcommand (CompileSnapshotCommand (
252269 commandName: CompileSnapshotCommand .jitSnapshotCmdName,
253270 help: 'to a JIT snapshot.' ,
254271 fileExt: 'jit' ,
255272 formatName: 'app-jit' ,
273+ verbose: verbose,
256274 ));
257275 addSubcommand (CompileSnapshotCommand (
258276 commandName: CompileSnapshotCommand .kernelCmdName,
259277 help: 'to a kernel snapshot.' ,
260278 fileExt: 'dill' ,
261279 formatName: 'kernel' ,
280+ verbose: verbose,
262281 ));
263282 addSubcommand (CompileNativeCommand (
264283 commandName: CompileNativeCommand .exeCmdName,
265284 help: 'to a self-contained executable.' ,
266285 format: 'exe' ,
286+ verbose: verbose,
267287 ));
268288 addSubcommand (CompileNativeCommand (
269289 commandName: CompileNativeCommand .aotSnapshotCmdName,
270290 help: 'to an AOT snapshot.' ,
271291 format: 'aot' ,
292+ verbose: verbose,
272293 ));
273294 }
274295}
0 commit comments