Skip to content

Commit b1a8581

Browse files
committed
Handle FQBNs provided via sketch.json files in upload/compile commands
1 parent e2bc059 commit b1a8581

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

cli/cli_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
312312
// Build sketch without FQBN
313313
exitCode, d = executeWithArgs("compile", sketchPath)
314314
require.NotZero(t, exitCode)
315-
require.Contains(t, string(d), "no FQBN provided")
315+
require.Contains(t, string(d), "Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
316316

317317
// Build sketch for arduino:avr:uno
318318
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", sketchPath)

cli/compile/compile.go

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"context"
2020
"os"
2121

22+
"github.com/arduino/arduino-cli/arduino/sketches"
23+
2224
"github.com/arduino/arduino-cli/cli/feedback"
2325

2426
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -94,6 +96,15 @@ func run(cmd *cobra.Command, args []string) {
9496
}
9597

9698
sketchPath := initSketchPath(path)
99+
sketch, err := sketches.NewSketchFromPath(sketchPath)
100+
if err != nil {
101+
feedback.Errorf("Error opening sketch: %v", err)
102+
os.Exit(errorcodes.ErrGeneric)
103+
}
104+
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
105+
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
106+
os.Exit(errorcodes.ErrGeneric)
107+
}
97108

98109
_, err = compile.Compile(context.Background(), &rpc.CompileReq{
99110
Instance: inst,

cli/upload/upload.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"context"
2020
"os"
2121

22+
"github.com/arduino/arduino-cli/arduino/sketches"
23+
2224
"github.com/arduino/arduino-cli/cli/errorcodes"
2325
"github.com/arduino/arduino-cli/cli/feedback"
2426
"github.com/arduino/arduino-cli/cli/instance"
@@ -71,8 +73,17 @@ func run(command *cobra.Command, args []string) {
7173
path = paths.New(args[0])
7274
}
7375
sketchPath := initSketchPath(path)
76+
sketch, err := sketches.NewSketchFromPath(sketchPath)
77+
if err != nil {
78+
feedback.Errorf("Error opening sketch: %v", err)
79+
os.Exit(errorcodes.ErrGeneric)
80+
}
81+
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
82+
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
83+
os.Exit(errorcodes.ErrGeneric)
84+
}
7485

75-
if _, err := upload.Upload(context.Background(), &rpc.UploadReq{
86+
if _, err = upload.Upload(context.Background(), &rpc.UploadReq{
7687
Instance: instance,
7788
Fqbn: fqbn,
7889
SketchPath: sketchPath.String(),

0 commit comments

Comments
 (0)