Skip to content

Commit 6732ae0

Browse files
authored
[breaking] gRPC updates to CompilerResponse, UploadUsingProgrammerResponse, and BurnBootloaderResponse (#2472)
* Refactored gRPC CompilerResponse * Refactored gRPC UploadUsingProgrammerResponse and BurnBootloaderResponse
1 parent 72dd249 commit 6732ae0

File tree

11 files changed

+634
-304
lines changed

11 files changed

+634
-304
lines changed

Diff for: commands/compile/compile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
var tr = i18n.Tr
4343

4444
// Compile FIXMEDOC
45-
func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream io.Writer, progressCB rpc.TaskProgressCB) (r *rpc.CompileResponse, e error) {
45+
func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream io.Writer, progressCB rpc.TaskProgressCB) (r *rpc.BuilderResult, e error) {
4646

4747
// There is a binding between the export binaries setting and the CLI flag to explicitly set it,
4848
// since we want this binding to work also for the gRPC interface we must read it here in this
@@ -105,7 +105,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
105105
return nil, &cmderrors.InvalidFQBNError{Cause: err}
106106
}
107107

108-
r = &rpc.CompileResponse{}
108+
r = &rpc.BuilderResult{}
109109
r.BoardPlatform = targetPlatform.ToRPCPlatformReference()
110110
r.BuildPlatform = buildPlatform.ToRPCPlatformReference()
111111

Diff for: commands/daemon/daemon.go

+50-11
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,31 @@ func (s *ArduinoCoreServerImpl) SetSketchDefaults(ctx context.Context, req *rpc.
181181
// Compile FIXMEDOC
182182
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.ArduinoCoreService_CompileServer) error {
183183
syncSend := NewSynchronizedSend(stream.Send)
184-
outStream := feedStreamTo(func(data []byte) { syncSend.Send(&rpc.CompileResponse{OutStream: data}) })
185-
errStream := feedStreamTo(func(data []byte) { syncSend.Send(&rpc.CompileResponse{ErrStream: data}) })
186-
compileResp, compileErr := compile.Compile(
187-
stream.Context(), req, outStream, errStream,
188-
func(p *rpc.TaskProgress) { syncSend.Send(&rpc.CompileResponse{Progress: p}) })
184+
outStream := feedStreamTo(func(data []byte) {
185+
syncSend.Send(&rpc.CompileResponse{
186+
Message: &rpc.CompileResponse_OutStream{OutStream: data},
187+
})
188+
})
189+
errStream := feedStreamTo(func(data []byte) {
190+
syncSend.Send(&rpc.CompileResponse{
191+
Message: &rpc.CompileResponse_ErrStream{ErrStream: data},
192+
})
193+
})
194+
progressStream := func(p *rpc.TaskProgress) {
195+
syncSend.Send(&rpc.CompileResponse{
196+
Message: &rpc.CompileResponse_Progress{Progress: p},
197+
})
198+
}
199+
compileRes, compileErr := compile.Compile(stream.Context(), req, outStream, errStream, progressStream)
189200
outStream.Close()
190201
errStream.Close()
191202
var compileRespSendErr error
192-
if compileResp != nil {
193-
compileRespSendErr = syncSend.Send(compileResp)
203+
if compileRes != nil {
204+
compileRespSendErr = syncSend.Send(&rpc.CompileResponse{
205+
Message: &rpc.CompileResponse_Result{
206+
Result: compileRes,
207+
},
208+
})
194209
}
195210
if compileErr != nil {
196211
return convertErrorToRPCStatus(compileErr)
@@ -287,8 +302,20 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadRequest, stream rpc.Arduin
287302
// UploadUsingProgrammer FIXMEDOC
288303
func (s *ArduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgrammerRequest, stream rpc.ArduinoCoreService_UploadUsingProgrammerServer) error {
289304
syncSend := NewSynchronizedSend(stream.Send)
290-
outStream := feedStreamTo(func(data []byte) { syncSend.Send(&rpc.UploadUsingProgrammerResponse{OutStream: data}) })
291-
errStream := feedStreamTo(func(data []byte) { syncSend.Send(&rpc.UploadUsingProgrammerResponse{ErrStream: data}) })
305+
outStream := feedStreamTo(func(data []byte) {
306+
syncSend.Send(&rpc.UploadUsingProgrammerResponse{
307+
Message: &rpc.UploadUsingProgrammerResponse_OutStream{
308+
OutStream: data,
309+
},
310+
})
311+
})
312+
errStream := feedStreamTo(func(data []byte) {
313+
syncSend.Send(&rpc.UploadUsingProgrammerResponse{
314+
Message: &rpc.UploadUsingProgrammerResponse_ErrStream{
315+
ErrStream: data,
316+
},
317+
})
318+
})
292319
err := upload.UsingProgrammer(stream.Context(), req, outStream, errStream)
293320
outStream.Close()
294321
errStream.Close()
@@ -307,8 +334,20 @@ func (s *ArduinoCoreServerImpl) SupportedUserFields(ctx context.Context, req *rp
307334
// BurnBootloader FIXMEDOC
308335
func (s *ArduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderRequest, stream rpc.ArduinoCoreService_BurnBootloaderServer) error {
309336
syncSend := NewSynchronizedSend(stream.Send)
310-
outStream := feedStreamTo(func(data []byte) { syncSend.Send(&rpc.BurnBootloaderResponse{OutStream: data}) })
311-
errStream := feedStreamTo(func(data []byte) { syncSend.Send(&rpc.BurnBootloaderResponse{ErrStream: data}) })
337+
outStream := feedStreamTo(func(data []byte) {
338+
syncSend.Send(&rpc.BurnBootloaderResponse{
339+
Message: &rpc.BurnBootloaderResponse_OutStream{
340+
OutStream: data,
341+
},
342+
})
343+
})
344+
errStream := feedStreamTo(func(data []byte) {
345+
syncSend.Send(&rpc.BurnBootloaderResponse{
346+
Message: &rpc.BurnBootloaderResponse_ErrStream{
347+
ErrStream: data,
348+
},
349+
})
350+
})
312351
resp, err := upload.BurnBootloader(stream.Context(), req, outStream, errStream)
313352
outStream.Close()
314353
errStream.Close()

Diff for: docs/UPGRADING.md

+110
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,116 @@ breaking changes as needed.
7272
{ "sketch_path": "/tmp/my_sketch" }
7373
```
7474

75+
### The gRPC response `cc.arduino.cli.commands.v1.CompileResponse` has been changed.
76+
77+
The `CompilerResponse` message has been refactored to made explicit which fields are intended for streaming the build
78+
process and which fields are part of the build result.
79+
80+
The old `CompilerResposne`:
81+
82+
```protoc
83+
message CompileResponse {
84+
// The output of the compilation process (stream)
85+
bytes out_stream = 1;
86+
// The error output of the compilation process (stream)
87+
bytes err_stream = 2;
88+
// The compiler build path
89+
string build_path = 3;
90+
// The libraries used in the build
91+
repeated Library used_libraries = 4;
92+
// The size of the executable split by sections
93+
repeated ExecutableSectionSize executable_sections_size = 5;
94+
// The platform where the board is defined
95+
InstalledPlatformReference board_platform = 6;
96+
// The platform used for the build (if referenced from the board platform)
97+
InstalledPlatformReference build_platform = 7;
98+
// Completions reports of the compilation process (stream)
99+
TaskProgress progress = 8;
100+
// Build properties used for compiling
101+
repeated string build_properties = 9;
102+
// Compiler errors and warnings
103+
repeated CompileDiagnostic diagnostics = 10;
104+
}
105+
```
106+
107+
has been split into a `CompilerResponse` and a `BuilderResult`:
108+
109+
```protoc
110+
message CompileResponse {
111+
oneof message {
112+
// The output of the compilation process (stream)
113+
bytes out_stream = 1;
114+
// The error output of the compilation process (stream)
115+
bytes err_stream = 2;
116+
// Completions reports of the compilation process (stream)
117+
TaskProgress progress = 3;
118+
// The compilation result
119+
BuilderResult result = 4;
120+
}
121+
}
122+
123+
message BuilderResult {
124+
// The compiler build path
125+
string build_path = 1;
126+
// The libraries used in the build
127+
repeated Library used_libraries = 2;
128+
// The size of the executable split by sections
129+
repeated ExecutableSectionSize executable_sections_size = 3;
130+
// The platform where the board is defined
131+
InstalledPlatformReference board_platform = 4;
132+
// The platform used for the build (if referenced from the board platform)
133+
InstalledPlatformReference build_platform = 5;
134+
// Build properties used for compiling
135+
repeated string build_properties = 7;
136+
// Compiler errors and warnings
137+
repeated CompileDiagnostic diagnostics = 8;
138+
}
139+
```
140+
141+
with a clear distinction on which fields are streamed.
142+
143+
### The gRPC response `cc.arduino.cli.commands.v1.UploadUsingProgrammerResponse` and `cc.arduino.cli.commands.v1.BurnBootloaderResponse` has been changed.
144+
145+
The old messages:
146+
147+
```protoc
148+
message UploadUsingProgrammerResponse {
149+
// The output of the upload process.
150+
bytes out_stream = 1;
151+
// The error output of the upload process.
152+
bytes err_stream = 2;
153+
}
154+
155+
message BurnBootloaderResponse {
156+
// The output of the burn bootloader process.
157+
bytes out_stream = 1;
158+
// The error output of the burn bootloader process.
159+
bytes err_stream = 2;
160+
}
161+
```
162+
163+
now have the `oneof` clause that makes explicit the streaming nature of the response:
164+
165+
```protoc
166+
message UploadUsingProgrammerResponse {
167+
oneof message {
168+
// The output of the upload process.
169+
bytes out_stream = 1;
170+
// The error output of the upload process.
171+
bytes err_stream = 2;
172+
}
173+
}
174+
175+
message BurnBootloaderResponse {
176+
oneof message {
177+
// The output of the burn bootloader process.
178+
bytes out_stream = 1;
179+
// The error output of the burn bootloader process.
180+
bytes err_stream = 2;
181+
}
182+
}
183+
```
184+
75185
### The gRPC `cc.arduino.cli.commands.v1.PlatformRelease` has been changed.
76186

77187
We've added a new field called `compatible`. This field indicates if the current platform release is installable or not.

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
245245
SkipLibrariesDiscovery: skipLibrariesDiscovery,
246246
DoNotExpandBuildProperties: showProperties == arguments.ShowPropertiesUnexpanded,
247247
}
248-
compileRes, compileError := compile.Compile(context.Background(), compileRequest, stdOut, stdErr, nil)
248+
builderRes, compileError := compile.Compile(context.Background(), compileRequest, stdOut, stdErr, nil)
249249

250250
var uploadRes *rpc.UploadResult
251251
if compileError == nil && uploadAfterCompile {
@@ -300,7 +300,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
300300

301301
libs := ""
302302
hasVendoredLibs := false
303-
for _, lib := range compileRes.GetUsedLibraries() {
303+
for _, lib := range builderRes.GetUsedLibraries() {
304304
if lib.GetLocation() != rpc.LibraryLocation_LIBRARY_LOCATION_USER && lib.GetLocation() != rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED {
305305
continue
306306
}
@@ -325,13 +325,13 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
325325
profileOut += fmt.Sprintln(" " + newProfileName + ":")
326326
profileOut += fmt.Sprintln(" fqbn: " + compileRequest.GetFqbn())
327327
profileOut += fmt.Sprintln(" platforms:")
328-
boardPlatform := compileRes.GetBoardPlatform()
328+
boardPlatform := builderRes.GetBoardPlatform()
329329
profileOut += fmt.Sprintln(" - platform: " + boardPlatform.GetId() + " (" + boardPlatform.GetVersion() + ")")
330330
if url := boardPlatform.GetPackageUrl(); url != "" {
331331
profileOut += fmt.Sprintln(" platform_index_url: " + url)
332332
}
333333

334-
if buildPlatform := compileRes.GetBuildPlatform(); buildPlatform != nil &&
334+
if buildPlatform := builderRes.GetBuildPlatform(); buildPlatform != nil &&
335335
buildPlatform.GetId() != boardPlatform.GetId() &&
336336
buildPlatform.GetVersion() != boardPlatform.GetVersion() {
337337
profileOut += fmt.Sprintln(" - platform: " + buildPlatform.GetId() + " (" + buildPlatform.GetVersion() + ")")
@@ -350,12 +350,12 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
350350
res := &compileResult{
351351
CompilerOut: stdIO.Stdout,
352352
CompilerErr: stdIO.Stderr,
353-
BuilderResult: result.NewCompileResponse(compileRes),
353+
BuilderResult: result.NewBuilderResult(builderRes),
354354
UploadResult: updatedUploadPortResult{
355355
UpdatedUploadPort: result.NewPort(uploadRes.GetUpdatedUploadPort()),
356356
},
357357
ProfileOut: profileOut,
358-
Diagnostics: result.NewCompileDiagnostics(compileRes.GetDiagnostics()),
358+
Diagnostics: result.NewCompileDiagnostics(builderRes.GetDiagnostics()),
359359
Success: compileError == nil,
360360
showPropertiesMode: showProperties,
361361
hideStats: preprocess,
@@ -401,7 +401,7 @@ type updatedUploadPortResult struct {
401401
type compileResult struct {
402402
CompilerOut string `json:"compiler_out"`
403403
CompilerErr string `json:"compiler_err"`
404-
BuilderResult *result.CompileResponse `json:"builder_result"`
404+
BuilderResult *result.BuilderResult `json:"builder_result"`
405405
UploadResult updatedUploadPortResult `json:"upload_result"`
406406
Success bool `json:"success"`
407407
ProfileOut string `json:"profile_out,omitempty"`

Diff for: internal/cli/feedback/result/rpc.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,7 @@ func NewMonitorPortSettingDescriptor(m *rpc.MonitorPortSettingDescriptor) *Monit
909909
}
910910
}
911911

912-
type CompileResponse struct {
913-
OutStream []byte `json:"out_stream,omitempty"`
914-
ErrStream []byte `json:"err_stream,omitempty"`
912+
type BuilderResult struct {
915913
BuildPath string `json:"build_path,omitempty"`
916914
UsedLibraries []*Library `json:"used_libraries,omitempty"`
917915
ExecutableSectionsSize []*ExecutableSectionSize `json:"executable_sections_size,omitempty"`
@@ -921,7 +919,7 @@ type CompileResponse struct {
921919
Diagnostics []*CompileDiagnostic `json:"diagnostics,omitempty"`
922920
}
923921

924-
func NewCompileResponse(c *rpc.CompileResponse) *CompileResponse {
922+
func NewBuilderResult(c *rpc.BuilderResult) *BuilderResult {
925923
if c == nil {
926924
return nil
927925
}
@@ -934,9 +932,7 @@ func NewCompileResponse(c *rpc.CompileResponse) *CompileResponse {
934932
executableSectionsSizes[i] = NewExecutableSectionSize(v)
935933
}
936934

937-
return &CompileResponse{
938-
OutStream: c.GetOutStream(),
939-
ErrStream: c.GetErrStream(),
935+
return &BuilderResult{
940936
BuildPath: c.GetBuildPath(),
941937
UsedLibraries: usedLibs,
942938
ExecutableSectionsSize: executableSectionsSizes,

Diff for: internal/cli/feedback/result/rpc_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ func TestAllFieldAreMapped(t *testing.T) {
190190
monitorPortSettingDescriptorResult := result.NewMonitorPortSettingDescriptor(monitorPortSettingDescriptorRpc)
191191
mustContainsAllPropertyOfRpcStruct(t, monitorPortSettingDescriptorRpc, monitorPortSettingDescriptorResult)
192192

193-
compileResponseRpc := &rpc.CompileResponse{}
194-
compileResponseResult := result.NewCompileResponse(compileResponseRpc)
195-
mustContainsAllPropertyOfRpcStruct(t, compileResponseRpc, compileResponseResult, "progress")
193+
builderResultRpc := &rpc.BuilderResult{}
194+
builderResultResult := result.NewBuilderResult(builderResultRpc)
195+
mustContainsAllPropertyOfRpcStruct(t, builderResultRpc, builderResultResult)
196196

197197
executableSectionSizeRpc := &rpc.ExecutableSectionSize{}
198198
executableSectionSizeResult := result.NewExecutableSectionSize(executableSectionSizeRpc)

Diff for: internal/integrationtest/compile_3/compile_show_properties_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import (
2020
"testing"
2121

2222
"github.com/arduino/arduino-cli/internal/integrationtest"
23-
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
23+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2424
"github.com/arduino/go-properties-orderedmap"
2525
"github.com/stretchr/testify/require"
2626
)
2727

2828
type cliCompileResponse struct {
29-
BuilderResult *commands.CompileResponse `json:"builder_result"`
29+
BuilderResult *rpc.BuilderResult `json:"builder_result"`
3030
}
3131

3232
func TestCompileShowProperties(t *testing.T) {

0 commit comments

Comments
 (0)