@@ -20,6 +20,7 @@ import 'dart:io';
20
20
import 'package:analyzer/dart/element/element.dart' ;
21
21
import 'package:args/args.dart' ;
22
22
import 'package:dartdoc/dartdoc.dart' ;
23
+ import 'package:dartdoc/src/tuple.dart' ;
23
24
import 'package:path/path.dart' as pathLib;
24
25
import 'package:yaml/yaml.dart' ;
25
26
@@ -226,22 +227,23 @@ class DartToolDefinition extends ToolDefinition {
226
227
/// to run. If no snapshot file existed, then create one and modify the args
227
228
/// so that if they are executed with dart, will result in the snapshot being
228
229
/// 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
232
234
// 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 ()) {
236
237
// replace the first argument with the path to the snapshot.
237
- args[0 ] = snapshotPath .absolute.path;
238
+ args[0 ] = snapshotFile .absolute.path;
238
239
} else {
239
240
args.insertAll (0 , [
240
- '--snapshot=${snapshotPath .absolute .path }' ,
241
+ '--snapshot=${snapshotFile .absolute .path }' ,
241
242
'--snapshot_kind=app-jit'
242
243
]);
243
244
}
244
- return Platform .resolvedExecutable;
245
+ return new Tuple2 (Platform .resolvedExecutable,
246
+ _snapshotCompleter.isCompleted ? null : _snapshotCompleter.complete);
245
247
}
246
248
247
249
DartToolDefinition (
@@ -250,11 +252,23 @@ class DartToolDefinition extends ToolDefinition {
250
252
// If the dart tool is already a snapshot, then we just use that.
251
253
if (command[0 ].endsWith ('.snapshot' )) {
252
254
_snapshotPath = File (command[0 ]);
255
+ _snapshotCompleter.complete ();
253
256
}
254
257
}
255
258
259
+ final Completer _snapshotCompleter = new Completer ();
260
+
256
261
/// If the tool has a pre-built snapshot, it will be stored here.
257
262
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
+ }
258
272
}
259
273
260
274
/// A configuration class that can interpret [ToolDefinition] s from a YAML map.
0 commit comments