@@ -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;
@@ -343,39 +360,60 @@ class ToolConfiguration {
343
360
List <String > findCommand ([String prefix = '' ]) {
344
361
List <String > command;
345
362
// If the command key is given, then it applies to all platforms.
346
- var commandFrom = toolMap.containsKey ('${prefix }command' )
363
+ var commandFromKey = toolMap.containsKey ('${prefix }command' )
347
364
? '${prefix }command'
348
365
: '$prefix ${Platform .operatingSystem }' ;
349
- if (toolMap.containsKey (commandFrom)) {
350
- if (toolMap[commandFrom].value is String ) {
351
- command = [toolMap[commandFrom].toString ()];
366
+ if (toolMap.containsKey (commandFromKey)) {
367
+ var commandFrom = toolMap[commandFromKey] as YamlNode ;
368
+ if (commandFrom.value is String ) {
369
+ command = [commandFrom.toString ()];
352
370
if (command[0 ].isEmpty) {
353
371
throw DartdocOptionError (
354
372
'Tool commands must not be empty. Tool $name command entry '
355
- '"$commandFrom " must contain at least one path.' );
373
+ '"$commandFromKey " must contain at least one path.' );
356
374
}
357
- } else if (toolMap[commandFrom] is YamlList ) {
358
- command = (toolMap[commandFrom] as YamlList )
359
- .map <String >((node) => node.toString ())
360
- .toList ();
375
+ } else if (commandFrom is YamlList ) {
376
+ command =
377
+ commandFrom.map <String >((node) => node.toString ()).toList ();
361
378
if (command.isEmpty) {
362
379
throw DartdocOptionError (
363
380
'Tool commands must not be empty. Tool $name command entry '
364
- '"$commandFrom " must contain at least one path.' );
381
+ '"$commandFromKey " must contain at least one path.' );
365
382
}
366
383
} else {
367
384
throw DartdocOptionError (
368
385
'Tool commands must be a path to an executable, or a list of '
369
386
'strings that starts with a path to an executable. '
370
- 'The tool $name has a $commandFrom entry that is a '
371
- '${toolMap [ commandFrom ] .runtimeType }' );
387
+ 'The tool $name has a $commandFromKey entry that is a '
388
+ '${commandFrom .runtimeType }' );
372
389
}
373
390
}
374
391
return command;
375
392
}
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
}
@@ -598,16 +637,17 @@ abstract class DartdocOption<T> {
598
637
_OptionValueWithContext <Object > valueWithContext, String missingFilename);
599
638
600
639
/// Call [_onMissing] for every path that does not exist.
601
- void _validatePaths (_OptionValueWithContext <dynamic > valueWithContext) {
640
+ void _validatePaths (_OptionValueWithContext <Object > valueWithContext) {
602
641
if (! mustExist) return ;
603
642
assert (isDir || isFile);
604
643
List <String > resolvedPaths;
605
- if (valueWithContext.value is String ) {
644
+ var value = valueWithContext.value;
645
+ if (value is String ) {
606
646
resolvedPaths = [valueWithContext.resolvedValue];
607
- } else if (valueWithContext. value is List <String >) {
608
- resolvedPaths = valueWithContext.resolvedValue. toList () ;
609
- } else if (valueWithContext. value is Map <String , String >) {
610
- resolvedPaths = valueWithContext.resolvedValue.values.toList ();
647
+ } else if (value is List <String >) {
648
+ resolvedPaths = valueWithContext.resolvedValue as List ;
649
+ } else if (value is Map <String , String >) {
650
+ resolvedPaths = ( valueWithContext.resolvedValue as Map ) .values.toList ();
611
651
} else {
612
652
assert (
613
653
false ,
@@ -1120,19 +1160,18 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
1120
1160
_OptionValueWithContext <Object > _valueAtFromFile (Folder dir) {
1121
1161
var yamlFileData = _yamlAtDirectory (dir);
1122
1162
var contextPath = yamlFileData.canonicalDirectoryPath;
1123
- dynamic yamlData = yamlFileData.data ?? {};
1163
+ Object yamlData = yamlFileData.data ?? {};
1124
1164
for (var key in keys) {
1125
- if (! yamlData.containsKey (key)) return null ;
1126
- yamlData = yamlData[key] ?? {};
1165
+ if (yamlData is Map && ! yamlData.containsKey (key)) return null ;
1166
+ yamlData = ( yamlData as Map ) [key] ?? {};
1127
1167
}
1128
1168
1129
- dynamic returnData;
1169
+ Object returnData;
1130
1170
if (_isListString) {
1131
1171
if (yamlData is YamlList ) {
1132
- returnData = < String > [];
1133
- for (var item in yamlData) {
1134
- returnData.add (item.toString ());
1135
- }
1172
+ returnData = [
1173
+ for (var item in yamlData) item.toString (),
1174
+ ];
1136
1175
}
1137
1176
} else if (yamlData is YamlMap ) {
1138
1177
// TODO(jcollins-g): This special casing is unfortunate. Consider
@@ -1700,7 +1739,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1700
1739
help: 'Generate ONLY the docs for the Dart SDK.' ),
1701
1740
DartdocOptionArgSynth <String >('sdkDir' ,
1702
1741
(DartdocSyntheticOption <String > option, Folder dir) {
1703
- if (! option.parent['sdkDocs' ].valueAt (dir) &&
1742
+ if (! ( option.parent['sdkDocs' ].valueAt (dir) as bool ) &&
1704
1743
(option.root['topLevelPackageMeta' ].valueAt (dir) as PackageMeta )
1705
1744
.requiresFlutter) {
1706
1745
String flutterRoot = option.root['flutterRoot' ].valueAt (dir);
0 commit comments