Skip to content

Commit

Permalink
Handle FQBNs provided via sketch.json files in upload/compile commands
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobond committed Jan 5, 2020
1 parent 78c6480 commit 0bce37c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
// Build sketch without FQBN
exitCode, d = executeWithArgs("compile", sketchPath)
require.NotZero(t, exitCode)
require.Contains(t, string(d), "required flag(s) \"fqbn\" not set")
require.Contains(t, string(d), "Error: no FQBN provided. Set --fqbn flag or attach board to sketch")

// Build sketch for arduino:avr:uno
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", sketchPath)
Expand Down
13 changes: 11 additions & 2 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"
"os"

"github.com/arduino/arduino-cli/arduino/sketches"

"github.com/arduino/arduino-cli/cli/feedback"

"github.com/arduino/arduino-cli/cli/errorcodes"
Expand Down Expand Up @@ -80,8 +82,6 @@ func NewCommand() *cobra.Command {
command.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
command.Flags().StringVar(&vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.")

command.MarkFlagRequired("fqbn")

return command
}

Expand All @@ -98,6 +98,15 @@ func run(cmd *cobra.Command, args []string) {
}

sketchPath := initSketchPath(path)
sketch, err := sketches.NewSketchFromPath(sketchPath)
if err != nil {
feedback.Errorf("Error opening sketch: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
os.Exit(errorcodes.ErrGeneric)
}

_, err = compile.Compile(context.Background(), &rpc.CompileReq{
Instance: inst,
Expand Down
14 changes: 12 additions & 2 deletions cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"
"os"

"github.com/arduino/arduino-cli/arduino/sketches"

"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
Expand Down Expand Up @@ -56,7 +58,6 @@ func NewCommand() *cobra.Command {
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")

uploadCommand.MarkFlagRequired("fqbn")
uploadCommand.MarkFlagRequired("port")

return uploadCommand
Expand All @@ -74,8 +75,17 @@ func run(command *cobra.Command, args []string) {
path = paths.New(args[0])
}
sketchPath := initSketchPath(path)
sketch, err := sketches.NewSketchFromPath(sketchPath)
if err != nil {
feedback.Errorf("Error opening sketch: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
os.Exit(errorcodes.ErrGeneric)
}

if _, err := upload.Upload(context.Background(), &rpc.UploadReq{
if _, err = upload.Upload(context.Background(), &rpc.UploadReq{
Instance: instance,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Expand Down

0 comments on commit 0bce37c

Please sign in to comment.