@@ -58,6 +58,7 @@ type SketchLibrariesDetector struct {
58
58
includeFolders paths.PathList
59
59
logger * logger.BuilderLogger
60
60
diagnosticStore * diagnostics.Store
61
+ preRunner * runner.Runner
61
62
}
62
63
63
64
// NewSketchLibrariesDetector todo
@@ -236,6 +237,18 @@ func (l *SketchLibrariesDetector) findIncludes(
236
237
l .logger .Warn (i18n .Tr ("Failed to load library discovery cache: %[1]s" , err ))
237
238
}
238
239
240
+ // Pre-run cache entries
241
+ l .preRunner = runner .New (ctx )
242
+ for _ , entry := range l .cache .EntriesAhead () {
243
+ if entry .Compile != nil && entry .CompileTask != nil {
244
+ upToDate , _ := entry .Compile .ObjFileIsUpToDate ()
245
+ if ! upToDate {
246
+ l .preRunner .Enqueue (entry .CompileTask )
247
+ }
248
+ }
249
+ }
250
+ defer l .preRunner .Cancel ()
251
+
239
252
l .addIncludeFolder (buildCorePath )
240
253
if buildVariantPath != nil {
241
254
l .addIncludeFolder (buildVariantPath )
@@ -263,6 +276,15 @@ func (l *SketchLibrariesDetector) findIncludes(
263
276
cachePath .Remove ()
264
277
return err
265
278
}
279
+
280
+ // Create a new pre-runner if the previous one was cancelled
281
+ if l .preRunner == nil {
282
+ l .preRunner = runner .New (ctx )
283
+ // Push in the remainder of the queue
284
+ for _ , sourceFile := range * sourceFileQueue {
285
+ l .preRunner .Enqueue (l .gccPreprocessTask (sourceFile , buildProperties ))
286
+ }
287
+ }
266
288
}
267
289
268
290
// Finalize the cache
@@ -326,9 +348,9 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
326
348
327
349
first := true
328
350
for {
329
- l .cache .Expect (& detectorCacheEntry {Compile : sourceFile })
330
-
331
351
preprocTask := l .gccPreprocessTask (sourceFile , buildProperties )
352
+ l .cache .Expect (& detectorCacheEntry {Compile : sourceFile , CompileTask : preprocTask })
353
+
332
354
var preprocErr error
333
355
var preprocResult * runner.Result
334
356
@@ -340,8 +362,27 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
340
362
}
341
363
first = false
342
364
} else {
343
- preprocResult = preprocTask .Run (ctx )
344
- preprocErr = preprocResult .Error
365
+ if l .preRunner != nil {
366
+ if r := l .preRunner .Results (preprocTask ); r != nil {
367
+ preprocResult = r
368
+ preprocErr = preprocResult .Error
369
+ }
370
+ }
371
+ if preprocResult == nil {
372
+ // The pre-runner missed this task, maybe the cache is outdated
373
+ // or maybe the source code changed.
374
+
375
+ // Stop the pre-runner
376
+ if l .preRunner != nil {
377
+ preRunner := l .preRunner
378
+ l .preRunner = nil
379
+ go preRunner .Cancel ()
380
+ }
381
+
382
+ // Run the actual preprocessor
383
+ preprocResult = preprocTask .Run (ctx )
384
+ preprocErr = preprocResult .Error
385
+ }
345
386
if l .logger .Verbose () {
346
387
l .logger .WriteStdout (preprocResult .Stdout )
347
388
}
0 commit comments