Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca79383

Browse files
authored
[breaking] gRPC Compile request now returns expanded build properties by default (#2184)
1 parent f328ecd commit ca79383

File tree

13 files changed

+364
-296
lines changed

13 files changed

+364
-296
lines changed

‎arduino/utils/url.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package utils
1818
import (
1919
"net/url"
2020
"runtime"
21+
22+
"github.com/arduino/go-properties-orderedmap"
2123
)
2224

2325
// URLParse parses a raw URL string and handles local files URLs depending on the platform
@@ -33,3 +35,17 @@ func URLParse(rawURL string) (*url.URL, error) {
3335
}
3436
return URL, nil
3537
}
38+
39+
// ExpandBuildProperties expands the build properties placeholders in the slice of properties.
40+
func ExpandBuildProperties(props []string) ([]string, error) {
41+
expanded, err := properties.LoadFromSlice(props)
42+
if err != nil {
43+
return nil, err
44+
}
45+
expandedProps := []string{}
46+
for _, k := range expanded.Keys() {
47+
v := expanded.Get(k)
48+
expandedProps = append(expandedProps, k+"="+expanded.ExpandPropsInString(v))
49+
}
50+
return expandedProps, nil
51+
}

‎commands/board/details.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/arduino/arduino-cli/arduino"
2222
"github.com/arduino/arduino-cli/arduino/cores"
23+
"github.com/arduino/arduino-cli/arduino/utils"
2324
"github.com/arduino/arduino-cli/commands"
2425
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2526
)
@@ -59,6 +60,9 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
5960
v := boardProperties.Get(k)
6061
details.BuildProperties = append(details.BuildProperties, k+"="+v)
6162
}
63+
if !req.GetDoNotExpandBuildProperties() {
64+
details.BuildProperties, _ = utils.ExpandBuildProperties(details.BuildProperties)
65+
}
6266

6367
details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") ||
6468
boardPlatform.Properties.ContainsKey("debug.executable") ||

‎commands/compile/compile.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
bldr "github.com/arduino/arduino-cli/arduino/builder"
2727
"github.com/arduino/arduino-cli/arduino/cores"
2828
"github.com/arduino/arduino-cli/arduino/sketch"
29+
"github.com/arduino/arduino-cli/arduino/utils"
2930
"github.com/arduino/arduino-cli/buildcache"
3031
"github.com/arduino/arduino-cli/commands"
3132
"github.com/arduino/arduino-cli/configuration"
@@ -233,6 +234,9 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
233234
for _, key := range keys {
234235
r.BuildProperties = append(r.BuildProperties, key+"="+buildProperties.Get(key))
235236
}
237+
if !req.GetDoNotExpandBuildProperties() {
238+
r.BuildProperties, _ = utils.ExpandBuildProperties(r.BuildProperties)
239+
}
236240
}()
237241

238242
if req.GetShowProperties() {

‎docs/UPGRADING.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@
22

33
Here you can find a list of migration guides to handle breaking changes between releases of the CLI.
44

5+
## 0.33.0
6+
7+
### gRPC `cc.arduino.cli.commands.v1.Compile` command now return expanded build_properties by default.
8+
9+
The gRPC `cc.arduino.cli.commands.v1.Compile` command now return expanded `build_properties` by default. If you want the
10+
**un**expanded `build_properties` you must set to `true` the field `do_not_expand_build_properties` in the
11+
`CompileRequest`.
12+
13+
### `compile --show-properties` now return the expanded build properties.
14+
15+
The command `compile --show-properties` now returns the **expanded** build properties, with the variable placeholders
16+
replaced with their current value. If you need the **un**expanded build properties you must change the command line to
17+
`compile --show-properties=unexpanded`.
18+
19+
Before:
20+
21+
```
22+
$ arduino-cli board details -b arduino:avr:uno --show-properties | grep ^tools.avrdude.path
23+
tools.avrdude.path={runtime.tools.avrdude.path}
24+
```
25+
26+
Now:
27+
28+
```
29+
$ arduino-cli board details -b arduino:avr:uno --show-properties | grep ^tools.avrdude.path
30+
tools.avrdude.path=/home/megabug/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17
31+
$ arduino-cli board details -b arduino:avr:uno --show-properties=unexpanded | grep ^tools.avrdude.path
32+
tools.avrdude.path={runtime.tools.avrdude.path}
33+
```
34+
535
## 0.32.2
636

737
### golang API: method `github.com/arduino/arduino-cli/arduino/cores/Board.GetBuildProperties` changed signature

‎internal/cli/arguments/show_properties.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (p *ShowProperties) Get() (ShowPropertiesMode, error) {
5656
func (p *ShowProperties) AddToCommand(command *cobra.Command) {
5757
command.Flags().StringVar(&p.arg,
5858
"show-properties", "disabled",
59-
tr(`Show build properties. The properties are returned exactly as they are defined. Use "--show-properties=expanded" to replace placeholders with context values.`),
59+
tr(`Show build properties. The properties are expanded, use "--show-properties=unexpanded" if you want them exactly as they are defined.`),
6060
)
61-
command.Flags().Lookup("show-properties").NoOptDefVal = "unexpanded" // default if the flag is present with no value
61+
command.Flags().Lookup("show-properties").NoOptDefVal = "expanded" // default if the flag is present with no value
6262
}

‎internal/cli/board/details.go‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/arduino/arduino-cli/commands/board"
2424
"github.com/arduino/arduino-cli/internal/cli/arguments"
25-
"github.com/arduino/arduino-cli/internal/cli/compile"
2625
"github.com/arduino/arduino-cli/internal/cli/feedback"
2726
"github.com/arduino/arduino-cli/internal/cli/instance"
2827
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -66,17 +65,14 @@ func runDetailsCommand(fqbn string, showFullDetails, listProgrammers bool, showP
6665
feedback.Fatal(err.Error(), feedback.ErrBadArgument)
6766
}
6867
res, err := board.Details(context.Background(), &rpc.BoardDetailsRequest{
69-
Instance: inst,
70-
Fqbn: fqbn,
68+
Instance: inst,
69+
Fqbn: fqbn,
70+
DoNotExpandBuildProperties: showPropertiesMode == arguments.ShowPropertiesUnexpanded,
7171
})
7272
if err != nil {
7373
feedback.Fatal(tr("Error getting board details: %v", err), feedback.ErrGeneric)
7474
}
7575

76-
if showPropertiesMode == arguments.ShowPropertiesExpanded {
77-
res.BuildProperties, _ = compile.ExpandBuildProperties(res.GetBuildProperties())
78-
}
79-
8076
feedback.PrintResult(detailsResult{
8177
details: res,
8278
listProgrammers: listProgrammers,

‎internal/cli/compile/compile.go‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/arduino/arduino-cli/table"
3939
"github.com/arduino/arduino-cli/version"
4040
"github.com/arduino/go-paths-helper"
41-
"github.com/arduino/go-properties-orderedmap"
4241
"github.com/fatih/color"
4342
"github.com/sirupsen/logrus"
4443
"github.com/spf13/cobra"
@@ -231,6 +230,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
231230
SignKey: signKey,
232231
EncryptKey: encryptKey,
233232
SkipLibrariesDiscovery: skipLibrariesDiscovery,
233+
DoNotExpandBuildProperties: showProperties == arguments.ShowPropertiesUnexpanded,
234234
}
235235
compileRes, compileError := compile.Compile(context.Background(), compileRequest, stdOut, stdErr, nil)
236236
if compileError == nil && uploadAfterCompile {
@@ -365,27 +365,9 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
365365
}
366366
feedback.FatalResult(res, feedback.ErrGeneric)
367367
}
368-
if showProperties == arguments.ShowPropertiesExpanded {
369-
res.BuilderResult.BuildProperties, _ = ExpandBuildProperties(res.BuilderResult.GetBuildProperties())
370-
// ignore error, it should never fail
371-
}
372368
feedback.PrintResult(res)
373369
}
374370

375-
// ExpandBuildProperties expands the build properties placeholders in the slice of properties.
376-
func ExpandBuildProperties(props []string) ([]string, error) {
377-
expanded, err := properties.LoadFromSlice(props)
378-
if err != nil {
379-
return nil, err
380-
}
381-
expandedProps := []string{}
382-
for _, k := range expanded.Keys() {
383-
v := expanded.Get(k)
384-
expandedProps = append(expandedProps, k+"="+expanded.ExpandPropsInString(v))
385-
}
386-
return expandedProps, nil
387-
}
388-
389371
type compileResult struct {
390372
CompilerOut string `json:"compiler_out"`
391373
CompilerErr string `json:"compiler_err"`

‎internal/integrationtest/compile_3/compile_show_properties_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ func TestCompileShowProperties(t *testing.T) {
4141
bareMinimum := cli.CopySketch("bare_minimum")
4242

4343
// Test --show-properties output is clean
44-
// properties are not expanded
44+
// properties are expanded
4545
stdout, stderr, err := cli.Run("compile", "--fqbn", "arduino:avr:uno", "-v", "--show-properties", bareMinimum.String())
4646
require.NoError(t, err)
4747
props, err := properties.LoadFromBytes(stdout)
4848
require.NoError(t, err, "Output must be a clean property list")
4949
require.Empty(t, stderr)
5050
require.True(t, props.ContainsKey("archive_file_path"))
51-
require.Contains(t, props.Get("archive_file_path"), "{build.path}")
51+
require.NotContains(t, props.Get("archive_file_path"), "{build.path}")
5252

5353
// Test --show-properties --format JSON output is clean
54-
// properties are not expanded
54+
// properties are expanded
5555
stdout, stderr, err = cli.Run("compile", "--fqbn", "arduino:avr:uno", "-v", "--show-properties", "--format", "json", bareMinimum.String())
5656
require.NoError(t, err)
5757
require.Empty(t, stderr)
5858
props, err = properties.LoadFromSlice(
5959
requireCompileResponseJson(t, stdout).BuilderResult.GetBuildProperties())
6060
require.NoError(t, err)
6161
require.True(t, props.ContainsKey("archive_file_path"))
62-
require.Contains(t, props.Get("archive_file_path"), "{build.path}")
62+
require.NotContains(t, props.Get("archive_file_path"), "{build.path}")
6363

6464
// Test --show-properties output is clean, with a wrong FQBN
6565
stdout, stderr, err = cli.Run("compile", "--fqbn", "arduino:avr:unoa", "-v", "--show-properties", bareMinimum.String())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /