Skip to content

Commit 7db3769

Browse files
committed
Implementation of compile output parser in gRPC command
1 parent cf494d6 commit 7db3769

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

commands/compile/compile.go

+19
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/inventory"
3536
"github.com/arduino/arduino-cli/legacy/builder"
3637
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -164,7 +165,25 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
164165
return nil, err
165166
}
166167

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

0 commit comments

Comments
 (0)