@@ -59,6 +59,7 @@ type SketchLibrariesDetector struct {
59
59
includeFolders paths.PathList
60
60
logger * logger.BuilderLogger
61
61
diagnosticStore * diagnostics.Store
62
+ preRunner * runner.Runner
62
63
}
63
64
64
65
// NewSketchLibrariesDetector todo
@@ -254,6 +255,18 @@ func (l *SketchLibrariesDetector) findIncludes(
254
255
l .logger .Warn (i18n .Tr ("Failed to load library discovery cache: %[1]s" , err ))
255
256
}
256
257
258
+ // Pre-run cache entries
259
+ l .preRunner = runner .New (ctx )
260
+ for _ , entry := range l .cache .EntriesAhead () {
261
+ if entry .Compile != nil && entry .CompileTask != nil {
262
+ upToDate , _ := entry .Compile .ObjFileIsUpToDate ()
263
+ if ! upToDate {
264
+ l .preRunner .Enqueue (entry .CompileTask )
265
+ }
266
+ }
267
+ }
268
+ defer l .preRunner .Cancel ()
269
+
257
270
l .addIncludeFolder (buildCorePath )
258
271
if buildVariantPath != nil {
259
272
l .addIncludeFolder (buildVariantPath )
@@ -291,6 +304,15 @@ func (l *SketchLibrariesDetector) findIncludes(
291
304
cachePath .Remove ()
292
305
return err
293
306
}
307
+
308
+ // Create a new pre-runner if the previous one was cancelled
309
+ if l .preRunner == nil {
310
+ l .preRunner = runner .New (ctx )
311
+ // Push in the remainder of the queue
312
+ for _ , sourceFile := range * sourceFileQueue {
313
+ l .preRunner .Enqueue (l .gccPreprocessTask (sourceFile , buildProperties ))
314
+ }
315
+ }
294
316
}
295
317
296
318
// Finalize the cache
@@ -354,9 +376,9 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
354
376
355
377
first := true
356
378
for {
357
- l .cache .Expect (& detectorCacheEntry {Compile : sourceFile })
358
-
359
379
preprocTask := l .gccPreprocessTask (sourceFile , buildProperties )
380
+ l .cache .Expect (& detectorCacheEntry {Compile : sourceFile , CompileTask : preprocTask })
381
+
360
382
var preprocErr error
361
383
var preprocResult * runner.Result
362
384
@@ -368,8 +390,27 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
368
390
}
369
391
first = false
370
392
} else {
371
- preprocResult = preprocTask .Run (ctx )
372
- preprocErr = preprocResult .Error
393
+ if l .preRunner != nil {
394
+ if r := l .preRunner .Results (preprocTask ); r != nil {
395
+ preprocResult = r
396
+ preprocErr = preprocResult .Error
397
+ }
398
+ }
399
+ if preprocResult == nil {
400
+ // The pre-runner missed this task, maybe the cache is outdated
401
+ // or maybe the source code changed.
402
+
403
+ // Stop the pre-runner
404
+ if l .preRunner != nil {
405
+ preRunner := l .preRunner
406
+ l .preRunner = nil
407
+ go preRunner .Cancel ()
408
+ }
409
+
410
+ // Run the actual preprocessor
411
+ preprocResult = preprocTask .Run (ctx )
412
+ preprocErr = preprocResult .Error
413
+ }
373
414
if l .logger .VerbosityLevel () == logger .VerbosityVerbose {
374
415
l .logger .WriteStdout (preprocResult .Stdout )
375
416
}
0 commit comments