@@ -39,6 +39,8 @@ const int _kIntVal = 0;
3939const double _kDoubleVal = 0.0 ;
4040const bool _kBoolVal = true ;
4141
42+ const String _kCompileArgsTagName = 'compile_args' ;
43+
4244int get _usageLineLength => stdout.hasTerminal ? stdout.terminalColumns : null ;
4345
4446typedef ConvertYamlToType <T > = T Function (YamlMap , String , ResourceProvider );
@@ -147,14 +149,22 @@ class ToolDefinition {
147149 List <String > command,
148150 List <String > setupCommand,
149151 String description,
150- ResourceProvider resourceProvider) {
152+ ResourceProvider resourceProvider,
153+ {List <String > compileArgs}) {
151154 assert (command != null );
152155 assert (command.isNotEmpty);
153156 assert (description != null );
154157 if (isDartExecutable (command[0 ])) {
155158 return DartToolDefinition (
156- command, setupCommand, description, resourceProvider);
159+ command, setupCommand, description, resourceProvider,
160+ compileArgs: compileArgs ?? const []);
157161 } else {
162+ if (compileArgs != null && compileArgs.isNotEmpty) {
163+ throw DartdocOptionError (
164+ 'Compile arguments may only be specified for Dart tools, but '
165+ '$_kCompileArgsTagName of $compileArgs were specified for '
166+ '$command .' );
167+ }
158168 return ToolDefinition (command, setupCommand, description);
159169 }
160170 }
@@ -274,6 +284,9 @@ class SnapshotCache {
274284class DartToolDefinition extends ToolDefinition {
275285 final ResourceProvider _resourceProvider;
276286
287+ /// A list of arguments to add to the snapshot compilation arguments.
288+ final List <String > compileArgs;
289+
277290 /// Takes a list of args to modify, and returns the name of the executable
278291 /// to run. If no snapshot file existed, then create one and modify the args
279292 /// so that if they are executed with dart, will result in the snapshot being
@@ -295,7 +308,8 @@ class DartToolDefinition extends ToolDefinition {
295308 '--ignore-unrecognized-flags' ,
296309 '--verbosity=error' ,
297310 '--snapshot=${_resourceProvider .pathContext .absolute (snapshotFile .path )}' ,
298- '--snapshot_kind=app-jit'
311+ '--snapshot_kind=app-jit' ,
312+ ...compileArgs,
299313 ]);
300314 } else {
301315 await snapshot.snapshotValid ();
@@ -307,8 +321,10 @@ class DartToolDefinition extends ToolDefinition {
307321 }
308322
309323 DartToolDefinition (List <String > command, List <String > setupCommand,
310- String description, this ._resourceProvider)
311- : super (command, setupCommand, description);
324+ String description, this ._resourceProvider,
325+ {this .compileArgs = const []})
326+ : assert (compileArgs != null ),
327+ super (command, setupCommand, description);
312328}
313329
314330/// A configuration class that can interpret [ToolDefinition] s from a YAML map.
@@ -335,6 +351,7 @@ class ToolConfiguration {
335351 for (var entry in yamlMap.entries) {
336352 var name = entry.key.toString ();
337353 var toolMap = entry.value;
354+ List <String > compileArgs;
338355 String description;
339356 List <String > command;
340357 List <String > setupCommand;
@@ -376,6 +393,27 @@ class ToolConfiguration {
376393
377394 command = findCommand ();
378395 setupCommand = findCommand ('setup_' );
396+
397+ List <String > findArgs () {
398+ List <String > args;
399+ if (toolMap.containsKey (_kCompileArgsTagName)) {
400+ var compileArgs = toolMap[_kCompileArgsTagName];
401+ if (compileArgs is String ) {
402+ args = [toolMap[_kCompileArgsTagName].toString ()];
403+ } else if (compileArgs is YamlList ) {
404+ args =
405+ compileArgs.map <String >((node) => node.toString ()).toList ();
406+ } else {
407+ throw DartdocOptionError (
408+ 'Tool compile arguments must be a list of strings. The tool '
409+ '$name has a $_kCompileArgsTagName entry that is a '
410+ '${compileArgs .runtimeType }' );
411+ }
412+ }
413+ return args;
414+ }
415+
416+ compileArgs = findArgs ();
379417 } else {
380418 throw DartdocOptionError (
381419 'Tools must be defined as a map of tool names to definitions. Tool '
@@ -421,7 +459,8 @@ class ToolConfiguration {
421459 setupCommand;
422460 }
423461 newToolDefinitions[name] = ToolDefinition .fromCommand (
424- [executable] + command, setupCommand, description, resourceProvider);
462+ [executable] + command, setupCommand, description, resourceProvider,
463+ compileArgs: compileArgs ?? const []);
425464 }
426465 return ToolConfiguration ._(newToolDefinitions, resourceProvider);
427466 }
0 commit comments