@@ -7,6 +7,8 @@ import 'dart:async';
7
7
import 'package:analyzer/file_system/file_system.dart' ;
8
8
import 'package:dartdoc/src/dartdoc_options.dart' ;
9
9
import 'package:dartdoc/src/io_utils.dart' ;
10
+ import 'package:dartdoc/src/tool_runner.dart' ;
11
+ import 'package:meta/meta.dart' ;
10
12
import 'package:path/path.dart' as p show extension;
11
13
12
14
/// Defines the attributes of a tool in the options file, corresponding to
@@ -81,7 +83,8 @@ class ToolDefinition {
81
83
}
82
84
}
83
85
84
- Future <ToolStateForArgs > toolStateForArgs (List <String > args) async {
86
+ Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
87
+ {@required ToolErrorCallback toolErrorCallback}) async {
85
88
var commandPath = args.removeAt (0 );
86
89
return ToolStateForArgs (commandPath, args, null );
87
90
}
@@ -101,14 +104,16 @@ class DartToolDefinition extends ToolDefinition {
101
104
/// so that if they are executed with dart, will result in the snapshot being
102
105
/// built.
103
106
@override
104
- Future <ToolStateForArgs > toolStateForArgs (List <String > args) async {
107
+ Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
108
+ {@required ToolErrorCallback toolErrorCallback}) async {
105
109
assert (args[0 ] == command.first);
106
110
// Set up flags to create a new snapshot, if needed, and use the first run
107
111
// as the training run.
108
112
SnapshotCache .createInstance (_resourceProvider);
109
113
var snapshot = SnapshotCache .instance.getSnapshot (command.first);
114
+ var snapshotFile = snapshot._snapshotFile;
110
115
var snapshotPath =
111
- _resourceProvider.pathContext.absolute (snapshot._snapshotFile .path);
116
+ _resourceProvider.pathContext.absolute (snapshotFile .path);
112
117
var needsSnapshot = snapshot.needsSnapshot;
113
118
if (needsSnapshot) {
114
119
return ToolStateForArgs (
@@ -127,8 +132,16 @@ class DartToolDefinition extends ToolDefinition {
127
132
snapshot._snapshotCompleted);
128
133
} else {
129
134
await snapshot._snapshotValid ();
130
- // replace the first argument with the path to the snapshot.
131
- args[0 ] = snapshotPath;
135
+ if (! snapshotFile.exists) {
136
+ if (toolErrorCallback != null ) {
137
+ toolErrorCallback (
138
+ 'Snapshot creation failed for $toolName tool. $snapshotPath does '
139
+ 'not exist. Will execute tool without snapshot.' );
140
+ }
141
+ } else {
142
+ // replace the first argument with the path to the snapshot.
143
+ args[0 ] = snapshotPath;
144
+ }
132
145
return ToolStateForArgs (_resourceProvider.resolvedExecutable, args, null );
133
146
}
134
147
}
0 commit comments