Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9199e9e

Browse files
committed
Implementation of compile output parser in gRPC command
1 parent 2f7eac2 commit 9199e9e

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

‎arduino/builder/builder.go‎

Lines changed: 29 additions & 2 deletions
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)

‎commands/compile/compile.go‎

Lines changed: 5 additions & 0 deletions
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 {

‎internal/cli/compile/compile.go‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
345345
BuilderResult: compileRes,
346346
UploadResult: uploadRes,
347347
ProfileOut: profileOut,
348+
Diagnostics: compileRes.GetDiagnostics(),
348349
Success: compileError == nil,
349350
showPropertiesMode: showProperties,
350351
hideStats: preprocess,
@@ -385,14 +386,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
385386
}
386387

387388
type compileResult struct {
388-
CompilerOut string `json:"compiler_out"`
389-
CompilerErr string `json:"compiler_err"`
390-
BuilderResult *rpc.CompileResponse `json:"builder_result"`
391-
UploadResult *rpc.UploadResult `json:"upload_result"`
392-
Success bool `json:"success"`
393-
ProfileOut string `json:"profile_out,omitempty"`
394-
Error string `json:"error,omitempty"`
395-
389+
CompilerOut string `json:"compiler_out"`
390+
CompilerErr string `json:"compiler_err"`
391+
BuilderResult *rpc.CompileResponse `json:"builder_result"`
392+
UploadResult *rpc.UploadResult `json:"upload_result"`
393+
Success bool `json:"success"`
394+
ProfileOut string `json:"profile_out,omitempty"`
395+
Error string `json:"error,omitempty"`
396+
Diagnostics []*rpc.CompileDiagnostic`json:"diagnostics"`
396397
showPropertiesMode arguments.ShowPropertiesMode
397398
hideStats bool
398399
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /