@@ -20,6 +20,7 @@ import 'dart:io';
2020import 'package:analyzer/dart/element/element.dart' ;
2121import 'package:args/args.dart' ;
2222import 'package:dartdoc/dartdoc.dart' ;
23+ import 'package:dartdoc/src/tuple.dart' ;
2324import 'package:path/path.dart' as pathLib;
2425import 'package:yaml/yaml.dart' ;
2526
@@ -226,22 +227,23 @@ class DartToolDefinition extends ToolDefinition {
226227 /// to run. If no snapshot file existed, then create one and modify the args
227228 /// so that if they are executed with dart, will result in the snapshot being
228229 /// built.
229- String createSnapshotIfNeeded (List <String > args) {
230- assert (ToolDefinition .isDartExecutable (args[0 ]));
231- // Generate a new snapshot, if needed, and use the first run as the training
230+ Future <Tuple2 <String , Function ()>> modifyArgsToCreateSnapshotIfNeeded (
231+ List <String > args) async {
232+ assert (args[0 ] == command.first);
233+ // Set up flags to create a new snapshot, if needed, and use the first run as the training
232234 // run.
233- File snapshotPath = _snapshotPath;
234- snapshotPath ?? = SnapshotCache .instance.getSnapshot (args[0 ]);
235- if (snapshotPath.existsSync ()) {
235+ File snapshotFile = await getSnapshotFile ();
236+ if (snapshotFile.existsSync ()) {
236237 // replace the first argument with the path to the snapshot.
237- args[0 ] = snapshotPath .absolute.path;
238+ args[0 ] = snapshotFile .absolute.path;
238239 } else {
239240 args.insertAll (0 , [
240- '--snapshot=${snapshotPath .absolute .path }' ,
241+ '--snapshot=${snapshotFile .absolute .path }' ,
241242 '--snapshot_kind=app-jit'
242243 ]);
243244 }
244- return Platform .resolvedExecutable;
245+ return new Tuple2 (Platform .resolvedExecutable,
246+ _snapshotCompleter.isCompleted ? null : _snapshotCompleter.complete);
245247 }
246248
247249 DartToolDefinition (
@@ -250,11 +252,23 @@ class DartToolDefinition extends ToolDefinition {
250252 // If the dart tool is already a snapshot, then we just use that.
251253 if (command[0 ].endsWith ('.snapshot' )) {
252254 _snapshotPath = File (command[0 ]);
255+ _snapshotCompleter.complete ();
253256 }
254257 }
255258
259+ final Completer _snapshotCompleter = new Completer ();
260+
256261 /// If the tool has a pre-built snapshot, it will be stored here.
257262 File _snapshotPath;
263+
264+ Future <File > getSnapshotFile () async {
265+ if (_snapshotPath == null ) {
266+ _snapshotPath = SnapshotCache .instance.getSnapshot (command.first);
267+ } else {
268+ await _snapshotCompleter.future;
269+ }
270+ return _snapshotPath;
271+ }
258272}
259273
260274/// A configuration class that can interpret [ToolDefinition] s from a YAML map.
0 commit comments