@@ -356,7 +356,7 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
356
356
}
357
357
358
358
var preprocErr error
359
- var preprocFirstResult * runner.Result
359
+ var preprocResult * runner.Result
360
360
361
361
var missingIncludeH string
362
362
if entry := l .cache .Peek (); unchanged && entry != nil && entry .MissingIncludeH != nil {
@@ -366,20 +366,20 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
366
366
}
367
367
first = false
368
368
} else {
369
- preprocFirstResult , preprocErr = preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
369
+ preprocResult , preprocErr = preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
370
370
if l .logger .VerbosityLevel () == logger .VerbosityVerbose {
371
- l .logger .WriteStdout (preprocFirstResult .Stdout )
371
+ l .logger .WriteStdout (preprocResult .Stdout )
372
372
}
373
373
// Unwrap error and see if it is an ExitError.
374
374
var exitErr * exec.ExitError
375
375
if preprocErr == nil {
376
376
// Preprocessor successful, done
377
377
missingIncludeH = ""
378
- } else if isExitErr := errors .As (preprocErr , & exitErr ); ! isExitErr || len (preprocFirstResult .Stderr ) == 0 {
378
+ } else if isExitErr := errors .As (preprocErr , & exitErr ); ! isExitErr || len (preprocResult .Stderr ) == 0 {
379
379
// Ignore ExitErrors (e.g. gcc returning non-zero status), but bail out on other errors
380
380
return preprocErr
381
381
} else {
382
- missingIncludeH = IncludesFinderWithRegExp (string (preprocFirstResult .Stderr ))
382
+ missingIncludeH = IncludesFinderWithRegExp (string (preprocResult .Stderr ))
383
383
if missingIncludeH == "" && l .logger .VerbosityLevel () == logger .VerbosityVerbose {
384
384
l .logger .Info (i18n .Tr ("Error while detecting libraries included by %[1]s" , sourcePath ))
385
385
}
@@ -396,25 +396,23 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
396
396
library := l .resolveLibrary (missingIncludeH , platformArch )
397
397
if library == nil {
398
398
// Library could not be resolved, show error
399
- if preprocErr == nil || len (preprocFirstResult .Stderr ) == 0 {
400
- // Filename came from cache, so run preprocessor to obtain error to show
401
- result , err := preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
399
+
400
+ // If preprocess result came from cache, run the preprocessor to obtain the actual error to show
401
+ if preprocErr == nil || len (preprocResult .Stderr ) == 0 {
402
+ preprocResult , preprocErr = preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
402
403
if l .logger .VerbosityLevel () == logger .VerbosityVerbose {
403
- l .logger .WriteStdout (result .Stdout )
404
+ l .logger .WriteStdout (preprocResult .Stdout )
404
405
}
405
- if err == nil {
406
+ if preprocErr == nil {
406
407
// If there is a missing #include in the cache, but running
407
408
// gcc does not reproduce that, there is something wrong.
408
409
// Returning an error here will cause the cache to be
409
410
// deleted, so hopefully the next compilation will succeed.
410
411
return errors .New (i18n .Tr ("Internal error in cache" ))
411
412
}
412
- l .diagnosticStore .Parse (result .Args , result .Stderr )
413
- l .logger .WriteStderr (result .Stderr )
414
- return err
415
413
}
416
- l .diagnosticStore .Parse (preprocFirstResult .Args , preprocFirstResult .Stderr )
417
- l .logger .WriteStderr (preprocFirstResult .Stderr )
414
+ l .diagnosticStore .Parse (preprocResult .Args , preprocResult .Stderr )
415
+ l .logger .WriteStderr (preprocResult .Stderr )
418
416
return preprocErr
419
417
}
420
418
0 commit comments