@@ -61,7 +61,7 @@ const _portMessageDone = "done";
61
61
// the part declares what file it's part of and if we've compiled other stuff
62
62
// first so we know more stuff).
63
63
class DartDocTest {
64
- DocTestIncrementalCompiler ? incrementalCompiler ;
64
+ DocTestIncrementalCompiler ? savedIncrementalCompiler ;
65
65
late CompilerOptions options;
66
66
late ProcessedOptions processedOpts;
67
67
bool errors = false ;
@@ -132,9 +132,12 @@ class DartDocTest {
132
132
sb.writeln ("}" );
133
133
}
134
134
135
- if (incrementalCompiler == null ) {
136
- setupIncrementalCompiler (uri);
137
- }
135
+ // Setup the incremental compiler.
136
+ // We only want to reuse it if it didn't crash as that will make it wait
137
+ // for the crashed compile to finish (and it won't).
138
+ DocTestIncrementalCompiler incrementalCompiler =
139
+ savedIncrementalCompiler ?? createIncrementalCompiler (uri);
140
+ savedIncrementalCompiler = null ;
138
141
139
142
processedOpts.inputs.clear ();
140
143
processedOpts.inputs.add (uri);
@@ -145,11 +148,11 @@ class DartDocTest {
145
148
processedOpts.clearFileSystemCache ();
146
149
// Invalidate package uri to force re-finding of packages
147
150
// (e.g. if we're now compiling somewhere else).
148
- incrementalCompiler! .invalidate (processedOpts.packagesUri);
151
+ incrementalCompiler.invalidate (processedOpts.packagesUri);
149
152
150
153
Stopwatch stopwatch = new Stopwatch ()..start ();
151
154
IncrementalCompilerResult compilerResult =
152
- await incrementalCompiler! .computeDelta (entryPoints: [uri]);
155
+ await incrementalCompiler.computeDelta (entryPoints: [uri]);
153
156
kernel.Component component = compilerResult.component;
154
157
if (errors) {
155
158
_print ("Got errors in ${stopwatch .elapsedMilliseconds } ms." );
@@ -161,16 +164,16 @@ class DartDocTest {
161
164
_print ("Compiled (1) in ${stopwatch .elapsedMilliseconds } ms." );
162
165
stopwatch.reset ();
163
166
164
- await incrementalCompiler! .compileDartDocTestLibrary (
167
+ await incrementalCompiler.compileDartDocTestLibrary (
165
168
sb.toString (), component.uriToSource[uri]? .importUri ?? uri);
166
169
167
170
final Uri dartDocMainUri = new Uri (scheme: "dartdoctest" , path: "main" );
168
171
fileSystem.memory
169
172
.entityForUri (dartDocMainUri)
170
173
.writeAsStringSync (mainFileContent);
171
174
172
- incrementalCompiler! .invalidate (dartDocMainUri);
173
- IncrementalCompilerResult compilerMainResult = await incrementalCompiler!
175
+ incrementalCompiler.invalidate (dartDocMainUri);
176
+ IncrementalCompilerResult compilerMainResult = await incrementalCompiler
174
177
.computeDelta (entryPoints: [dartDocMainUri], fullComponent: true );
175
178
kernel.Component componentMain = compilerMainResult.component;
176
179
if (errors) {
@@ -270,6 +273,9 @@ class DartDocTest {
270
273
await completer.future;
271
274
tmpDir.deleteSync (recursive: true );
272
275
276
+ // We finished successfully. Save the incremental compiler.
277
+ savedIncrementalCompiler = incrementalCompiler;
278
+
273
279
if (error) {
274
280
_print ("Completed with an error in ${stopwatch .elapsedMilliseconds } ms." );
275
281
return [new TestResult (null , TestOutcome .RuntimeError )];
@@ -300,7 +306,7 @@ class DartDocTest {
300
306
}
301
307
}
302
308
303
- void setupIncrementalCompiler (Uri uri) {
309
+ DocTestIncrementalCompiler createIncrementalCompiler (Uri uri) {
304
310
options = getOptions ();
305
311
TargetFlags targetFlags = new TargetFlags ();
306
312
// TODO: Target could possible be something else...
@@ -318,7 +324,7 @@ class DartDocTest {
318
324
};
319
325
processedOpts = new ProcessedOptions (options: options, inputs: [uri]);
320
326
CompilerContext compilerContext = new CompilerContext (processedOpts);
321
- this .incrementalCompiler = new DocTestIncrementalCompiler (compilerContext);
327
+ return new DocTestIncrementalCompiler (compilerContext);
322
328
}
323
329
}
324
330
0 commit comments