Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8026881

Browse files
committedFeb 11, 2021
[breaking] Fix export binaries binding not working in gRPC interface
1 parent 0425c95 commit 8026881

File tree

6 files changed

+117
-96
lines changed

6 files changed

+117
-96
lines changed
 

‎cli/compile/compile.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ var (
5555
optimizeForDebug bool // Optimize compile output for debug, not for release
5656
programmer string // Use the specified programmer to upload
5757
clean bool // Cleanup the build folder and do not use any cached build
58-
exportBinaries bool // Copies compiled binaries to sketch folder when true
5958
compilationDatabaseOnly bool // Only create compilation database without actually compiling
6059
sourceOverrides string // Path to a .json file that contains a set of replacements of the sketch source code.
6160
)
@@ -100,8 +99,7 @@ func NewCommand() *cobra.Command {
10099
command.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload.")
101100
command.Flags().BoolVar(&compilationDatabaseOnly, "only-compilation-database", false, "Just produce the compilation database, without actually compiling.")
102101
command.Flags().BoolVar(&clean, "clean", false, "Optional, cleanup the build folder and do not use any cached build.")
103-
// We must use the following syntax for this flag since it's also bound to settings, we could use the other one too
104-
// but it wouldn't make sense since we still must explicitly set the exportBinaries variable by reading from settings.
102+
// We must use the following syntax for this flag since it's also bound to settings.
105103
// This must be done because the value is set when the binding is accessed from viper. Accessing from cobra would only
106104
// read the value if the flag is set explicitly by the user.
107105
command.Flags().BoolP("export-binaries", "e", false, "If set built binaries will be exported to the sketch folder.")
@@ -137,11 +135,6 @@ func run(cmd *cobra.Command, args []string) {
137135
}
138136
}
139137

140-
// We must read this from settings since the value is set when the binding is accessed from viper,
141-
// accessing it from cobra would only read it if the flag is explicitly set by the user and ignore
142-
// the config file and the env vars.
143-
exportBinaries = configuration.Settings.GetBool("sketch.always_export_binaries")
144-
145138
var overrides map[string]string
146139
if sourceOverrides != "" {
147140
data, err := paths.New(sourceOverrides).ReadFile()
@@ -176,7 +169,6 @@ func run(cmd *cobra.Command, args []string) {
176169
Libraries: libraries,
177170
OptimizeForDebug: optimizeForDebug,
178171
Clean: clean,
179-
ExportBinaries: exportBinaries,
180172
CreateCompilationDatabaseOnly: compilationDatabaseOnly,
181173
SourceOverride: overrides,
182174
}

‎commands/compile/compile.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ import (
4545
// Compile FIXMEDOC
4646
func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.Writer, debug bool) (r *rpc.CompileResp, e error) {
4747

48+
// There is a binding between the export binaries setting and the CLI flag to explicitly set it,
49+
// since we want this binding to work also for the gRPC interface we must read it here in this
50+
// package instead of the cli/compile one, otherwise we'd lose the binding.
51+
exportBinaries := configuration.Settings.GetBool("sketch.always_export_binaries")
52+
// If we'd just read the binding in any case, even if the request sets the export binaries setting,
53+
// the settings value would always overwrite the request one and it wouldn't have any effect
54+
// setting it for individual requests. To solve this we use a wrapper.BoolValue to handle
55+
// the optionality of this property, otherwise we would have no way of knowing if the property
56+
// was set in the request or it's just the default boolean value.
57+
if reqExportBinaries := req.GetExportBinaries(); reqExportBinaries != nil {
58+
exportBinaries = reqExportBinaries.Value
59+
}
60+
4861
tags := map[string]string{
4962
"fqbn": req.Fqbn,
5063
"sketchPath": metrics.Sanitize(req.SketchPath),
@@ -59,7 +72,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
5972
"jobs": strconv.FormatInt(int64(req.Jobs), 10),
6073
"libraries": strings.Join(req.Libraries, ","),
6174
"clean": strconv.FormatBool(req.GetClean()),
62-
"exportBinaries": strconv.FormatBool(req.GetExportBinaries()),
75+
"exportBinaries": strconv.FormatBool(exportBinaries),
6376
}
6477

6578
// Use defer func() to evaluate tags map when function returns
@@ -214,7 +227,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
214227
}
215228

216229
// If the export directory is set we assume you want to export the binaries
217-
if req.GetExportBinaries() || req.GetExportDir() != "" {
230+
if exportBinaries || req.GetExportDir() != "" {
218231
var exportPath *paths.Path
219232
if exportDir := req.GetExportDir(); exportDir != "" {
220233
exportPath = paths.New(exportDir)

‎docs/UPGRADING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## Unreleased
66

7+
### Change type of `CompileReq.ExportBinaries` message in gRPC interface
8+
9+
This change affects only the gRPC consumers.
10+
11+
In the `CompileReq` message the `export_binaries` property type has been changed from `bool` to
12+
`google.protobuf.BoolValue`. This has been done to handle settings bindings by gRPC consumers and the CLI in the same
13+
way so that they an identical behaviour.
14+
715
## 0.15.0
816

917
### Rename `telemetry` settings to `metrics`

‎rpc/commands/compile.pb.go

Lines changed: 89 additions & 82 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cc.arduino.cli.commands;
1919

2020
option go_package = "github.com/arduino/arduino-cli/rpc/commands";
2121

22+
import "google/protobuf/wrappers.proto";
2223
import "commands/common.proto";
2324
import "commands/lib.proto";
2425

@@ -40,9 +41,9 @@ message CompileReq {
4041
bool optimizeForDebug = 16; // Optimize compile output for debug, not for release.
4142
string export_dir = 18; // Optional: save the build artifacts in this directory, the directory must exist.
4243
bool clean = 19; // Optional: cleanup the build folder and do not use any previously cached build
43-
bool export_binaries = 20; // When set to `true` the compiled binary will be copied to the export directory.
4444
bool create_compilation_database_only = 21; // When set to `true` only the compilation database will be produced and no actual build will be performed.
4545
map<string, string> source_override = 22; // This map (source file -> new content) let the builder use the provided content instead of reading the corresponding file on disk. This is useful for IDE that have unsaved changes in memory. The path must be relative to the sketch directory. Only files from the sketch are allowed.
46+
google.protobuf.BoolValue export_binaries = 23; // When set to `true` the compiled binary will be copied to the export directory.
4647
}
4748

4849
message CompileResp {

‎rpc/settings/settings.pb.go

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

0 commit comments

Comments
 (0)
Please sign in to comment.