@@ -32,6 +32,7 @@ import (
3232 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3333 "github.com/arduino/go-paths-helper"
3434 "github.com/arduino/go-properties-orderedmap"
35+ "github.com/sirupsen/logrus"
3536)
3637
3738// ErrSketchCannotBeLocatedInBuildPath fixdoc
@@ -90,6 +91,9 @@ type Builder struct {
9091 // This is a function used to parse the output of the compiler
9192 // It is used to extract errors and warnings
9293 compilerOutputParser diagnostics.CompilerOutputParserCB
94+ // There are the diagnostics parsed from the compiler
95+ compilerDiagnostics diagnostics.Diagnostics
96+ // TODO: diagnostics can be done better here
9397}
9498
9599// buildArtifacts contains the result of various build
@@ -187,7 +191,7 @@ func NewBuilder(
187191 logger .Warn (string (verboseOut ))
188192 }
189193
190- return & Builder {
194+ b := & Builder {
191195 sketch : sk ,
192196 buildProperties : buildProperties ,
193197 buildPath : buildPath ,
@@ -224,7 +228,26 @@ func NewBuilder(
224228 buildProperties .GetPath ("runtime.platform.path" ),
225229 buildProperties .GetPath ("build.core.path" ), // TODO can we buildCorePath ?
226230 ),
227- }, nil
231+ }
232+
233+ b .compilerOutputParser = func (cmdline []string , out []byte ) {
234+ compiler := diagnostics .DetectCompilerFromCommandLine (
235+ cmdline ,
236+ false , // at the moment compiler-probing is not required
237+ )
238+ if compiler == nil {
239+ logrus .Warnf ("Could not detect compiler from: %s" , cmdline )
240+ return
241+ }
242+ diags , err := diagnostics .ParseCompilerOutput (compiler , out )
243+ if err != nil {
244+ logrus .Warnf ("Error parsing compiler output: %s" , err )
245+ return
246+ }
247+ b .compilerDiagnostics = append (b .compilerDiagnostics , diags ... )
248+ }
249+
250+ return b , nil
228251}
229252
230253// GetBuildProperties returns the build properties for running this build
@@ -247,6 +270,11 @@ func (b *Builder) ImportedLibraries() libraries.List {
247270 return b .libsDetector .ImportedLibraries ()
248271}
249272
273+ // CompilerDiagnostics returns the parsed compiler diagnostics
274+ func (b * Builder ) CompilerDiagnostics () diagnostics.Diagnostics {
275+ return b .compilerDiagnostics
276+ }
277+
250278// Preprocess fixdoc
251279func (b * Builder ) Preprocess () error {
252280 b .Progress .AddSubSteps (6 )
0 commit comments