@@ -39,6 +39,8 @@ const int _kIntVal = 0;
39
39
const double _kDoubleVal = 0.0 ;
40
40
const bool _kBoolVal = true ;
41
41
42
+ const String _kCompileArgsTagName = 'compile_args' ;
43
+
42
44
int get _usageLineLength => stdout.hasTerminal ? stdout.terminalColumns : null ;
43
45
44
46
typedef ConvertYamlToType <T > = T Function (YamlMap , String , ResourceProvider );
@@ -147,14 +149,22 @@ class ToolDefinition {
147
149
List <String > command,
148
150
List <String > setupCommand,
149
151
String description,
150
- ResourceProvider resourceProvider) {
152
+ ResourceProvider resourceProvider,
153
+ {List <String > compileArgs}) {
151
154
assert (command != null );
152
155
assert (command.isNotEmpty);
153
156
assert (description != null );
154
157
if (isDartExecutable (command[0 ])) {
155
158
return DartToolDefinition (
156
- command, setupCommand, description, resourceProvider);
159
+ command, setupCommand, description, resourceProvider,
160
+ compileArgs: compileArgs ?? const []);
157
161
} 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
+ }
158
168
return ToolDefinition (command, setupCommand, description);
159
169
}
160
170
}
@@ -274,6 +284,9 @@ class SnapshotCache {
274
284
class DartToolDefinition extends ToolDefinition {
275
285
final ResourceProvider _resourceProvider;
276
286
287
+ /// A list of arguments to add to the snapshot compilation arguments.
288
+ final List <String > compileArgs;
289
+
277
290
/// Takes a list of args to modify, and returns the name of the executable
278
291
/// to run. If no snapshot file existed, then create one and modify the args
279
292
/// so that if they are executed with dart, will result in the snapshot being
@@ -295,7 +308,8 @@ class DartToolDefinition extends ToolDefinition {
295
308
'--ignore-unrecognized-flags' ,
296
309
'--verbosity=error' ,
297
310
'--snapshot=${_resourceProvider .pathContext .absolute (snapshotFile .path )}' ,
298
- '--snapshot_kind=app-jit'
311
+ '--snapshot_kind=app-jit' ,
312
+ ...compileArgs,
299
313
]);
300
314
} else {
301
315
await snapshot.snapshotValid ();
@@ -307,8 +321,10 @@ class DartToolDefinition extends ToolDefinition {
307
321
}
308
322
309
323
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);
312
328
}
313
329
314
330
/// A configuration class that can interpret [ToolDefinition] s from a YAML map.
@@ -335,6 +351,7 @@ class ToolConfiguration {
335
351
for (var entry in yamlMap.entries) {
336
352
var name = entry.key.toString ();
337
353
var toolMap = entry.value;
354
+ List <String > compileArgs;
338
355
String description;
339
356
List <String > command;
340
357
List <String > setupCommand;
@@ -376,6 +393,27 @@ class ToolConfiguration {
376
393
377
394
command = findCommand ();
378
395
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 ();
379
417
} else {
380
418
throw DartdocOptionError (
381
419
'Tools must be defined as a map of tool names to definitions. Tool '
@@ -421,7 +459,8 @@ class ToolConfiguration {
421
459
setupCommand;
422
460
}
423
461
newToolDefinitions[name] = ToolDefinition .fromCommand (
424
- [executable] + command, setupCommand, description, resourceProvider);
462
+ [executable] + command, setupCommand, description, resourceProvider,
463
+ compileArgs: compileArgs ?? const []);
425
464
}
426
465
return ToolConfiguration ._(newToolDefinitions, resourceProvider);
427
466
}
0 commit comments