Skip to content

Commit 932c0ad

Browse files
committed
Implementation of compile output parser in gRPC command
1 parent 6d8acab commit 932c0ad

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

commands/compile/compile.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/arduino/arduino-cli/commands"
3232
"github.com/arduino/arduino-cli/configuration"
3333
"github.com/arduino/arduino-cli/i18n"
34+
"github.com/arduino/arduino-cli/internal/builder/diagnostics"
3435
"github.com/arduino/arduino-cli/internal/inventory"
3536
"github.com/arduino/arduino-cli/legacy/builder"
3637
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -168,7 +169,25 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
168169
return nil, err
169170
}
170171

172+
var allDiagnostics diagnostics.Diagnostics
173+
defer func() {
174+
r.Diagnostics = allDiagnostics.ToRPC()
175+
}()
176+
171177
builderCtx := &types.Context{}
178+
builderCtx.CompilerOutputParser = func(cmdline []string, out []byte) {
179+
compiler := diagnostics.DetectCompilerFromCommandLine(cmdline, false /* at the moment compiler-probing is not required */)
180+
if compiler == nil {
181+
logrus.Warnf("Could not detect compiler from: %s", cmdline)
182+
return
183+
}
184+
diags, err := diagnostics.ParseCompilerOutput(compiler, out)
185+
if err != nil {
186+
logrus.Warnf("Error parsing compiler output: %s", err)
187+
return
188+
}
189+
allDiagnostics = append(allDiagnostics, diags...)
190+
}
172191
builderCtx.PackageManager = pme
173192
if pme.GetProfile() != nil {
174193
builderCtx.LibrariesManager = lm

0 commit comments

Comments
 (0)