Skip to content

Commit 0f37dfb

Browse files
committed
Added "board config" flags and parameters
This is an alternative way to extended FQBN to pass board configuration options.
1 parent e98e1f0 commit 0f37dfb

File tree

16 files changed

+200
-139
lines changed

16 files changed

+200
-139
lines changed

arduino/cores/packagemanager/package_manager.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ func (pm *PackageManager) FindBoardsWithID(id string) []*cores.Board {
119119
// FindBoard search the board identified by boardArg (board alias or board fqbn).
120120
// It returns FQBN, RegistereBoard and Board or an error if not found.
121121
// The board may be present in registry but not installed, in this case o
122-
func (pm *PackageManager) FindBoard(boardArg string) (*cores.FQBN, *RegisteredBoard, *cores.Board, error) {
122+
func (pm *PackageManager) FindBoard(boardArg string, config []string) (*cores.FQBN, *RegisteredBoard, *cores.Board, error) {
123123
fqbn, registeredBoard, err := pm.Registry.FindBoard(boardArg)
124124
if err != nil {
125125
return fqbn, registeredBoard, nil, err
126126
}
127+
if config != nil {
128+
fqbn.SetConfigs(config)
129+
}
127130
board, err := pm.FindBoardWithFQBN(fqbn)
128131
return fqbn, registeredBoard, board, err
129132
}

arduino/cores/packagemanager/package_manager_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ func TestFindBoardWithFQBN(t *testing.T) {
4141
pm := packagemanager.NewPackageManager(customHardware, customHardware, customHardware, customHardware)
4242
pm.LoadHardwareFromDirectory(customHardware)
4343

44-
_, _, board, err := pm.FindBoard("arduino:avr:uno")
44+
_, _, board, err := pm.FindBoard("arduino:avr:uno", nil)
4545
require.Nil(t, err)
4646
require.NotNil(t, board)
4747
require.Equal(t, board.Name(), "Arduino/Genuino Uno")
4848

49-
_, _, board, err = pm.FindBoard("arduino:avr:mega")
49+
_, _, board, err = pm.FindBoard("arduino:avr:mega", nil)
5050
require.Nil(t, err)
5151
require.NotNil(t, board)
5252
require.Equal(t, board.Name(), "Arduino/Genuino Mega or Mega 2560")
@@ -178,7 +178,7 @@ func TestBoardOptionsFunctions(t *testing.T) {
178178
pm := packagemanager.NewPackageManager(customHardware, customHardware, customHardware, customHardware)
179179
pm.LoadHardwareFromDirectory(customHardware)
180180

181-
_, _, nano, err := pm.FindBoard("arduino:avr:nano")
181+
_, _, nano, err := pm.FindBoard("arduino:avr:nano", nil)
182182
require.Nil(t, err)
183183
require.NotNil(t, nano)
184184
require.Equal(t, nano.Name(), "Arduino Nano")
@@ -194,7 +194,7 @@ func TestBoardOptionsFunctions(t *testing.T) {
194194
expectedNanoCPUValues.Set("atmega168", "ATmega168")
195195
require.EqualValues(t, expectedNanoCPUValues, nanoCPUValues)
196196

197-
_, _, esp8266, err := pm.FindBoard("esp8266:esp8266:generic")
197+
_, _, esp8266, err := pm.FindBoard("esp8266:esp8266:generic", nil)
198198
require.Nil(t, err)
199199
require.NotNil(t, esp8266)
200200
require.Equal(t, esp8266.Name(), "Generic ESP8266 Module")
@@ -230,7 +230,7 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
230230
loadIndex("http://arduino.esp8266.com/stable/package_esp8266com_index.json")
231231
loadIndex("https://adafruit.github.io/arduino-board-index/package_adafruit_index.json")
232232
require.NoError(t, pm.LoadHardware())
233-
_, _, esp32, err := pm.FindBoard("esp32:esp32:esp32")
233+
_, _, esp32, err := pm.FindBoard("esp32:esp32:esp32", nil)
234234
require.NoError(t, err)
235235
esptool231 := pm.FindToolDependency(&cores.ToolDependency{
236236
ToolPackager: "esp32",
@@ -266,7 +266,7 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
266266
testConflictingToolsInDifferentPackages()
267267
testConflictingToolsInDifferentPackages()
268268

269-
_, _, feather, err := pm.FindBoard("adafruit:samd:adafruit_feather_m0_express")
269+
_, _, feather, err := pm.FindBoard("adafruit:samd:adafruit_feather_m0_express", nil)
270270
require.NoError(t, err)
271271
require.NotNil(t, feather)
272272
featherTools, err := pm.FindToolsRequiredForBoard(feather)

cli/board/board.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewCommand() *cobra.Command {
3434
}
3535

3636
boardCommand.AddCommand(initAttachCommand())
37-
boardCommand.AddCommand(detailsCommand)
37+
boardCommand.AddCommand(initDetailsCommand())
3838
boardCommand.AddCommand(initListCommand())
3939
boardCommand.AddCommand(listAllCommand)
4040
boardCommand.AddCommand(initInstallCommand())

cli/board/details.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,22 @@ import (
2929
"github.com/spf13/cobra"
3030
)
3131

32-
var detailsCommand = &cobra.Command{
33-
Use: "details <FQBN>",
34-
Short: "Print details about a board.",
35-
Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.",
36-
Example: " " + os.Args[0] + " board details arduino:avr:nano",
37-
Args: cobra.ExactArgs(1),
38-
Run: runDetailsCommand,
32+
func initDetailsCommand() *cobra.Command {
33+
cmd := &cobra.Command{
34+
Use: "details <FQBN | BOARD_ALIAS>",
35+
Short: "Print details about a board.",
36+
Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.",
37+
Example: " " + os.Args[0] + " board details arduino:avr:nano",
38+
Args: cobra.ExactArgs(1),
39+
Run: runDetailsCommand,
40+
}
41+
detailsFlags.boardConfig =
42+
cmd.Flags().StringSliceP("board-conf", "c", nil, "set a board configuration value. The flag can be used multiple times.\n"+"Example: "+os.Args[0]+" board details arduino:avr:nano -c cpu=atmega168")
43+
return cmd
44+
}
45+
46+
var detailsFlags struct {
47+
boardConfig *[]string
3948
}
4049

4150
func runDetailsCommand(cmd *cobra.Command, args []string) {
@@ -46,8 +55,9 @@ func runDetailsCommand(cmd *cobra.Command, args []string) {
4655
}
4756

4857
res, err := board.Details(context.Background(), &rpc.BoardDetailsReq{
49-
Instance: inst,
50-
Fqbn: args[0],
58+
Instance: inst,
59+
Board: args[0],
60+
BoardConfig: *detailsFlags.boardConfig,
5161
})
5262

5363
if err != nil {

cli/compile/compile.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import (
3333
)
3434

3535
var (
36-
boardArg string // Board Alias or Board FQBN
36+
boardArg string // Board Alias or Board FQBN
37+
boardConfig *[]string // Board Configuration
38+
3739
showProperties bool // Show all build preferences used instead of compiling.
3840
preprocess bool // Print preprocessed code to stdout.
3941
buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
@@ -64,6 +66,8 @@ func NewCommand() *cobra.Command {
6466
}
6567

6668
command.Flags().StringVarP(&boardArg, "board", "b", "", "Board Alias or Board FQBN (e.g. 'arduino:avr:uno')")
69+
boardConfig =
70+
command.Flags().StringSliceP("board-conf", "c", nil, "set a board configuration value. The flag can be used multiple times.\n"+"Example: "+os.Args[0]+" board details arduino:avr:nano -c cpu=atmega168")
6771
command.Flags().StringVarP(&boardArg, "fqbn", "", "", "")
6872
command.Flags().MarkDeprecated("fqbn", "use --board instead.")
6973
command.Flags().BoolVar(&showProperties, "show-properties", false, "Show all build properties used instead of compiling.")
@@ -107,6 +111,7 @@ func run(cmd *cobra.Command, args []string) {
107111
_, err = compile.Compile(context.Background(), &rpc.CompileReq{
108112
Instance: inst,
109113
Board: boardArg,
114+
BoardConfig: *boardConfig,
110115
SketchPath: sketchPath.String(),
111116
ShowProperties: showProperties,
112117
Preprocess: preprocess,

cli/upload/upload.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import (
3030
)
3131

3232
var (
33-
boardArg string
33+
boardArg string
34+
boardConfig *[]string
35+
3436
port string
3537
verbose bool
3638
verify bool
@@ -49,6 +51,8 @@ func NewCommand() *cobra.Command {
4951
}
5052

5153
uploadCommand.Flags().StringVarP(&boardArg, "board", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno")
54+
boardConfig =
55+
uploadCommand.Flags().StringSliceP("board-conf", "c", nil, "set a board configuration value. The flag can be used multiple times.\n"+"Example: "+os.Args[0]+" board details arduino:avr:nano -c cpu=atmega168")
5256
uploadCommand.Flags().StringVarP(&boardArg, "fqbn", "", "", "")
5357
uploadCommand.Flags().MarkDeprecated("fqbn", "use --board instead.")
5458
uploadCommand.Flags().StringVarP(&port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0")

commands/board/details.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ package board
1818
import (
1919
"context"
2020
"errors"
21-
"fmt"
2221

23-
"github.com/arduino/arduino-cli/arduino/cores"
2422
"github.com/arduino/arduino-cli/commands"
2523
rpc "github.com/arduino/arduino-cli/rpc/commands"
2624
)
@@ -32,14 +30,14 @@ func Details(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsRe
3230
return nil, errors.New("invalid instance")
3331
}
3432

35-
fqbn, err := cores.ParseFQBN(req.GetFqbn())
36-
if err != nil {
37-
return nil, fmt.Errorf("parsing fqbn: %s", err)
33+
boardArg := req.GetBoard()
34+
if boardArg == "" {
35+
boardArg = req.GetFqbn() // Deprecated: use FQBN for old client.
3836
}
39-
40-
_, _, board, _, _, err := pm.ResolveFQBN(fqbn)
37+
fqbn, _, board, err := pm.FindBoard(boardArg, req.GetBoardConfig())
38+
// TODO: do not ignore *RegisteredBoard result, but output data from it?
4139
if err != nil {
42-
return nil, fmt.Errorf("loading board data: %s", err)
40+
return nil, err
4341
}
4442

4543
details := &rpc.BoardDetailsResp{}

commands/board/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Install(ctx context.Context, req *rpc.BoardInstallReq,
3535
return nil, errors.New("invalid instance")
3636
}
3737

38-
fqbn, _, _, err := pm.FindBoard(req.GetBoard())
38+
fqbn, _, _, err := pm.FindBoard(req.GetBoard(), nil)
3939
if err != nil {
4040
return nil, errors.Errorf("board '%s' not found: %s", req.GetBoard(), err)
4141
}

commands/compile/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
9696
return nil, errors.Errorf("no board provided")
9797
}
9898

99-
fqbn, _, _, err := pm.FindBoard(boardArg)
99+
fqbn, _, _, err := pm.FindBoard(boardArg, req.GetBoardConfig())
100100
if err != nil {
101101
return nil, errors.Errorf("board '%s' not found: %s", req.GetBoard(), err)
102102
}

commands/upload/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
8080
}
8181

8282
pm := commands.GetPackageManager(req.GetInstance().GetId())
83-
fqbn, _, _, err := pm.FindBoard(boardArg)
83+
fqbn, _, _, err := pm.FindBoard(boardArg, req.GetBoardConfig())
8484
if err != nil {
8585
return nil, errors.Errorf("board '%s' not found: %s", req.GetBoard(), err)
8686
}

0 commit comments

Comments
 (0)