Skip to content

Added possibility to set custom properties on upload/burn-bootloader/debug commands. #2693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions commands/service_debug_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"slices"
"strconv"
Expand Down Expand Up @@ -55,13 +56,14 @@ func (s *arduinoCoreServerImpl) IsDebugSupported(ctx context.Context, req *rpc.I
}
defer release()
configRequest := &rpc.GetDebugConfigRequest{
Instance: req.GetInstance(),
Fqbn: req.GetFqbn(),
SketchPath: "",
Port: req.GetPort(),
Interpreter: req.GetInterpreter(),
ImportDir: "",
Programmer: req.GetProgrammer(),
Instance: req.GetInstance(),
Fqbn: req.GetFqbn(),
SketchPath: "",
Port: req.GetPort(),
Interpreter: req.GetInterpreter(),
ImportDir: "",
Programmer: req.GetProgrammer(),
DebugProperties: req.GetDebugProperties(),
}
expectedOutput, err := getDebugProperties(configRequest, pme, true)
var x *cmderrors.FailedDebugError
Expand Down Expand Up @@ -202,6 +204,13 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
}
}

// Add user provided custom debug properties
if p, err := properties.LoadFromSlice(req.GetDebugProperties()); err == nil {
debugProperties.Merge(p)
} else {
return nil, fmt.Errorf("invalid build properties: %w", err)
}

if !debugProperties.ContainsKey("executable") || debugProperties.Get("executable") == "" {
return nil, &cmderrors.FailedDebugError{Message: i18n.Tr("Debugging not supported for board %s", req.GetFqbn())}
}
Expand Down
31 changes: 21 additions & 10 deletions commands/service_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func (s *arduinoCoreServerImpl) Upload(req *rpc.UploadRequest, stream rpc.Arduin
errStream,
req.GetDryRun(),
req.GetUserFields(),
req.GetUploadProperties(),
)
if err != nil {
return err
Expand Down Expand Up @@ -246,16 +247,18 @@ func (s *arduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgra
return &cmderrors.MissingProgrammerError{}
}
return s.Upload(&rpc.UploadRequest{
Instance: req.GetInstance(),
SketchPath: req.GetSketchPath(),
ImportFile: req.GetImportFile(),
ImportDir: req.GetImportDir(),
Fqbn: req.GetFqbn(),
Port: req.GetPort(),
Programmer: req.GetProgrammer(),
Verbose: req.GetVerbose(),
Verify: req.GetVerify(),
UserFields: req.GetUserFields(),
Instance: req.GetInstance(),
SketchPath: req.GetSketchPath(),
ImportFile: req.GetImportFile(),
ImportDir: req.GetImportDir(),
Fqbn: req.GetFqbn(),
Port: req.GetPort(),
Programmer: req.GetProgrammer(),
Verbose: req.GetVerbose(),
Verify: req.GetVerify(),
UserFields: req.GetUserFields(),
DryRun: req.GetDryRun(),
UploadProperties: req.GetUploadProperties(),
}, streamAdapter)
}

Expand All @@ -266,6 +269,7 @@ func runProgramAction(ctx context.Context, pme *packagemanager.Explorer,
verbose, verify, burnBootloader bool,
outStream, errStream io.Writer,
dryRun bool, userFields map[string]string,
requestUploadProperties []string,
) (*rpc.Port, error) {
port := rpc.DiscoveryPortFromRPCPort(userPort)
if port == nil || (port.Address == "" && port.Protocol == "") {
Expand Down Expand Up @@ -377,6 +381,13 @@ func runProgramAction(ctx context.Context, pme *packagemanager.Explorer,
uploadProperties.Merge(programmer.Properties)
}

// Add user provided custom upload properties
if p, err := properties.LoadFromSlice(requestUploadProperties); err == nil {
uploadProperties.Merge(p)
} else {
return nil, fmt.Errorf("invalid build properties: %w", err)
}

// Certain tools require the user to provide custom fields at run time,
// if they've been provided set them
// For more info:
Expand Down
1 change: 1 addition & 0 deletions commands/service_upload_burnbootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (s *arduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderRequest, s
errStream,
req.GetDryRun(),
map[string]string{}, // User fields
req.GetUploadProperties(),
); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions commands/service_upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func TestUploadPropertiesComposition(t *testing.T) {
errStream,
false,
map[string]string{},
nil,
)
verboseVerifyOutput := "verbose verify"
if !verboseVerify {
Expand Down
31 changes: 17 additions & 14 deletions internal/cli/burnbootloader/burnbootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import (
)

var (
fqbn arguments.Fqbn
port arguments.Port
verbose bool
verify bool
programmer arguments.Programmer
dryRun bool
tr = i18n.Tr
fqbn arguments.Fqbn
port arguments.Port
verbose bool
verify bool
programmer arguments.Programmer
dryRun bool
uploadProperties []string
)

// NewCommand created a new `burn-bootloader` command
Expand All @@ -57,6 +57,8 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
fqbn.AddToCommand(burnBootloaderCommand, srv)
port.AddToCommand(burnBootloaderCommand, srv)
programmer.AddToCommand(burnBootloaderCommand, srv)
burnBootloaderCommand.Flags().StringArrayVar(&uploadProperties, "upload-property", []string{},
i18n.Tr("Override an upload property with a custom value. Can be used multiple times for multiple properties."))
burnBootloaderCommand.Flags().BoolVarP(&verify, "verify", "t", false, i18n.Tr("Verify uploaded binary after the upload."))
burnBootloaderCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, i18n.Tr("Turns on verbose mode."))
burnBootloaderCommand.Flags().BoolVar(&dryRun, "dry-run", false, i18n.Tr("Do not perform the actual upload, just log out actions"))
Expand All @@ -79,13 +81,14 @@ func runBootloaderCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer)
stdOut, stdErr, res := feedback.OutputStreams()
stream := commands.BurnBootloaderToServerStreams(ctx, stdOut, stdErr)
if err := srv.BurnBootloader(&rpc.BurnBootloaderRequest{
Instance: instance,
Fqbn: fqbn.String(),
Port: discoveryPort,
Verbose: verbose,
Verify: verify,
Programmer: programmer.String(ctx, instance, srv, fqbn.String()),
DryRun: dryRun,
Instance: instance,
Fqbn: fqbn.String(),
Port: discoveryPort,
Verbose: verbose,
Verify: verify,
Programmer: programmer.String(ctx, instance, srv, fqbn.String()),
UploadProperties: uploadProperties,
DryRun: dryRun,
}, stream); err != nil {
errcode := feedback.ErrGeneric
if errors.Is(err, &cmderrors.ProgrammerRequiredForUploadError{}) {
Expand Down
37 changes: 21 additions & 16 deletions internal/cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ import (
// NewCommand created a new `upload` command
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
var (
fqbnArg arguments.Fqbn
portArgs arguments.Port
profileArg arguments.Profile
interpreter string
importDir string
printInfo bool
programmer arguments.Programmer
fqbnArg arguments.Fqbn
portArgs arguments.Port
profileArg arguments.Profile
interpreter string
importDir string
printInfo bool
programmer arguments.Programmer
debugProperties []string
)

debugCommand := &cobra.Command{
Expand All @@ -54,7 +55,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runDebugCommand(cmd.Context(), srv, args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg)
runDebugCommand(cmd.Context(), srv, args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg, debugProperties)
},
}

Expand All @@ -66,12 +67,15 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", i18n.Tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", i18n.Tr("Directory containing binaries for debug."))
debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, i18n.Tr("Show metadata about the debug session instead of starting the debugger."))
debugCommand.Flags().StringArrayVar(&debugProperties, "debug-property", []string{},
i18n.Tr("Override an debug property with a custom value. Can be used multiple times for multiple properties."))

return debugCommand
}

func runDebugCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, portArgs *arguments.Port, fqbnArg *arguments.Fqbn,
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool, profileArg *arguments.Profile) {
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool, profileArg *arguments.Profile,
debugProperties []string) {
logrus.Info("Executing `arduino-cli debug`")

path := ""
Expand Down Expand Up @@ -111,13 +115,14 @@ func runDebugCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args
}

debugConfigRequested := &rpc.GetDebugConfigRequest{
Instance: inst,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: port,
Interpreter: interpreter,
ImportDir: importDir,
Programmer: prog,
Instance: inst,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: port,
Interpreter: interpreter,
ImportDir: importDir,
Programmer: prog,
DebugProperties: debugProperties,
}

if printInfo {
Expand Down
28 changes: 17 additions & 11 deletions internal/cli/debug/debug_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,32 @@ import (

func newDebugCheckCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
var (
fqbnArg arguments.Fqbn
portArgs arguments.Port
interpreter string
programmer arguments.Programmer
fqbnArg arguments.Fqbn
portArgs arguments.Port
interpreter string
programmer arguments.Programmer
debugProperties []string
)
debugCheckCommand := &cobra.Command{
Use: "check",
Short: i18n.Tr("Check if the given board/programmer combination supports debugging."),
Example: " " + os.Args[0] + " debug check -b arduino:samd:mkr1000 -P atmel_ice",
Run: func(cmd *cobra.Command, args []string) {
runDebugCheckCommand(cmd.Context(), srv, &portArgs, &fqbnArg, interpreter, &programmer)
runDebugCheckCommand(cmd.Context(), srv, &portArgs, &fqbnArg, interpreter, &programmer, debugProperties)
},
}
fqbnArg.AddToCommand(debugCheckCommand, srv)
portArgs.AddToCommand(debugCheckCommand, srv)
programmer.AddToCommand(debugCheckCommand, srv)
debugCheckCommand.Flags().StringVar(&interpreter, "interpreter", "console", i18n.Tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
debugCheckCommand.Flags().StringArrayVar(&debugProperties, "debug-property", []string{},
i18n.Tr("Override an debug property with a custom value. Can be used multiple times for multiple properties."))
return debugCheckCommand
}

func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, portArgs *arguments.Port, fqbnArg *arguments.Fqbn, interpreter string, programmerArg *arguments.Programmer) {
func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, portArgs *arguments.Port,
fqbnArg *arguments.Fqbn, interpreter string, programmerArg *arguments.Programmer, debugProperties []string,
) {
instance := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli debug`")

Expand All @@ -61,11 +66,12 @@ func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer,
}
fqbn := fqbnArg.String()
resp, err := srv.IsDebugSupported(ctx, &rpc.IsDebugSupportedRequest{
Instance: instance,
Fqbn: fqbn,
Port: port,
Interpreter: interpreter,
Programmer: programmerArg.String(ctx, instance, srv, fqbn),
Instance: instance,
Fqbn: fqbn,
Port: port,
Interpreter: interpreter,
Programmer: programmerArg.String(ctx, instance, srv, fqbn),
DebugProperties: debugProperties,
})
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
Expand Down
45 changes: 24 additions & 21 deletions internal/cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ import (
)

var (
fqbnArg arguments.Fqbn
portArgs arguments.Port
profileArg arguments.Profile
verbose bool
verify bool
importDir string
importFile string
programmer arguments.Programmer
dryRun bool
tr = i18n.Tr
fqbnArg arguments.Fqbn
portArgs arguments.Port
profileArg arguments.Profile
verbose bool
verify bool
importDir string
importFile string
programmer arguments.Programmer
dryRun bool
uploadProperties []string
)

// NewCommand created a new `upload` command
Expand All @@ -72,6 +72,8 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
profileArg.AddToCommand(uploadCommand, srv)
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", i18n.Tr("Directory containing binaries to upload."))
uploadCommand.Flags().StringVarP(&importFile, "input-file", "i", "", i18n.Tr("Binary file to upload."))
uploadCommand.Flags().StringArrayVar(&uploadProperties, "upload-property", []string{},
i18n.Tr("Override an upload property with a custom value. Can be used multiple times for multiple properties."))
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, i18n.Tr("Verify uploaded binary after the upload."))
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, i18n.Tr("Optional, turns on verbose mode."))
programmer.AddToCommand(uploadCommand, srv)
Expand Down Expand Up @@ -185,17 +187,18 @@ func runUploadCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, arg

stdOut, stdErr, stdIOResult := feedback.OutputStreams()
req := &rpc.UploadRequest{
Instance: inst,
Fqbn: fqbn,
SketchPath: path,
Port: port,
Verbose: verbose,
Verify: verify,
ImportFile: importFile,
ImportDir: importDir,
Programmer: prog,
DryRun: dryRun,
UserFields: fields,
Instance: inst,
Fqbn: fqbn,
SketchPath: path,
Port: port,
Verbose: verbose,
Verify: verify,
ImportFile: importFile,
ImportDir: importDir,
Programmer: prog,
DryRun: dryRun,
UserFields: fields,
UploadProperties: uploadProperties,
}
stream, streamResp := commands.UploadToServerStreams(ctx, stdOut, stdErr)
if err := srv.Upload(req, stream); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion rpc/cc/arduino/cli/commands/v1/compile.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/cc/arduino/cli/commands/v1/compile.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ message CompileRequest {
// a directory will be created in the operating system's default temporary
// path.
string build_path = 7;
// List of custom build properties separated by commas.
// List of custom build properties.
repeated string build_properties = 8;
// Used to tell gcc which warning level to use. The level names are: "none",
// "default", "more" and "all".
Expand Down
Loading
Loading