From 1b249c7c71adff2b7417462b1a7cc292488f9f7b Mon Sep 17 00:00:00 2001 From: rsora Date: Thu, 2 Jul 2020 11:18:03 +0200 Subject: [PATCH 01/16] Remove deprecation from importFile param --- cli/upload/upload.go | 3 ++ rpc/commands/board.pb.go | 2 +- rpc/commands/commands.pb.go | 2 +- rpc/commands/common.pb.go | 2 +- rpc/commands/compile.pb.go | 2 +- rpc/commands/core.pb.go | 2 +- rpc/commands/lib.pb.go | 2 +- rpc/commands/upload.pb.go | 103 ++++++++++++++++++------------------ rpc/commands/upload.proto | 4 +- rpc/debug/debug.pb.go | 2 +- rpc/monitor/monitor.pb.go | 2 +- rpc/settings/settings.pb.go | 2 +- 12 files changed, 66 insertions(+), 62 deletions(-) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 1a598dae0a1..83e451e008b 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -36,6 +36,7 @@ var ( verbose bool verify bool importDir string + importFile string programmer string ) @@ -53,6 +54,7 @@ func NewCommand() *cobra.Command { uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno") uploadCommand.Flags().StringVarP(&port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0") uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Directory containing binaries to upload.") + uploadCommand.Flags().StringVarP(&importDir, "input-file", "", "", "Binary file to upload.") 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.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload or 'list' to list supported programmers.") @@ -80,6 +82,7 @@ func run(command *cobra.Command, args []string) { Port: port, Verbose: verbose, Verify: verify, + ImportFile: importFile, ImportDir: importDir, Programmer: programmer, }, os.Stdout, os.Stderr); err != nil { diff --git a/rpc/commands/board.pb.go b/rpc/commands/board.pb.go index a2db846ddda..8e1692836e6 100644 --- a/rpc/commands/board.pb.go +++ b/rpc/commands/board.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: commands/board.proto package commands diff --git a/rpc/commands/commands.pb.go b/rpc/commands/commands.pb.go index 0a0db9ed929..daa6c609523 100644 --- a/rpc/commands/commands.pb.go +++ b/rpc/commands/commands.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: commands/commands.proto package commands diff --git a/rpc/commands/common.pb.go b/rpc/commands/common.pb.go index 6d6629fa077..5cb44f8a351 100644 --- a/rpc/commands/common.pb.go +++ b/rpc/commands/common.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: commands/common.proto package commands diff --git a/rpc/commands/compile.pb.go b/rpc/commands/compile.pb.go index ed4efd99a3e..021c906d0d7 100644 --- a/rpc/commands/compile.pb.go +++ b/rpc/commands/compile.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: commands/compile.proto package commands diff --git a/rpc/commands/core.pb.go b/rpc/commands/core.pb.go index b50430ed524..6302b691249 100644 --- a/rpc/commands/core.pb.go +++ b/rpc/commands/core.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: commands/core.proto package commands diff --git a/rpc/commands/lib.pb.go b/rpc/commands/lib.pb.go index 913963df787..ded72bfc3b1 100644 --- a/rpc/commands/lib.pb.go +++ b/rpc/commands/lib.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: commands/lib.proto package commands diff --git a/rpc/commands/upload.pb.go b/rpc/commands/upload.pb.go index 724a56c620b..dbf3969a664 100644 --- a/rpc/commands/upload.pb.go +++ b/rpc/commands/upload.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: commands/upload.proto package commands @@ -62,8 +62,9 @@ type UploadReq struct { // After upload, verify that the contents of the memory on the board match the // uploaded binary. Verify bool `protobuf:"varint,6,opt,name=verify,proto3" json:"verify,omitempty"` - // Deprecated: Do not use. - ImportFile string `protobuf:"bytes,7,opt,name=import_file,json=importFile,proto3" json:"import_file,omitempty"` // DEPRECATED: Use import_dir instead + // When `import_file` is specified, it overrides the `import_dir` and `sketch_path` + // params. + ImportFile string `protobuf:"bytes,7,opt,name=import_file,json=importFile,proto3" json:"import_file,omitempty"` // Custom path to a directory containing compiled files. When `import_dir` is // not specified, the standard build directory under `sketch_path` is used. ImportDir string `protobuf:"bytes,8,opt,name=import_dir,json=importDir,proto3" json:"import_dir,omitempty"` @@ -144,7 +145,6 @@ func (x *UploadReq) GetVerify() bool { return false } -// Deprecated: Do not use. func (x *UploadReq) GetImportFile() string { if x != nil { return x.ImportFile @@ -483,7 +483,7 @@ var file_commands_upload_proto_rawDesc = []byte{ 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x17, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x1a, 0x15, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, - 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa9, 0x02, 0x0a, 0x09, 0x55, 0x70, 0x6c, 0x6f, + 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa5, 0x02, 0x0a, 0x09, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, @@ -496,54 +496,53 @@ var file_commands_upload_proto_rawDesc = []byte{ 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, - 0x23, 0x0a, 0x0b, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, - 0x46, 0x69, 0x6c, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x64, - 0x69, 0x72, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, - 0x44, 0x69, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, - 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, - 0x6d, 0x65, 0x72, 0x22, 0x4a, 0x0a, 0x0a, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, - 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, - 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x65, 0x72, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, - 0xcc, 0x01, 0x0a, 0x11, 0x42, 0x75, 0x72, 0x6e, 0x42, 0x6f, 0x6f, 0x74, 0x6c, 0x6f, 0x61, 0x64, - 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, + 0x1f, 0x0a, 0x0b, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x46, 0x69, 0x6c, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x08, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x12, + 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x22, + 0x4a, 0x0a, 0x0a, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, + 0x0a, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1d, 0x0a, 0x0a, + 0x65, 0x72, 0x72, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x09, 0x65, 0x72, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, 0xcc, 0x01, 0x0a, 0x11, + 0x42, 0x75, 0x72, 0x6e, 0x42, 0x6f, 0x6f, 0x74, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, + 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x49, 0x6e, + 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x66, 0x71, 0x62, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x62, + 0x6f, 0x73, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, + 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, + 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x22, 0x52, 0x0a, 0x12, 0x42, 0x75, + 0x72, 0x6e, 0x42, 0x6f, 0x6f, 0x74, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x12, 0x1d, 0x0a, 0x0a, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, + 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x09, 0x65, 0x72, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, 0x79, + 0x0a, 0x24, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, + 0x73, 0x41, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x55, 0x70, 0x6c, + 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, + 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, + 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, + 0x64, 0x73, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, + 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x22, 0x6e, 0x0a, 0x25, 0x4c, 0x69, 0x73, + 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x73, 0x41, 0x76, 0x61, 0x69, + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, + 0x73, 0x70, 0x12, 0x45, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, - 0x73, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, - 0x61, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x18, 0x0a, 0x07, - 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, - 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, 0x1e, - 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x22, 0x52, - 0x0a, 0x12, 0x42, 0x75, 0x72, 0x6e, 0x42, 0x6f, 0x6f, 0x74, 0x6c, 0x6f, 0x61, 0x64, 0x65, 0x72, - 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x53, 0x74, 0x72, - 0x65, 0x61, 0x6d, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, - 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x65, 0x72, 0x72, 0x53, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x22, 0x79, 0x0a, 0x24, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, - 0x6d, 0x6d, 0x65, 0x72, 0x73, 0x41, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x6f, - 0x72, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, - 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, - 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, - 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, - 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, - 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x22, 0x6e, 0x0a, - 0x25, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x73, - 0x41, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x55, 0x70, 0x6c, 0x6f, - 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x45, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, - 0x6d, 0x6d, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x63, 0x63, - 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, - 0x52, 0x0b, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x73, 0x42, 0x2d, 0x5a, - 0x2b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, - 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, - 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x2e, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x52, 0x0b, 0x70, 0x72, + 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x73, 0x42, 0x2d, 0x5a, 0x2b, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, + 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/rpc/commands/upload.proto b/rpc/commands/upload.proto index b2477a712e8..0f5e04e196c 100644 --- a/rpc/commands/upload.proto +++ b/rpc/commands/upload.proto @@ -39,7 +39,9 @@ message UploadReq { // After upload, verify that the contents of the memory on the board match the // uploaded binary. bool verify = 6; - string import_file = 7 [deprecated = true]; // DEPRECATED: Use import_dir instead + // When `import_file` is specified, it overrides the `import_dir` and `sketch_path` + // params. + string import_file = 7; // Custom path to a directory containing compiled files. When `import_dir` is // not specified, the standard build directory under `sketch_path` is used. string import_dir = 8; diff --git a/rpc/debug/debug.pb.go b/rpc/debug/debug.pb.go index 78459b85514..baad7cd1832 100644 --- a/rpc/debug/debug.pb.go +++ b/rpc/debug/debug.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: debug/debug.proto package debug diff --git a/rpc/monitor/monitor.pb.go b/rpc/monitor/monitor.pb.go index 9ac0cb7da6b..d3fdcc2942c 100644 --- a/rpc/monitor/monitor.pb.go +++ b/rpc/monitor/monitor.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: monitor/monitor.proto package monitor diff --git a/rpc/settings/settings.pb.go b/rpc/settings/settings.pb.go index a020f54189c..eb5d02fa8b6 100644 --- a/rpc/settings/settings.pb.go +++ b/rpc/settings/settings.pb.go @@ -16,7 +16,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc v3.11.3 // source: settings/settings.proto package settings From 13d0d1b9d7c167391f2cba5280fff3fc8e16a5be Mon Sep 17 00:00:00 2001 From: rsora Date: Thu, 2 Jul 2020 15:07:16 +0200 Subject: [PATCH 02/16] Implement --input-file flag --- cli/upload/upload.go | 2 +- commands/upload/burnbootloader.go | 1 + commands/upload/upload.go | 50 ++++++++++++++++++------------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 83e451e008b..0db6a9afaee 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command { uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno") uploadCommand.Flags().StringVarP(&port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0") uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Directory containing binaries to upload.") - uploadCommand.Flags().StringVarP(&importDir, "input-file", "", "", "Binary file to upload.") + uploadCommand.Flags().StringVarP(&importFile, "input-file", "", "", "Binary file to upload.") 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.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload or 'list' to list supported programmers.") diff --git a/commands/upload/burnbootloader.go b/commands/upload/burnbootloader.go index 212c1f50ff7..31f02df0216 100644 --- a/commands/upload/burnbootloader.go +++ b/commands/upload/burnbootloader.go @@ -37,6 +37,7 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderReq, outStream i err := runProgramAction( pm, nil, // sketch + "", // importFile "", // importDir req.GetFqbn(), req.GetPort(), diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 72fcda080ee..4ed140d1b92 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -56,6 +56,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr err = runProgramAction( pm, sketch, + req.GetImportFile(), req.GetImportDir(), req.GetFqbn(), req.GetPort(), @@ -73,7 +74,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr } func runProgramAction(pm *packagemanager.PackageManager, - sketch *sketches.Sketch, importDir string, fqbnIn string, port string, + sketch *sketches.Sketch, importFile string, importDir string, fqbnIn string, port string, programmerID string, verbose, verify, burnBootloader bool, outStream io.Writer, errStream io.Writer) error { @@ -241,28 +242,37 @@ func runProgramAction(pm *packagemanager.PackageManager, var importPath *paths.Path if !burnBootloader { - if sketch == nil { - return fmt.Errorf(("no sketch specified")) - } - - if importDir != "" { - importPath = paths.New(importDir) + if importFile != "" { + importFilePath := paths.New(importFile) + importFilePath.ToAbs() + importPath = importFilePath.Parent() + uploadProperties.SetPath("build.path", importPath) + uploadProperties.Set("build.project_name", importFilePath.Base()) + feedback.Printf("build.path %s", importPath.String()) + feedback.Printf("build.project_name %s", importFilePath.Base()) } else { - // TODO: Create a function to obtain importPath from sketch - importPath = sketch.FullPath - // Add FQBN (without configs part) to export path - fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1) - importPath = importPath.Join("build").Join(fqbnSuffix) - } + if sketch == nil { + return fmt.Errorf(("no sketch specified")) + } + if importDir != "" { + importPath = paths.New(importDir) + } else { + // TODO: Create a function to obtain importPath from sketch + importPath = sketch.FullPath + // Add FQBN (without configs part) to export path + fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1) + importPath = importPath.Join("build").Join(fqbnSuffix) + } - if !importPath.Exist() { - return fmt.Errorf("compiled sketch not found in %s", importPath) - } - if !importPath.IsDir() { - return fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath) + if !importPath.Exist() { + return fmt.Errorf("compiled sketch not found in %s", importPath) + } + if !importPath.IsDir() { + return fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath) + } + uploadProperties.SetPath("build.path", importPath) + uploadProperties.Set("build.project_name", sketch.Name+".ino") } - uploadProperties.SetPath("build.path", importPath) - uploadProperties.Set("build.project_name", sketch.Name+".ino") } // If not using programmer perform some action required From 032038dbc8ebe22065f9df77f5499115eb573ea0 Mon Sep 17 00:00:00 2001 From: rsora Date: Thu, 2 Jul 2020 16:37:20 +0200 Subject: [PATCH 03/16] Add comment in --input-file splitting step --- commands/upload/upload.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 4ed140d1b92..e46b0dbd030 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -244,12 +244,12 @@ func runProgramAction(pm *packagemanager.PackageManager, if !burnBootloader { if importFile != "" { importFilePath := paths.New(importFile) - importFilePath.ToAbs() importPath = importFilePath.Parent() + // In general, the binary file extension (like .bin or .hex or even .zip) are already written explicitly in + // the core recipes. This why the CLI removes it before setting the build.project_name property. + importFileName := strings.ReplaceAll(importFilePath.Base(), importFilePath.Ext(), "") uploadProperties.SetPath("build.path", importPath) - uploadProperties.Set("build.project_name", importFilePath.Base()) - feedback.Printf("build.path %s", importPath.String()) - feedback.Printf("build.project_name %s", importFilePath.Base()) + uploadProperties.Set("build.project_name", importFileName) } else { if sketch == nil { return fmt.Errorf(("no sketch specified")) From 5cc9a30e34e53b11482d30de024918f715065122 Mon Sep 17 00:00:00 2001 From: rsora Date: Thu, 2 Jul 2020 16:37:41 +0200 Subject: [PATCH 04/16] Add e2e test for --input-x flags --- test/test_upload.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/test_upload.py b/test/test_upload.py index 439bd98d084..6f5b35ce754 100644 --- a/test/test_upload.py +++ b/test/test_upload.py @@ -30,7 +30,8 @@ def test_upload(run_command, data_dir, detected_boards): # Download core assert run_command("core install {}".format(board.core)) # Create a sketch - sketch_path = os.path.join(data_dir, "foo") + sketch_name = "foo" + sketch_path = os.path.join(data_dir, sketch_name) assert run_command("sketch new {}".format(sketch_path)) # Build sketch assert run_command("compile -b {fqbn} {sketch_path}".format(fqbn=board.fqbn, sketch_path=sketch_path)) @@ -44,6 +45,19 @@ def test_upload(run_command, data_dir, detected_boards): ) ) + # Upload using --input-dir + assert run_command( + "upload -b {fqbn} -p {port} --input-dir {sketch_path}/build/{fqbn}".format( + sketch_path=sketch_path, fqbn=board.fqbn, port=board.address, sketch_name=sketch_name + ) + ) + # Upload using --input-file + assert run_command( + "upload -b {fqbn} -p {port} --input-dir {sketch_path}/build/{fqbn}/{sketch_name}.ino.bin".format( + sketch_path=sketch_path, fqbn=board.fqbn, port=board.address, sketch_name=sketch_name + ) + ) + def test_upload_after_attach(run_command, data_dir, detected_boards): # Init the environment explicitly From 0d2278be5f40e3d5e1f86b2e4230431b720fd236 Mon Sep 17 00:00:00 2001 From: rsora Date: Fri, 3 Jul 2020 14:16:13 +0200 Subject: [PATCH 05/16] Refine upload flags testing --- test/test_upload.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/test_upload.py b/test/test_upload.py index 6f5b35ce754..52354092ef5 100644 --- a/test/test_upload.py +++ b/test/test_upload.py @@ -13,6 +13,7 @@ # software without disclosing the source code of your own applications. To purchase # a commercial license, send an email to license@arduino.cc. import os +import time import pytest @@ -45,16 +46,23 @@ def test_upload(run_command, data_dir, detected_boards): ) ) - # Upload using --input-dir + # multiple uploads requires some pauses + time.sleep(2) + # Upload using --input-dir reusing standard sketch "build" folder artifacts assert run_command( - "upload -b {fqbn} -p {port} --input-dir {sketch_path}/build/{fqbn}".format( - sketch_path=sketch_path, fqbn=board.fqbn, port=board.address, sketch_name=sketch_name + "upload -b {fqbn} -p {port} --input-dir {sketch_path}/build/{fqbn_path} {sketch_path}".format( + sketch_path=sketch_path, fqbn=board.fqbn, port=board.address, + fqbn_path=board.fqbn.replace(":", ".") ) ) - # Upload using --input-file + + # multiple uploads requires some pauses + time.sleep(2) + # Upload using --input-file reusing standard sketch "build" folder artifacts assert run_command( - "upload -b {fqbn} -p {port} --input-dir {sketch_path}/build/{fqbn}/{sketch_name}.ino.bin".format( - sketch_path=sketch_path, fqbn=board.fqbn, port=board.address, sketch_name=sketch_name + "upload -b {fqbn} -p {port} --input-file {sketch_path}/build/{fqbn_path}/{sketch_name}.ino.bin".format( + sketch_path=sketch_path, fqbn=board.fqbn, port=board.address, sketch_name=sketch_name, + fqbn_path=board.fqbn.replace(":", ".") ) ) From 1fb9ccc75aaea2c574f3675ddcf604d1c3d7b891 Mon Sep 17 00:00:00 2001 From: rsora Date: Fri, 3 Jul 2020 15:04:58 +0200 Subject: [PATCH 06/16] Add --input-file file existence check --- commands/upload/upload.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index e46b0dbd030..e635266ebd8 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -244,6 +244,9 @@ func runProgramAction(pm *packagemanager.PackageManager, if !burnBootloader { if importFile != "" { importFilePath := paths.New(importFile) + if !importFilePath.Exist() { + return fmt.Errorf("binary file not found in %s", importFilePath) + } importPath = importFilePath.Parent() // In general, the binary file extension (like .bin or .hex or even .zip) are already written explicitly in // the core recipes. This why the CLI removes it before setting the build.project_name property. From bc866920e1296a9e62568121b654e21613189e71 Mon Sep 17 00:00:00 2001 From: rsora Date: Tue, 7 Jul 2020 17:34:15 +0200 Subject: [PATCH 07/16] Use TrimSuffix instead of replace --- commands/upload/upload.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index e635266ebd8..20c357ea93e 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -249,8 +249,9 @@ func runProgramAction(pm *packagemanager.PackageManager, } importPath = importFilePath.Parent() // In general, the binary file extension (like .bin or .hex or even .zip) are already written explicitly in - // the core recipes. This why the CLI removes it before setting the build.project_name property. - importFileName := strings.ReplaceAll(importFilePath.Base(), importFilePath.Ext(), "") + // the core recipes inside platform.txt. This why the CLI removes it before setting the build.project_name + // property. + importFileName := strings.TrimSuffix(importFilePath.Base(), importFilePath.Ext()) uploadProperties.SetPath("build.path", importPath) uploadProperties.Set("build.project_name", importFileName) } else { From 3df5b6bd4e5eb1c9a02823fbe5bfe235164ed41b Mon Sep 17 00:00:00 2001 From: rsora Date: Tue, 7 Jul 2020 18:36:32 +0200 Subject: [PATCH 08/16] Restore -i shorthand flag for --input-file and add CLI checkFlagsConflicts function --- cli/upload/upload.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 0db6a9afaee..3922ba2f4a3 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -48,13 +48,14 @@ func NewCommand() *cobra.Command { Long: "Upload Arduino sketches. This does NOT compile the sketch prior to upload.", Example: " " + os.Args[0] + " upload /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), + PreRun: checkFlagsConflicts, Run: run, } uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno") uploadCommand.Flags().StringVarP(&port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0") uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Directory containing binaries to upload.") - uploadCommand.Flags().StringVarP(&importFile, "input-file", "", "", "Binary file to upload.") + uploadCommand.Flags().StringVarP(&importFile, "input-file", "i", "", "Binary file to upload.") 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.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload or 'list' to list supported programmers.") @@ -62,6 +63,13 @@ func NewCommand() *cobra.Command { return uploadCommand } +func checkFlagsConflicts(command *cobra.Command, args []string) { + if importFile != "" && importDir != "" { + feedback.Errorf("error: --input-file and --input-dir flags cannot be used together") + os.Exit(errorcodes.ErrBadArgument) + } +} + func run(command *cobra.Command, args []string) { instance, err := instance.CreateInstance() if err != nil { From de6c4432fa5cf2da6b057d2be04f4d4b32c6f3f4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 10:26:22 +0200 Subject: [PATCH 09/16] Improved build path and project name auto-detection This should make the upload command compatibile with all the reasonable usages. See #764 See #641 --- commands/upload/testdata/Blonk/Blonk.ino | 0 .../build/arduino.samd.mkr1000/Blonk.ino.bin | 0 .../build/arduino.samd.mkr1000/Blonk.ino.elf | 0 .../build/arduino.samd.mkr1000/Blonk.ino.hex | 0 .../build/arduino.samd.mkr1000/Blonk.ino.map | 0 .../Blonk.ino.with_bootloader.bin | 0 .../Blonk.ino.with_bootloader.hex | 0 .../testdata/build_path_1/sketch.ino.bin | 0 .../testdata/build_path_2/Blink.ino.bin | 0 .../testdata/build_path_2/Blink.ino.elf | 0 .../testdata/build_path_2/Blink.ino.hex | 0 .../testdata/build_path_2/Blink.ino.map | 0 .../Blink.ino.with_bootloader.bin | 0 .../Blink.ino.with_bootloader.hex | 0 .../build_path_3/AnotherSketch.ino.bin | 0 .../testdata/build_path_3/Blink.ino.bin | 0 .../testdata/build_path_3/Blink.ino.elf | 0 .../testdata/build_path_3/Blink.ino.hex | 0 .../testdata/build_path_3/Blink.ino.map | 0 .../Blink.ino.with_bootloader.bin | 0 .../Blink.ino.with_bootloader.hex | 0 commands/upload/upload.go | 154 ++++++++++++++---- commands/upload/upload_test.go | 106 ++++++++++++ 23 files changed, 225 insertions(+), 35 deletions(-) create mode 100644 commands/upload/testdata/Blonk/Blonk.ino create mode 100644 commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.bin create mode 100644 commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.elf create mode 100644 commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.hex create mode 100644 commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.map create mode 100644 commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.with_bootloader.bin create mode 100644 commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.with_bootloader.hex create mode 100644 commands/upload/testdata/build_path_1/sketch.ino.bin create mode 100644 commands/upload/testdata/build_path_2/Blink.ino.bin create mode 100644 commands/upload/testdata/build_path_2/Blink.ino.elf create mode 100644 commands/upload/testdata/build_path_2/Blink.ino.hex create mode 100644 commands/upload/testdata/build_path_2/Blink.ino.map create mode 100644 commands/upload/testdata/build_path_2/Blink.ino.with_bootloader.bin create mode 100644 commands/upload/testdata/build_path_2/Blink.ino.with_bootloader.hex create mode 100644 commands/upload/testdata/build_path_3/AnotherSketch.ino.bin create mode 100644 commands/upload/testdata/build_path_3/Blink.ino.bin create mode 100644 commands/upload/testdata/build_path_3/Blink.ino.elf create mode 100644 commands/upload/testdata/build_path_3/Blink.ino.hex create mode 100644 commands/upload/testdata/build_path_3/Blink.ino.map create mode 100644 commands/upload/testdata/build_path_3/Blink.ino.with_bootloader.bin create mode 100644 commands/upload/testdata/build_path_3/Blink.ino.with_bootloader.hex create mode 100644 commands/upload/upload_test.go diff --git a/commands/upload/testdata/Blonk/Blonk.ino b/commands/upload/testdata/Blonk/Blonk.ino new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.bin b/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.elf b/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.elf new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.hex b/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.hex new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.map b/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.map new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.with_bootloader.bin b/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.with_bootloader.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.with_bootloader.hex b/commands/upload/testdata/Blonk/build/arduino.samd.mkr1000/Blonk.ino.with_bootloader.hex new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_1/sketch.ino.bin b/commands/upload/testdata/build_path_1/sketch.ino.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_2/Blink.ino.bin b/commands/upload/testdata/build_path_2/Blink.ino.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_2/Blink.ino.elf b/commands/upload/testdata/build_path_2/Blink.ino.elf new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_2/Blink.ino.hex b/commands/upload/testdata/build_path_2/Blink.ino.hex new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_2/Blink.ino.map b/commands/upload/testdata/build_path_2/Blink.ino.map new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_2/Blink.ino.with_bootloader.bin b/commands/upload/testdata/build_path_2/Blink.ino.with_bootloader.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_2/Blink.ino.with_bootloader.hex b/commands/upload/testdata/build_path_2/Blink.ino.with_bootloader.hex new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_3/AnotherSketch.ino.bin b/commands/upload/testdata/build_path_3/AnotherSketch.ino.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_3/Blink.ino.bin b/commands/upload/testdata/build_path_3/Blink.ino.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_3/Blink.ino.elf b/commands/upload/testdata/build_path_3/Blink.ino.elf new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_3/Blink.ino.hex b/commands/upload/testdata/build_path_3/Blink.ino.hex new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_3/Blink.ino.map b/commands/upload/testdata/build_path_3/Blink.ino.map new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_3/Blink.ino.with_bootloader.bin b/commands/upload/testdata/build_path_3/Blink.ino.with_bootloader.bin new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/testdata/build_path_3/Blink.ino.with_bootloader.hex b/commands/upload/testdata/build_path_3/Blink.ino.with_bootloader.hex new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 20c357ea93e..a325bbc529b 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "net/url" + "path/filepath" "strings" "time" @@ -32,6 +33,7 @@ import ( rpc "github.com/arduino/arduino-cli/rpc/commands" paths "github.com/arduino/go-paths-helper" properties "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "go.bug.st/serial" ) @@ -240,43 +242,19 @@ func runProgramAction(pm *packagemanager.PackageManager, uploadProperties.Set("program.verify", uploadProperties.Get("program.params.noverify")) } - var importPath *paths.Path if !burnBootloader { - if importFile != "" { - importFilePath := paths.New(importFile) - if !importFilePath.Exist() { - return fmt.Errorf("binary file not found in %s", importFilePath) - } - importPath = importFilePath.Parent() - // In general, the binary file extension (like .bin or .hex or even .zip) are already written explicitly in - // the core recipes inside platform.txt. This why the CLI removes it before setting the build.project_name - // property. - importFileName := strings.TrimSuffix(importFilePath.Base(), importFilePath.Ext()) - uploadProperties.SetPath("build.path", importPath) - uploadProperties.Set("build.project_name", importFileName) - } else { - if sketch == nil { - return fmt.Errorf(("no sketch specified")) - } - if importDir != "" { - importPath = paths.New(importDir) - } else { - // TODO: Create a function to obtain importPath from sketch - importPath = sketch.FullPath - // Add FQBN (without configs part) to export path - fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1) - importPath = importPath.Join("build").Join(fqbnSuffix) - } - - if !importPath.Exist() { - return fmt.Errorf("compiled sketch not found in %s", importPath) - } - if !importPath.IsDir() { - return fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath) - } - uploadProperties.SetPath("build.path", importPath) - uploadProperties.Set("build.project_name", sketch.Name+".ino") + importPath, sketchName, err := determineBuildPathAndSketchName(importFile, importDir, sketch, fqbn) + if err != nil { + return errors.Errorf("retrieving build artifacts: %s", err) + } + if !importPath.Exist() { + return fmt.Errorf("compiled sketch not found in %s", importPath) + } + if !importPath.IsDir() { + return fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath) } + uploadProperties.SetPath("build.path", importPath) + uploadProperties.Set("build.project_name", sketchName) } // If not using programmer perform some action required @@ -463,3 +441,109 @@ func waitForNewSerialPort() (string, error) { return "", nil } + +func determineBuildPathAndSketchName(importFile, importDir string, sketch *sketches.Sketch, fqbn *cores.FQBN) (*paths.Path, string, error) { + // In general, compiling a sketch will produce a set of files that are + // named as the sketch but have different extensions, for example Sketch.ino + // may produce: Sketch.ino.bin; Sketch.ino.hex; Sketch.ino.zip; etc... + // These files are created together in the build directory and anyone of + // them may be required for upload. + + // The upload recipes are already written using the 'build.project_name' property + // concatenated with an explicit extension. To perform the upload we should now + // determine the project name (e.g. 'sketch.ino) and set the 'build.project_name' + // property accordingly, together with the 'build.path' property to point to the + // directory containing the build artifacts. + + // Case 1: importFile flag has been specified + if importFile != "" { + if importDir != "" { + return nil, "", fmt.Errorf("importFile and importDir cannot be used together") + } + + // We have a path like "path/to/my/build/SketchName.ino.bin". We are going to + // ignore the extension and set: + // - "build.path" as "path/to/my/build" + // - "build.project_name" as "SketchName.ino" + + importFilePath := paths.New(importFile) + if !importFilePath.Exist() { + return nil, "", fmt.Errorf("binary file not found in %s", importFilePath) + } + return importFilePath.Parent(), strings.TrimSuffix(importFilePath.Base(), importFilePath.Ext()), nil + } + + if importDir != "" { + // Case 2: importDir flag with a sketch + if sketch != nil { + // In this case we have both the build path and the sketch name given, + // so we just return them as-is + return paths.New(importDir), sketch.Name + ".ino", nil + } + + // Case 3: importDir flag without a sketch + + // In this case we have a build path but the sketch name is not given, we may + // try to determine the sketch name by applying some euristics to the build folder. + // - "build.path" as importDir + // - "build.project_name" after trying to autodetect it from the build folder. + buildPath := paths.New(importDir) + sketchName, err := detectSketchNameFromBuildPath(buildPath) + if err != nil { + return nil, "", errors.Errorf("autodetect build artifact: %s", err) + } + return buildPath, sketchName, nil + } + + // Case 4: nothing given... + if sketch == nil { + return nil, "", fmt.Errorf("no sketch or build directory/file specified") + } + + // Case 5: only sketch specified. In this case we use the default sketch build path + // and the given sketch name. + + // TODO: Create a function to obtain importPath from sketch + // Add FQBN (without configs part) to export path + if fqbn == nil { + return nil, "", fmt.Errorf("missing FQBN") + } + fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1) + return sketch.FullPath.Join("build").Join(fqbnSuffix), sketch.Name + ".ino", nil +} + +func detectSketchNameFromBuildPath(buildPath *paths.Path) (string, error) { + files, err := buildPath.ReadDir() + if err != nil { + return "", err + } + + candidateName := "" + var candidateFile *paths.Path + for _, file := range files { + // Build artifacts are usually names as "Blink.ino.hex" or "Blink.ino.bin". + // Extract the "Blink.ino" part + name := strings.TrimSuffix(file.Base(), file.Ext()) + + // Sometimes we may have particular files like: + // Blink.ino.with_bootloader.bin + if filepath.Ext(name) != ".ino" { + // just ignore those files + continue + } + + if candidateName == "" { + candidateName = name + candidateFile = file + } + + if candidateName != name { + return "", errors.Errorf("multiple build artifacts found: '%s' and '%s'", candidateFile, file) + } + } + + if candidateName == "" { + return "", errors.New("could not find a valid build artifact") + } + return candidateName, nil +} diff --git a/commands/upload/upload_test.go b/commands/upload/upload_test.go new file mode 100644 index 00000000000..29f0d469147 --- /dev/null +++ b/commands/upload/upload_test.go @@ -0,0 +1,106 @@ +// This file is part of arduino-cli. +// +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package upload + +import ( + "fmt" + "testing" + + "github.com/arduino/arduino-cli/arduino/cores" + "github.com/arduino/arduino-cli/arduino/sketches" + paths "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" +) + +func TestDetectSketchNameFromBuildPath(t *testing.T) { + sk1, err1 := detectSketchNameFromBuildPath(paths.New("testdata/build_path_1")) + require.NoError(t, err1) + require.Equal(t, "sketch.ino", sk1) + + sk2, err2 := detectSketchNameFromBuildPath(paths.New("testdata/build_path_2")) + require.NoError(t, err2) + require.Equal(t, "Blink.ino", sk2) + + sk3, err3 := detectSketchNameFromBuildPath(paths.New("testdata/build_path_3")) + require.Error(t, err3) + require.Equal(t, "", sk3) +} + +func TestDetermineBuildPathAndSketchName(t *testing.T) { + type test struct { + importFile string + importDir string + sketch *sketches.Sketch + fqbn *cores.FQBN + resBuildPath string + resSketchName string + hasError bool + } + + blonk, err := sketches.NewSketchFromPath(paths.New("testdata/Blonk")) + require.NoError(t, err) + + fqbn, err := cores.ParseFQBN("arduino:samd:mkr1000") + require.NoError(t, err) + + tests := []test{ + // 00: error: no data passed in + {"", "", nil, nil, "", "", true}, + // 01: use importFile to detect build.path and project_name + {"testdata/build_path_2/Blink.ino.hex", "", nil, nil, "testdata/build_path_2", "Blink.ino", false}, + // 02: use importPath as build.path and project_name + {"", "testdata/build_path_2", nil, nil, "testdata/build_path_2", "Blink.ino", false}, + // 03: error: used both importPath and importFile + {"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", nil, nil, "", "", true}, + // 04: error: only sketch without FQBN + {"", "", blonk, nil, "", "", true}, + // 05: use importFile to detect build.path and project_name, sketch is ignored. + {"testdata/build_path_2/Blink.ino.hex", "", blonk, nil, "testdata/build_path_2", "Blink.ino", false}, + // 06: use importPath as build.path and Blonk as project name (forced by the sketch) + {"", "testdata/build_path_2", blonk, nil, "testdata/build_path_2", "Blonk.ino", false}, + // 07: error: used both importPath and importFile + {"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, nil, "", "", true}, + + // 08: error: no data passed in + {"", "", nil, fqbn, "", "", true}, + // 09: use importFile to detect build.path and project_name, fqbn ignored + {"testdata/build_path_2/Blink.ino.hex", "", nil, fqbn, "testdata/build_path_2", "Blink.ino", false}, + // 10: use importPath as build.path and project_name, fqbn ignored + {"", "testdata/build_path_2", nil, fqbn, "testdata/build_path_2", "Blink.ino", false}, + // 11: error: used both importPath and importFile + {"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", nil, fqbn, "", "", true}, + // 12: use sketch to determine project name and sketch+fqbn to determine build path + {"", "", blonk, fqbn, "testdata/Blonk/build/arduino.samd.mkr1000", "Blonk.ino", false}, + // 13: use importFile to detect build.path and project_name, sketch+fqbn is ignored. + {"testdata/build_path_2/Blink.ino.hex", "", blonk, fqbn, "testdata/build_path_2", "Blink.ino", false}, + // 14: use importPath as build.path and Blonk as project name (forced by the sketch), fqbn ignored + {"", "testdata/build_path_2", blonk, fqbn, "testdata/build_path_2", "Blonk.ino", false}, + // 15: error: used both importPath and importFile + {"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, fqbn, "", "", true}, + } + for i, test := range tests { + t.Run(fmt.Sprintf("SubTest%02d", i), func(t *testing.T) { + buildPath, sketchName, err := determineBuildPathAndSketchName(test.importFile, test.importDir, test.sketch, test.fqbn) + if test.hasError { + require.Error(t, err) + } else { + require.NoError(t, err) + } + require.Equal(t, test.resBuildPath, fmt.Sprint(buildPath)) + require.Equal(t, test.resSketchName, sketchName) + }) + } +} From 9afd7ee595b6c7d2396515b81f2e69b5b13dd5b1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 11:24:31 +0200 Subject: [PATCH 10/16] Made UploadTest more resilient --- commands/upload/upload_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commands/upload/upload_test.go b/commands/upload/upload_test.go index 29f0d469147..212b6996dd4 100644 --- a/commands/upload/upload_test.go +++ b/commands/upload/upload_test.go @@ -99,7 +99,14 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) { } else { require.NoError(t, err) } - require.Equal(t, test.resBuildPath, fmt.Sprint(buildPath)) + if test.resBuildPath == "" { + require.Nil(t, buildPath) + } else { + resBuildPath := paths.New(test.resBuildPath) + require.NoError(t, resBuildPath.ToAbs()) + require.NoError(t, buildPath.ToAbs()) + require.Equal(t, resBuildPath.String(), buildPath.String()) + } require.Equal(t, test.resSketchName, sketchName) }) } From c48c1cc1f89db6f84cacac66eab0e646928d7d85 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 11:28:26 +0200 Subject: [PATCH 11/16] upload: sketch is ignored if input-dir or input-file is specified There is no point in overriding the sketch name if the user explicitly give it via command line. --- arduino/sketches/sketches.go | 9 +++++++++ commands/upload/upload.go | 20 +++++--------------- commands/upload/upload_test.go | 8 ++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/arduino/sketches/sketches.go b/arduino/sketches/sketches.go index 10627920d80..601853f1590 100644 --- a/arduino/sketches/sketches.go +++ b/arduino/sketches/sketches.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/arduino/go-paths-helper" + "github.com/pkg/errors" ) // Sketch is a sketch for Arduino @@ -43,9 +44,17 @@ type BoardMetadata struct { // NewSketchFromPath loads a sketch from the specified path func NewSketchFromPath(path *paths.Path) (*Sketch, error) { + path, err := path.Abs() + if err != nil { + return nil, errors.Errorf("getting sketch path: %s", err) + } if !path.IsDir() { path = path.Parent() } + sketchFile := path.Join(path.Base() + ".ino") + if !sketchFile.Exist() { + return nil, errors.Errorf("no valid sketch found in %s: missing %s", path, sketchFile.Base()) + } sketch := &Sketch{ FullPath: path, Name: path.Base(), diff --git a/commands/upload/upload.go b/commands/upload/upload.go index a325bbc529b..d13cffb3135 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -44,12 +44,9 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr // TODO: make a generic function to extract sketch from request // and remove duplication in commands/compile.go - if req.GetSketchPath() == "" { - return nil, fmt.Errorf("missing sketchPath") - } sketchPath := paths.New(req.GetSketchPath()) sketch, err := sketches.NewSketchFromPath(sketchPath) - if err != nil { + if err != nil && req.GetImportDir() == "" && req.GetImportFile() == "" { return nil, fmt.Errorf("opening sketch: %s", err) } @@ -474,16 +471,9 @@ func determineBuildPathAndSketchName(importFile, importDir string, sketch *sketc } if importDir != "" { - // Case 2: importDir flag with a sketch - if sketch != nil { - // In this case we have both the build path and the sketch name given, - // so we just return them as-is - return paths.New(importDir), sketch.Name + ".ino", nil - } - - // Case 3: importDir flag without a sketch + // Case 2: importDir flag has been specified - // In this case we have a build path but the sketch name is not given, we may + // In this case we have a build path but ignore the sketch name, we'll // try to determine the sketch name by applying some euristics to the build folder. // - "build.path" as importDir // - "build.project_name" after trying to autodetect it from the build folder. @@ -495,12 +485,12 @@ func determineBuildPathAndSketchName(importFile, importDir string, sketch *sketc return buildPath, sketchName, nil } - // Case 4: nothing given... + // Case 3: nothing given... if sketch == nil { return nil, "", fmt.Errorf("no sketch or build directory/file specified") } - // Case 5: only sketch specified. In this case we use the default sketch build path + // Case 4: only sketch specified. In this case we use the default sketch build path // and the given sketch name. // TODO: Create a function to obtain importPath from sketch diff --git a/commands/upload/upload_test.go b/commands/upload/upload_test.go index 212b6996dd4..989453f524d 100644 --- a/commands/upload/upload_test.go +++ b/commands/upload/upload_test.go @@ -69,8 +69,8 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) { {"", "", blonk, nil, "", "", true}, // 05: use importFile to detect build.path and project_name, sketch is ignored. {"testdata/build_path_2/Blink.ino.hex", "", blonk, nil, "testdata/build_path_2", "Blink.ino", false}, - // 06: use importPath as build.path and Blonk as project name (forced by the sketch) - {"", "testdata/build_path_2", blonk, nil, "testdata/build_path_2", "Blonk.ino", false}, + // 06: use importPath as build.path and Blink as project name, ignore the sketch Blonk + {"", "testdata/build_path_2", blonk, nil, "testdata/build_path_2", "Blink.ino", false}, // 07: error: used both importPath and importFile {"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, nil, "", "", true}, @@ -86,8 +86,8 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) { {"", "", blonk, fqbn, "testdata/Blonk/build/arduino.samd.mkr1000", "Blonk.ino", false}, // 13: use importFile to detect build.path and project_name, sketch+fqbn is ignored. {"testdata/build_path_2/Blink.ino.hex", "", blonk, fqbn, "testdata/build_path_2", "Blink.ino", false}, - // 14: use importPath as build.path and Blonk as project name (forced by the sketch), fqbn ignored - {"", "testdata/build_path_2", blonk, fqbn, "testdata/build_path_2", "Blonk.ino", false}, + // 14: use importPath as build.path and Blink as project name, ignore the sketch Blonk, ignore fqbn + {"", "testdata/build_path_2", blonk, fqbn, "testdata/build_path_2", "Blink.ino", false}, // 15: error: used both importPath and importFile {"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, fqbn, "", "", true}, } From c609e125cf0263854978d42e05a0fae2cbf9b371 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 11:59:29 +0200 Subject: [PATCH 12/16] Update go-paths-helper to version 1.3.2 fixes EquivalentTo when used with abs paths --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 92a3cc2d8f4..dcc2c64ab90 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( bou.ke/monkey v1.0.1 github.com/GeertJohan/go.rice v1.0.0 github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c - github.com/arduino/go-paths-helper v1.3.1 + github.com/arduino/go-paths-helper v1.3.2 github.com/arduino/go-properties-orderedmap v1.3.0 github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b diff --git a/go.sum b/go.sum index 46b9fa660b9..cf093eae332 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,8 @@ github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWje github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.2.0 h1:qDW93PR5IZUN/jzO4rCtexiwF8P4OIcOmcSgAYLZfY4= github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= -github.com/arduino/go-paths-helper v1.3.1 h1:Gz+PVt0luQyH4nffDePd8WBs/O5P05jADtJsY8NqvCM= -github.com/arduino/go-paths-helper v1.3.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= +github.com/arduino/go-paths-helper v1.3.2 h1:5U9TSKQODiwSVgTxskC0PNl0l0Vf40GUlp99Zy2SK8w= +github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o= github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4= From bf438650c4415b4938cb7ff6aa7c33358eaf209c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 12:24:24 +0200 Subject: [PATCH 13/16] fix TestGetCommandLine --- commands/debug/debug_test.go | 17 +++++++++-------- commands/debug/testdata/hello/hello.ino | 0 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 commands/debug/testdata/hello/hello.ino diff --git a/commands/debug/debug_test.go b/commands/debug/debug_test.go index 0e352f07a87..8d0fd57ad7f 100644 --- a/commands/debug/debug_test.go +++ b/commands/debug/debug_test.go @@ -26,14 +26,16 @@ import ( dbg "github.com/arduino/arduino-cli/rpc/debug" "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -var customHardware = paths.New("testdata", "custom_hardware") -var dataDir = paths.New("testdata", "data_dir", "packages") -var sketch = "hello" -var sketchPath = paths.New("testdata", sketch) - func TestGetCommandLine(t *testing.T) { + customHardware := paths.New("testdata", "custom_hardware") + dataDir := paths.New("testdata", "data_dir", "packages") + sketch := "hello" + sketchPath := paths.New("testdata", sketch) + require.NoError(t, sketchPath.ToAbs()) + pm := packagemanager.NewPackageManager(nil, nil, nil, nil) pm.LoadHardwareFromDirectory(customHardware) pm.LoadHardwareFromDirectory(dataDir) @@ -59,9 +61,9 @@ func TestGetCommandLine(t *testing.T) { fmt.Sprintf(" -c \"gdb_port pipe\" -c \"telnet_port 0\" -c init -c halt %s/build/arduino-test.samd.arduino_zero_edbg/hello.ino.elf", sketchPath) command, err := getCommandLine(req, pm) - assert.Nil(t, err) + require.Nil(t, err) commandToTest := strings.Join(command[:], " ") - assert.Equal(t, filepath.FromSlash(goldCommand), filepath.FromSlash(commandToTest)) + require.Equal(t, filepath.FromSlash(goldCommand), filepath.FromSlash(commandToTest)) // Other samd boards such as mkr1000 can be debugged using an external tool such as Atmel ICE connected to // the board debug port @@ -83,5 +85,4 @@ func TestGetCommandLine(t *testing.T) { assert.Nil(t, err) commandToTest2 := strings.Join(command2[:], " ") assert.Equal(t, filepath.FromSlash(goldCommand2), filepath.FromSlash(commandToTest2)) - } diff --git a/commands/debug/testdata/hello/hello.ino b/commands/debug/testdata/hello/hello.ino new file mode 100644 index 00000000000..e69de29bb2d From 0c30b9e8b7c529a5651cf7920d2f0649949f24ce Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 12:57:52 +0200 Subject: [PATCH 14/16] 100% coverage on detectSketchNameFromBuildPath function --- .../upload/testdata/build_path_4/some_other_files.txt | 0 commands/upload/upload_test.go | 8 ++++++++ 2 files changed, 8 insertions(+) create mode 100644 commands/upload/testdata/build_path_4/some_other_files.txt diff --git a/commands/upload/testdata/build_path_4/some_other_files.txt b/commands/upload/testdata/build_path_4/some_other_files.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/commands/upload/upload_test.go b/commands/upload/upload_test.go index 989453f524d..54f34155e7e 100644 --- a/commands/upload/upload_test.go +++ b/commands/upload/upload_test.go @@ -37,6 +37,14 @@ func TestDetectSketchNameFromBuildPath(t *testing.T) { sk3, err3 := detectSketchNameFromBuildPath(paths.New("testdata/build_path_3")) require.Error(t, err3) require.Equal(t, "", sk3) + + sk4, err4 := detectSketchNameFromBuildPath(paths.New("testdata/build_path_4")) + require.Error(t, err4) + require.Equal(t, "", sk4) + + sk5, err5 := detectSketchNameFromBuildPath(paths.New("testdata/build_path_invalid")) + require.Error(t, err5) + require.Equal(t, "", sk5) } func TestDetermineBuildPathAndSketchName(t *testing.T) { From f2c4839dd710846819cc9ca827546dc9606d077b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 13:22:26 +0200 Subject: [PATCH 15/16] Do not git-ignore all *.bin but just inside the client_example folder --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6e7b8d65eb0..2b918c4df3f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,8 @@ venv # gRPC client example folder /client_example/client_example -*.bin -*.elf +/client_example/**/*.bin +/client_example/**/*.elf # Misc. .DS_Store From 4181de47738f3aeff6be365ec01eb76944fd7338 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Sep 2020 16:59:13 +0200 Subject: [PATCH 16/16] slightly simplified function signature (cosmetic) --- commands/upload/upload.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index d13cffb3135..1e1dc9701e6 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -73,10 +73,11 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr } func runProgramAction(pm *packagemanager.PackageManager, - sketch *sketches.Sketch, importFile string, importDir string, fqbnIn string, port string, + sketch *sketches.Sketch, + importFile, importDir, fqbnIn, port string, programmerID string, verbose, verify, burnBootloader bool, - outStream io.Writer, errStream io.Writer) error { + outStream, errStream io.Writer) error { if burnBootloader && programmerID == "" { return fmt.Errorf("no programmer specified for burning bootloader")