@@ -284,6 +284,19 @@ func (l *SketchLibrariesDetector) findIncludes(
284284 return nil
285285}
286286
287+ func (l * SketchLibrariesDetector ) gccPreprocessTask (sourceFile * sourceFile , buildProperties * properties.Map ) * runner.Task {
288+ // Libraries may require the "utility" directory to be added to the include
289+ // search path, but only for the source code of the library, so we temporary
290+ // copy the current search path list and add the library' utility directory
291+ // if needed.
292+ includeFolders := l .includeFolders
293+ if extraInclude := sourceFile .ExtraIncludePath ; extraInclude != nil {
294+ includeFolders = append (includeFolders , extraInclude )
295+ }
296+
297+ return preprocessor .GCC (sourceFile .SourcePath , paths .NullPath (), includeFolders , buildProperties )
298+ }
299+
287300func (l * SketchLibrariesDetector ) findMissingIncludesInCompilationUnit (
288301 ctx context.Context ,
289302 sourceFileQueue * uniqueSourceFileQueue ,
@@ -315,15 +328,7 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
315328 for {
316329 l .cache .Expect (& detectorCacheEntry {Compile : sourceFile })
317330
318- // Libraries may require the "utility" directory to be added to the include
319- // search path, but only for the source code of the library, so we temporary
320- // copy the current search path list and add the library' utility directory
321- // if needed.
322- includeFolders := l .includeFolders
323- if extraInclude := sourceFile .ExtraIncludePath ; extraInclude != nil {
324- includeFolders = append (includeFolders , extraInclude )
325- }
326-
331+ preprocTask := l .gccPreprocessTask (sourceFile , buildProperties )
327332 var preprocErr error
328333 var preprocResult * runner.Result
329334
@@ -335,7 +340,8 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
335340 }
336341 first = false
337342 } else {
338- preprocResult , preprocErr = preprocessor .GCC (ctx , sourcePath , paths .NullPath (), includeFolders , buildProperties )
343+ preprocResult = preprocTask .Run (ctx )
344+ preprocErr = preprocResult .Error
339345 if l .logger .Verbose () {
340346 l .logger .WriteStdout (preprocResult .Stdout )
341347 }
@@ -368,7 +374,8 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
368374
369375 // If preprocess result came from cache, run the preprocessor to obtain the actual error to show
370376 if preprocErr == nil || len (preprocResult .Stderr ) == 0 {
371- preprocResult , preprocErr = preprocessor .GCC (ctx , sourcePath , paths .NullPath (), includeFolders , buildProperties )
377+ preprocResult = preprocTask .Run (ctx )
378+ preprocErr = preprocResult .Error
372379 if l .logger .Verbose () {
373380 l .logger .WriteStdout (preprocResult .Stdout )
374381 }
0 commit comments