Skip to content

Commit bb0727d

Browse files
committed
Implementation of compile output parser in gRPC command
1 parent bdf748e commit bb0727d

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

Diff for: arduino/builder/builder.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3838
"github.com/arduino/go-paths-helper"
3939
"github.com/arduino/go-properties-orderedmap"
40+
"github.com/sirupsen/logrus"
4041
)
4142

4243
// ErrSketchCannotBeLocatedInBuildPath fixdoc
@@ -95,6 +96,8 @@ type Builder struct {
9596
// This is a function used to parse the output of the compiler
9697
// It is used to extract errors and warnings
9798
compilerOutputParser diagnostics.CompilerOutputParserCB
99+
// and here are the diagnostics parsed from the compiler
100+
compilerDiagnostics diagnostics.Diagnostics
98101
}
99102

100103
// buildArtifacts contains the result of various build
@@ -194,7 +197,7 @@ func NewBuilder(
194197
logger.Warn(string(verboseOut))
195198
}
196199

197-
return &Builder{
200+
b := &Builder{
198201
sketch: sk,
199202
buildProperties: buildProperties,
200203
buildPath: buildPath,
@@ -231,7 +234,26 @@ func NewBuilder(
231234
buildProperties.GetPath("runtime.platform.path"),
232235
buildProperties.GetPath("build.core.path"), // TODO can we buildCorePath ?
233236
),
234-
}, nil
237+
}
238+
239+
b.compilerOutputParser = func(cmdline []string, out []byte) {
240+
compiler := diagnostics.DetectCompilerFromCommandLine(
241+
cmdline,
242+
false, // at the moment compiler-probing is not required
243+
)
244+
if compiler == nil {
245+
logrus.Warnf("Could not detect compiler from: %s", cmdline)
246+
return
247+
}
248+
diags, err := diagnostics.ParseCompilerOutput(compiler, out)
249+
if err != nil {
250+
logrus.Warnf("Error parsing compiler output: %s", err)
251+
return
252+
}
253+
b.compilerDiagnostics = append(b.compilerDiagnostics, diags...)
254+
}
255+
256+
return b, nil
235257
}
236258

237259
// GetBuildProperties returns the build properties for running this build
@@ -254,6 +276,11 @@ func (b *Builder) ImportedLibraries() libraries.List {
254276
return b.libsDetector.ImportedLibraries()
255277
}
256278

279+
// CompilerDiagnostics returns the parsed compiler diagnostics
280+
func (b *Builder) CompilerDiagnostics() diagnostics.Diagnostics {
281+
return b.compilerDiagnostics
282+
}
283+
257284
// Preprocess fixdoc
258285
func (b *Builder) Preprocess() ([]byte, error) {
259286
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 {

Diff for: internal/cli/compile/compile.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
348348
UpdatedUploadPort: result.NewPort(uploadRes.GetUpdatedUploadPort()),
349349
},
350350
ProfileOut: profileOut,
351+
Diagnostics: compileRes.GetDiagnostics(),
351352
Success: compileError == nil,
352353
showPropertiesMode: showProperties,
353354
hideStats: preprocess,
@@ -399,7 +400,8 @@ type compileResult struct {
399400
Success bool `json:"success"`
400401
ProfileOut string `json:"profile_out,omitempty"`
401402
Error string `json:"error,omitempty"`
402-
403+
// TODO: make a proper result.* structure
404+
Diagnostics []*rpc.CompileDiagnostic `json:"diagnostics"`
403405
showPropertiesMode arguments.ShowPropertiesMode
404406
hideStats bool
405407
}

0 commit comments

Comments
 (0)