@@ -26,6 +26,7 @@ import (
26
26
"strings"
27
27
"time"
28
28
29
+ "github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnostics"
29
30
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/logger"
30
31
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/preprocessor"
31
32
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/utils"
@@ -57,6 +58,7 @@ type SketchLibrariesDetector struct {
57
58
librariesResolutionResults map [string ]libraryResolutionResult
58
59
includeFolders paths.PathList
59
60
logger * logger.BuilderLogger
61
+ diagnosticStore * diagnostics.Store
60
62
}
61
63
62
64
// NewSketchLibrariesDetector todo
@@ -66,6 +68,7 @@ func NewSketchLibrariesDetector(
66
68
useCachedLibrariesResolution bool ,
67
69
onlyUpdateCompilationDatabase bool ,
68
70
logger * logger.BuilderLogger ,
71
+ diagnosticStore * diagnostics.Store ,
69
72
) * SketchLibrariesDetector {
70
73
return & SketchLibrariesDetector {
71
74
librariesManager : lm ,
@@ -76,6 +79,7 @@ func NewSketchLibrariesDetector(
76
79
includeFolders : paths.PathList {},
77
80
onlyUpdateCompilationDatabase : onlyUpdateCompilationDatabase ,
78
81
logger : logger ,
82
+ diagnosticStore : diagnosticStore ,
79
83
}
80
84
}
81
85
@@ -337,7 +341,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
337
341
}
338
342
339
343
var preprocErr error
340
- var preprocStderr [] byte
344
+ var preprocFirstResult preprocessor. Result
341
345
342
346
var missingIncludeH string
343
347
if unchanged && cache .valid {
@@ -346,21 +350,20 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
346
350
l .logger .Info (tr ("Using cached library dependencies for file: %[1]s" , sourcePath ))
347
351
}
348
352
} else {
349
- var preprocStdout []byte
350
- preprocStdout , preprocStderr , preprocErr = preprocessor .GCC (sourcePath , targetFilePath , includeFolders , buildProperties )
353
+ preprocFirstResult , preprocErr = preprocessor .GCC (sourcePath , targetFilePath , includeFolders , buildProperties )
351
354
if l .logger .Verbose () {
352
- l .logger .WriteStdout (preprocStdout )
355
+ l .logger .WriteStdout (preprocFirstResult . Stdout () )
353
356
}
354
357
// Unwrap error and see if it is an ExitError.
355
358
var exitErr * exec.ExitError
356
359
if preprocErr == nil {
357
360
// Preprocessor successful, done
358
361
missingIncludeH = ""
359
- } else if isExitErr := errors .As (preprocErr , & exitErr ); ! isExitErr || preprocStderr == nil {
362
+ } else if isExitErr := errors .As (preprocErr , & exitErr ); ! isExitErr || preprocFirstResult . Stderr () == nil {
360
363
// Ignore ExitErrors (e.g. gcc returning non-zero status), but bail out on other errors
361
364
return preprocErr
362
365
} else {
363
- missingIncludeH = IncludesFinderWithRegExp (string (preprocStderr ))
366
+ missingIncludeH = IncludesFinderWithRegExp (string (preprocFirstResult . Stderr () ))
364
367
if missingIncludeH == "" && l .logger .Verbose () {
365
368
l .logger .Info (tr ("Error while detecting libraries included by %[1]s" , sourcePath ))
366
369
}
@@ -376,22 +379,25 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
376
379
library := l .resolveLibrary (missingIncludeH , platformArch )
377
380
if library == nil {
378
381
// Library could not be resolved, show error
379
- if preprocErr == nil || preprocStderr == nil {
382
+ if preprocErr == nil || preprocFirstResult . Stderr () == nil {
380
383
// Filename came from cache, so run preprocessor to obtain error to show
381
- var preprocStdout []byte
382
- preprocStdout , preprocStderr , preprocErr = preprocessor .GCC (sourcePath , targetFilePath , includeFolders , buildProperties )
384
+ result , err := preprocessor .GCC (sourcePath , targetFilePath , includeFolders , buildProperties )
383
385
if l .logger .Verbose () {
384
- l .logger .WriteStdout (preprocStdout )
386
+ l .logger .WriteStdout (result . Stdout () )
385
387
}
386
- if preprocErr == nil {
388
+ if err == nil {
387
389
// If there is a missing #include in the cache, but running
388
390
// gcc does not reproduce that, there is something wrong.
389
391
// Returning an error here will cause the cache to be
390
392
// deleted, so hopefully the next compilation will succeed.
391
393
return errors .New (tr ("Internal error in cache" ))
392
394
}
395
+ l .diagnosticStore .Parse (result .Args (), result .Stderr ())
396
+ l .logger .WriteStderr (result .Stderr ())
397
+ return err
393
398
}
394
- l .logger .WriteStderr (preprocStderr )
399
+ l .diagnosticStore .Parse (preprocFirstResult .Args (), preprocFirstResult .Stderr ())
400
+ l .logger .WriteStderr (preprocFirstResult .Stderr ())
395
401
return preprocErr
396
402
}
397
403
0 commit comments