@@ -97,12 +97,13 @@ ${_argParser.usage}
9797''' ;
9898
9999Future <void > main (List <String > arguments) async {
100- io.exitCode = await runCompiler (_argParser. parse ( arguments) );
100+ io.exitCode = await runCompilerWithCommandLineArguments ( arguments);
101101}
102102
103- /// Run bytecode compiler tool with given [options]
104- /// and return exit code.
105- Future <int > runCompiler (ArgResults options) async {
103+ /// Run bytecode compiler tool with given [arguments]
104+ /// and return exit code (0 on success, non-zero on failure).
105+ Future <int > runCompilerWithCommandLineArguments (List <String > arguments) async {
106+ final ArgResults options = _argParser.parse (arguments);
106107 final String ? platformKernel = options['platform' ];
107108
108109 if (options['help' ]) {
@@ -131,6 +132,58 @@ Future<int> runCompiler(ArgResults options) async {
131132 return badUsageExitCode;
132133 }
133134
135+ final String ? importDill = options['import-dill' ];
136+ final String ? validateDynamicInterface = options['validate' ];
137+ final String messageVerbosity = options['verbosity' ];
138+ final String cfeInvocationModes = options['invocation-modes' ];
139+ final bool trackWidgetCreation = options['track-widget-creation' ];
140+ final List <String >? bytecodeGeneratorOptions = options['bytecode-options' ];
141+
142+ return await runCompilerWithOptions (
143+ input: input,
144+ platformKernel: platformKernel,
145+ outputFileName: outputFileName,
146+ targetName: targetName,
147+ packages: packages,
148+ importDill: importDill,
149+ validateDynamicInterface: validateDynamicInterface,
150+ enableAsserts: enableAsserts,
151+ experimentalFlags: experimentalFlags,
152+ environmentDefines: environmentDefines,
153+ fileSystemScheme: fileSystemScheme,
154+ fileSystemRoots: fileSystemRoots,
155+ messageVerbosity: messageVerbosity,
156+ cfeInvocationModes: cfeInvocationModes,
157+ trackWidgetCreation: trackWidgetCreation,
158+ bytecodeGeneratorOptions: bytecodeGeneratorOptions,
159+ depfile: depfile,
160+ depfileTarget: depfileTarget,
161+ );
162+ }
163+
164+ /// Run bytecode compiler tool with given options
165+ /// and return exit code (0 on success, non-zero on failure).
166+ Future <int > runCompilerWithOptions ({
167+ required String input,
168+ required String platformKernel,
169+ required String outputFileName,
170+ required String targetName,
171+ String ? packages,
172+ String ? importDill,
173+ String ? validateDynamicInterface,
174+ bool enableAsserts = false ,
175+ List <String >? experimentalFlags,
176+ Map <String , String > environmentDefines = const {},
177+ String ? fileSystemScheme,
178+ List <String >? fileSystemRoots,
179+ String messageVerbosity = Verbosity .defaultValue,
180+ void Function (String ) printMessage = print,
181+ String cfeInvocationModes = '' ,
182+ bool trackWidgetCreation = false ,
183+ List <String >? bytecodeGeneratorOptions,
184+ String ? depfile,
185+ String ? depfileTarget,
186+ }) async {
134187 final fileSystem =
135188 createFrontEndFileSystem (fileSystemScheme, fileSystemRoots);
136189
@@ -139,17 +192,17 @@ Future<int> runCompiler(ArgResults options) async {
139192 final platformKernelUri = Uri .base .resolveUri (new Uri .file (platformKernel));
140193
141194 final List <Uri > additionalDills = < Uri > [];
142- final String ? importDill = options['import-dill' ];
143195 if (importDill != null ) {
144196 additionalDills.add (Uri .base .resolveUri (new Uri .file (importDill)));
145197 }
146198
147- final String ? validate = options['validate' ];
148199 final Uri ? dynamicInterfaceSpecificationUri =
149- (validate != null ) ? resolveInputUri (validate) : null ;
200+ (validateDynamicInterface != null )
201+ ? resolveInputUri (validateDynamicInterface)
202+ : null ;
150203
151- final verbosity = Verbosity .parseArgument (options[ 'verbosity' ] );
152- final errorPrinter = ErrorPrinter (verbosity);
204+ final verbosity = Verbosity .parseArgument (messageVerbosity );
205+ final errorPrinter = ErrorPrinter (verbosity, println : printMessage );
153206 final errorDetector = ErrorDetector (previousErrorHandler: errorPrinter.call);
154207
155208 Uri mainUri = resolveInputUri (input);
@@ -165,20 +218,18 @@ Future<int> runCompiler(ArgResults options) async {
165218 ..dynamicInterfaceSpecificationUri = dynamicInterfaceSpecificationUri
166219 ..explicitExperimentalFlags = parseExperimentalFlags (
167220 parseExperimentalArguments (experimentalFlags),
168- onError: print )
221+ onError: printMessage )
169222 ..onDiagnostic = (DiagnosticMessage m) {
170223 errorDetector (m);
171224 }
172225 ..embedSourceText = false
173- ..invocationModes =
174- InvocationMode .parseArguments (options['invocation-modes' ])
226+ ..invocationModes = InvocationMode .parseArguments (cfeInvocationModes)
175227 ..verbosity = verbosity;
176228
177229 compilerOptions.target = createFrontEndTarget (targetName,
178- trackWidgetCreation: options['track-widget-creation' ],
179- supportMirrors: false );
230+ trackWidgetCreation: trackWidgetCreation, supportMirrors: false );
180231 if (compilerOptions.target == null ) {
181- print ('Failed to create front-end target $targetName .' );
232+ printMessage ('Failed to create front-end target $targetName .' );
182233 return badUsageExitCode;
183234 }
184235
@@ -187,7 +238,7 @@ Future<int> runCompiler(ArgResults options) async {
187238 options: compilerOptions,
188239 requireMain: false ,
189240 includePlatform: false ,
190- environmentDefines: environmentDefines,
241+ environmentDefines: Map . of ( environmentDefines) ,
191242 enableAsserts: enableAsserts));
192243
193244 errorPrinter.printCompilationMessages ();
@@ -199,7 +250,7 @@ Future<int> runCompiler(ArgResults options) async {
199250
200251 final BytecodeOptions bytecodeOptions =
201252 BytecodeOptions (enableAsserts: enableAsserts)
202- ..parseCommandLineFlags (options[ 'bytecode-options' ] );
253+ ..parseCommandLineFlags (bytecodeGeneratorOptions );
203254
204255 if (bytecodeOptions.showBytecodeSizeStatistics) {
205256 BytecodeSizeStatistics .reset ();
0 commit comments