Skip to content

Commit d4f67e5

Browse files
committed
Implementation of compile output parser in gRPC command
1 parent 1128f3e commit d4f67e5

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Diff for: arduino/builder/builder.go

+30-2
Original file line numberDiff line numberDiff line change
@@ -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
251279
func (b *Builder) Preprocess() error {
252280
b.Progress.AddSubSteps(6)

Diff for: commands/compile/compile.go

+5
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
177177
if pme.GetProfile() != nil {
178178
libsManager = lm
179179
}
180+
180181
sketchBuilder, err := builder.NewBuilder(
181182
sk,
182183
boardBuildProperties,
@@ -218,6 +219,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
218219
}
219220
}()
220221

222+
defer func() {
223+
r.Diagnostics = sketchBuilder.CompilerDiagnostics().ToRPC()
224+
}()
225+
221226
defer func() {
222227
buildProperties := sketchBuilder.GetBuildProperties()
223228
if buildProperties == nil {

0 commit comments

Comments
 (0)