Skip to content

Commit 0374489

Browse files
committed
Give some more info in compiler json output
1 parent 6f0d6d8 commit 0374489

File tree

4 files changed

+107
-60
lines changed

4 files changed

+107
-60
lines changed

cli/compile/compile.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ func run(cmd *cobra.Command, args []string) {
148148
compileOut := new(bytes.Buffer)
149149
compileErr := new(bytes.Buffer)
150150
verboseCompile := configuration.Settings.GetString("logging.level") == "debug"
151+
var compileRes *rpc.CompileResp
151152
if output.OutputFormat == "json" {
152-
_, err = compile.Compile(context.Background(), compileReq, compileOut, compileErr, verboseCompile)
153+
compileRes, err = compile.Compile(context.Background(), compileReq, compileOut, compileErr, verboseCompile)
153154
} else {
154-
_, err = compile.Compile(context.Background(), compileReq, os.Stdout, os.Stderr, verboseCompile)
155+
compileRes, err = compile.Compile(context.Background(), compileReq, os.Stdout, os.Stderr, verboseCompile)
155156
}
156157
if err != nil {
157158
feedback.Errorf("Error during build: %v", err)
@@ -185,8 +186,9 @@ func run(cmd *cobra.Command, args []string) {
185186
}
186187

187188
feedback.PrintResult(&compileResult{
188-
CompileOut: compileOut.String(),
189-
CompileErr: compileErr.String(),
189+
CompileOut: compileOut.String(),
190+
CompileErr: compileErr.String(),
191+
BuilderResult: compileRes,
190192
})
191193
}
192194

@@ -206,8 +208,9 @@ func initSketchPath(sketchPath *paths.Path) *paths.Path {
206208
}
207209

208210
type compileResult struct {
209-
CompileOut string
210-
CompileErr string
211+
CompileOut string `json:"compiler_out"`
212+
CompileErr string `json:"compiler_err"`
213+
BuilderResult *rpc.CompileResp `json:"builder_result"`
211214
}
212215

213216
func (r *compileResult) Data() interface{} {

commands/compile/compile.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
189189
builderCtx.SetLogger(i18n.LoggerToCustomStreams{Stdout: outStream, Stderr: errStream})
190190
builderCtx.Clean = req.GetClean()
191191

192+
// Use defer() to create an rpc.CompileResp with all the information available at the
193+
// moment of return.
194+
defer func() {
195+
if r != nil {
196+
importedLibs := []*rpc.Library{}
197+
for _, lib := range builderCtx.ImportedLibraries {
198+
importedLibs = append(importedLibs, lib.ToRPCLibrary())
199+
}
200+
201+
r.BuildPath = builderCtx.BuildPath.String()
202+
r.UsedLibraries = importedLibs
203+
}
204+
}()
205+
192206
// if --preprocess or --show-properties were passed, we can stop here
193207
if req.GetShowProperties() {
194208
return &rpc.CompileResp{}, builder.RunParseHardwareAndDumpBuildProperties(builderCtx)

rpc/commands/compile.pb.go

Lines changed: 81 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/commands/compile.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package cc.arduino.cli.commands;
2020
option go_package = "github.com/arduino/arduino-cli/rpc/commands";
2121

2222
import "commands/common.proto";
23+
import "commands/lib.proto";
2324

2425
message CompileReq {
2526
Instance instance = 1; // Arduino Core Service instance from the `Init` response.
@@ -45,4 +46,6 @@ message CompileReq {
4546
message CompileResp {
4647
bytes out_stream = 1; // The output of the compilation process.
4748
bytes err_stream = 2; // The error output of the compilation process.
49+
string build_path = 3; // The compiler build path
50+
repeated Library used_libraries = 4; // The libraries used in the build
4851
}

0 commit comments

Comments
 (0)