@@ -328,7 +328,7 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
328
328
}
329
329
330
330
var preprocErr error
331
- var preprocFirstResult * runner.Result
331
+ var preprocResult * runner.Result
332
332
333
333
var missingIncludeH string
334
334
if entry := l .cache .Peek (); unchanged && entry != nil && entry .MissingIncludeH != nil {
@@ -338,20 +338,20 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
338
338
}
339
339
first = false
340
340
} else {
341
- preprocFirstResult , preprocErr = preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
341
+ preprocResult , preprocErr = preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
342
342
if l .logger .Verbose () {
343
- l .logger .WriteStdout (preprocFirstResult .Stdout )
343
+ l .logger .WriteStdout (preprocResult .Stdout )
344
344
}
345
345
// Unwrap error and see if it is an ExitError.
346
346
var exitErr * exec.ExitError
347
347
if preprocErr == nil {
348
348
// Preprocessor successful, done
349
349
missingIncludeH = ""
350
- } else if isExitErr := errors .As (preprocErr , & exitErr ); ! isExitErr || len (preprocFirstResult .Stderr ) == 0 {
350
+ } else if isExitErr := errors .As (preprocErr , & exitErr ); ! isExitErr || len (preprocResult .Stderr ) == 0 {
351
351
// Ignore ExitErrors (e.g. gcc returning non-zero status), but bail out on other errors
352
352
return preprocErr
353
353
} else {
354
- missingIncludeH = IncludesFinderWithRegExp (string (preprocFirstResult .Stderr ))
354
+ missingIncludeH = IncludesFinderWithRegExp (string (preprocResult .Stderr ))
355
355
if missingIncludeH == "" && l .logger .Verbose () {
356
356
l .logger .Info (i18n .Tr ("Error while detecting libraries included by %[1]s" , sourcePath ))
357
357
}
@@ -368,25 +368,23 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
368
368
library := l .resolveLibrary (missingIncludeH , platformArch )
369
369
if library == nil {
370
370
// Library could not be resolved, show error
371
- if preprocErr == nil || len (preprocFirstResult .Stderr ) == 0 {
372
- // Filename came from cache, so run preprocessor to obtain error to show
373
- result , err := preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
371
+
372
+ // If preprocess result came from cache, run the preprocessor to obtain the actual error to show
373
+ if preprocErr == nil || len (preprocResult .Stderr ) == 0 {
374
+ preprocResult , preprocErr = preprocessor .GCC (ctx , sourcePath , targetFilePath , includeFolders , buildProperties )
374
375
if l .logger .Verbose () {
375
- l .logger .WriteStdout (result .Stdout )
376
+ l .logger .WriteStdout (preprocResult .Stdout )
376
377
}
377
- if err == nil {
378
+ if preprocErr == nil {
378
379
// If there is a missing #include in the cache, but running
379
380
// gcc does not reproduce that, there is something wrong.
380
381
// Returning an error here will cause the cache to be
381
382
// deleted, so hopefully the next compilation will succeed.
382
383
return errors .New (i18n .Tr ("Internal error in cache" ))
383
384
}
384
- l .diagnosticStore .Parse (result .Args , result .Stderr )
385
- l .logger .WriteStderr (result .Stderr )
386
- return err
387
385
}
388
- l .diagnosticStore .Parse (preprocFirstResult .Args , preprocFirstResult .Stderr )
389
- l .logger .WriteStderr (preprocFirstResult .Stderr )
386
+ l .diagnosticStore .Parse (preprocResult .Args , preprocResult .Stderr )
387
+ l .logger .WriteStderr (preprocResult .Stderr )
390
388
return preprocErr
391
389
}
392
390
0 commit comments