Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4a5585e

Browse files
Add programmer field to sketch profile and --profile flag to debug command (#2505)
* Add programmer field to rpc.SketchProfile * Add programmer to the sketch profile * Retrieve programmer's information from the profile if the flag is not used * Add profile flag to debug command * Add default_programmer field to sketch project * Add default_programmer to rpc.Sketch * Add methods to set and retrieve default_programmer from a sketch * Modify SetSketchDefaults function to set a programmer if specified * Modify board attach command to set a default programmer * Use default programmer if no other value is specified * Update docs * Update TestBoardAttach to test that a programmer is correctly written to sketch.yaml * Add TestDebugProfile to integration tests
1 parent a617a40 commit 4a5585e

File tree

18 files changed

+618
-421
lines changed

18 files changed

+618
-421
lines changed

‎commands/sketch/set_defaults.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func SetSketchDefaults(ctx context.Context, req *rpc.SetSketchDefaultsRequest) (
3535
oldAddress, oldProtocol := sk.GetDefaultPortAddressAndProtocol()
3636
res := &rpc.SetSketchDefaultsResponse{
3737
DefaultFqbn: sk.GetDefaultFQBN(),
38+
DefaultProgrammer: sk.GetDefaultProgrammer(),
3839
DefaultPortAddress: oldAddress,
3940
DefaultPortProtocol: oldProtocol,
4041
}
@@ -45,6 +46,12 @@ func SetSketchDefaults(ctx context.Context, req *rpc.SetSketchDefaultsRequest) (
4546
}
4647
res.DefaultFqbn = fqbn
4748
}
49+
if programmer := req.GetDefaultProgrammer(); programmer != "" {
50+
if err := sk.SetDefaultProgrammer(programmer); err != nil {
51+
return nil, &cmderrors.CantUpdateSketchError{Cause: err}
52+
}
53+
res.DefaultProgrammer = programmer
54+
}
4855
if newAddress, newProtocol := req.GetDefaultPortAddress(), req.GetDefaultPortProtocol(); newAddress != "" {
4956
if err := sk.SetDefaultPort(newAddress, newProtocol); err != nil {
5057
return nil, &cmderrors.CantUpdateSketchError{Cause: err}

‎commands/upload/upload.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,22 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
146146
fqbn = pme.GetProfile().FQBN
147147
}
148148

149+
programmer := req.GetProgrammer()
150+
if programmer == "" && pme.GetProfile() != nil {
151+
programmer = pme.GetProfile().Programmer
152+
}
153+
if programmer == "" {
154+
programmer = sk.GetDefaultProgrammer()
155+
}
156+
149157
updatedPort, err := runProgramAction(
150158
pme,
151159
sk,
152160
req.GetImportFile(),
153161
req.GetImportDir(),
154162
fqbn,
155163
req.GetPort(),
156-
req.GetProgrammer(),
164+
programmer,
157165
req.GetVerbose(),
158166
req.GetVerify(),
159167
false, // burnBootloader

‎docs/sketch-project-file.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ multiple profiles.
1010
Each profile will define:
1111

1212
- The board FQBN
13+
- The programmer to use
1314
- The target core platform name and version (with the 3rd party platform index URL if needed)
1415
- A possible core platform name and version, that is a dependency of the target core platform (with the 3rd party
1516
platform index URL if needed)
@@ -22,6 +23,7 @@ profiles:
2223
<PROFILE_NAME>:
2324
notes: <USER_NOTES>
2425
fqbn: <FQBN>
26+
programmer: <PROGRAMMER>
2527
platforms:
2628
- platform: <PLATFORM> (<PLATFORM_VERSION>)
2729
platform_index_url: <3RD_PARTY_PLATFORM_URL>
@@ -50,6 +52,7 @@ otherwise below). The available fields are:
5052
- `libraries:` is a section where the required libraries to build the project are defined. This section is optional.
5153
- `<LIB_VERSION>` is the version required for the library, for example, `1.0.0`.
5254
- `<USER_NOTES>` is a free text string available to the developer to add comments. This field is optional.
55+
- `<PROGRAMMER>` is the programmer that will be used. This field is optional.
5356

5457
A complete example of a sketch project file may be the following:
5558

@@ -134,19 +137,22 @@ The sketch project file may be used to set the default value for some command li
134137
particular:
135138

136139
- The `default_fqbn` key sets the default value for the `--fqbn` flag
140+
- The `default_programmer` key sets the default value for the `--programmer` flag
137141
- The `default_port` key sets the default value for the `--port` flag
138142
- The `default_protocol` key sets the default value for the `--protocol` flag
139143
- The `default_profile` key sets the default value for the `--profile` flag
140144

141145
For example:
142146

143147
```
144-
default_fqbn: arduino:avr:uno
148+
default_fqbn: arduino:samd:mkr1000
149+
default_programmer: atmel_ice
145150
default_port: /dev/ttyACM0
146151
default_protocol: serial
147152
default_profile: myprofile
148153
```
149154

150-
With this configuration set, it is not necessary to specify the `--fqbn`, `--port`, `--protocol` or `--profile` flags to
151-
the [`arduino-cli compile`](commands/arduino-cli_compile.md) or [`arduino-cli upload`](commands/arduino-cli_upload.md)
152-
commands when compiling or uploading the sketch.
155+
With this configuration set, it is not necessary to specify the `--fqbn`, `--programmer`, `--port`, `--protocol` or
156+
`--profile` flags to the [`arduino-cli compile`](commands/arduino-cli_compile.md),
157+
[`arduino-cli upload`](commands/arduino-cli_upload.md) or [`arduino-cli debug`](commands/arduino-cli_debug.md) commands
158+
when compiling, uploading or debugging the sketch.

‎internal/arduino/sketch/profiles.go‎

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,22 @@ import (
3232

3333
// projectRaw is a support struct used only to unmarshal the yaml
3434
type projectRaw struct {
35-
ProfilesRaw yaml.Node `yaml:"profiles"`
36-
DefaultProfile string `yaml:"default_profile"`
37-
DefaultFqbn string `yaml:"default_fqbn"`
38-
DefaultPort string `yaml:"default_port,omitempty"`
39-
DefaultProtocol string `yaml:"default_protocol,omitempty"`
35+
ProfilesRaw yaml.Node `yaml:"profiles"`
36+
DefaultProfile string `yaml:"default_profile"`
37+
DefaultFqbn string `yaml:"default_fqbn"`
38+
DefaultPort string `yaml:"default_port,omitempty"`
39+
DefaultProtocol string `yaml:"default_protocol,omitempty"`
40+
DefaultProgrammer string `yaml:"default_programmer,omitempty"`
4041
}
4142

4243
// Project represents the sketch project file
4344
type Project struct {
44-
Profiles []*Profile
45-
DefaultProfile string
46-
DefaultFqbn string
47-
DefaultPort string
48-
DefaultProtocol string
45+
Profiles []*Profile
46+
DefaultProfile string
47+
DefaultFqbn string
48+
DefaultPort string
49+
DefaultProtocol string
50+
DefaultProgrammer string
4951
}
5052

5153
// AsYaml outputs the sketch project file as YAML
@@ -69,6 +71,9 @@ func (p *Project) AsYaml() string {
6971
if p.DefaultProtocol != "" {
7072
res += fmt.Sprintf("default_protocol: %s\n", p.DefaultProtocol)
7173
}
74+
if p.DefaultProgrammer != "" {
75+
res += fmt.Sprintf("default_programmer: %s\n", p.DefaultProgrammer)
76+
}
7277
return res
7378
}
7479

@@ -93,18 +98,20 @@ func (p *projectRaw) getProfiles() ([]*Profile, error) {
9398
// Profile is a sketch profile, it contains a reference to all the resources
9499
// needed to build and upload a sketch
95100
type Profile struct {
96-
Name string
97-
Notes string `yaml:"notes"`
98-
FQBN string `yaml:"fqbn"`
99-
Platforms ProfileRequiredPlatforms `yaml:"platforms"`
100-
Libraries ProfileRequiredLibraries `yaml:"libraries"`
101+
Name string
102+
Notes string `yaml:"notes"`
103+
FQBN string `yaml:"fqbn"`
104+
Programmer string `yaml:"programmer"`
105+
Platforms ProfileRequiredPlatforms `yaml:"platforms"`
106+
Libraries ProfileRequiredLibraries `yaml:"libraries"`
101107
}
102108

103109
// ToRpc converts this Profile to an rpc.SketchProfile
104110
func (p *Profile) ToRpc() *rpc.SketchProfile {
105111
return &rpc.SketchProfile{
106-
Name: p.Name,
107-
Fqbn: p.FQBN,
112+
Name: p.Name,
113+
Fqbn: p.FQBN,
114+
Programmer: p.Programmer,
108115
}
109116
}
110117

@@ -115,6 +122,9 @@ func (p *Profile) AsYaml() string {
115122
res += fmt.Sprintf(" notes: %s\n", p.Notes)
116123
}
117124
res += fmt.Sprintf(" fqbn: %s\n", p.FQBN)
125+
if p.Programmer != "" {
126+
res += fmt.Sprintf(" programmer: %s\n", p.Programmer)
127+
}
118128
res += p.Platforms.AsYaml()
119129
res += p.Libraries.AsYaml()
120130
return res
@@ -275,10 +285,11 @@ func LoadProjectFile(file *paths.Path) (*Project, error) {
275285
return nil, err
276286
}
277287
return &Project{
278-
Profiles: profiles,
279-
DefaultProfile: raw.DefaultProfile,
280-
DefaultFqbn: raw.DefaultFqbn,
281-
DefaultPort: raw.DefaultPort,
282-
DefaultProtocol: raw.DefaultProtocol,
288+
Profiles: profiles,
289+
DefaultProfile: raw.DefaultProfile,
290+
DefaultFqbn: raw.DefaultFqbn,
291+
DefaultPort: raw.DefaultPort,
292+
DefaultProtocol: raw.DefaultProtocol,
293+
DefaultProgrammer: raw.DefaultProgrammer,
283294
}, nil
284295
}

‎internal/arduino/sketch/sketch.go‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ func (s *Sketch) GetDefaultPortAddressAndProtocol() (string, string) {
246246
return s.Project.DefaultPort, s.Project.DefaultProtocol
247247
}
248248

249+
// GetDefaultProgrammer return the default Programmer for the sketch (from the sketch.yaml project file),
250+
// ore the empty string if not set.
251+
func (s *Sketch) GetDefaultProgrammer() string {
252+
return s.Project.DefaultProgrammer
253+
}
254+
249255
// SetDefaultFQBN sets the default FQBN for the sketch and saves it in the sketch.yaml project file.
250256
func (s *Sketch) SetDefaultFQBN(fqbn string) error {
251257
s.Project.DefaultFqbn = fqbn
@@ -263,6 +269,12 @@ func (s *Sketch) SetDefaultPort(address, protocol string) error {
263269
return updateOrAddYamlRootEntry(s.GetProjectPath(), "default_protocol", protocol)
264270
}
265271

272+
// SetDefaultFQBN sets the default programmer for the sketch and saves it in the sketch.yaml project file.
273+
func (s *Sketch) SetDefaultProgrammer(programmer string) error {
274+
s.Project.DefaultProgrammer = programmer
275+
return updateOrAddYamlRootEntry(s.GetProjectPath(), "default_programmer", programmer)
276+
}
277+
266278
// InvalidSketchFolderNameError is returned when the sketch directory doesn't match the sketch name
267279
type InvalidSketchFolderNameError struct {
268280
SketchFolder *paths.Path
@@ -290,15 +302,16 @@ func (s *Sketch) Hash() string {
290302
func (s *Sketch) ToRpc() *rpc.Sketch {
291303
defaultPort, defaultProtocol := s.GetDefaultPortAddressAndProtocol()
292304
res := &rpc.Sketch{
293-
MainFile: s.MainFile.String(),
294-
LocationPath: s.FullPath.String(),
295-
OtherSketchFiles: s.OtherSketchFiles.AsStrings(),
296-
AdditionalFiles: s.AdditionalFiles.AsStrings(),
297-
RootFolderFiles: s.RootFolderFiles.AsStrings(),
298-
DefaultFqbn: s.GetDefaultFQBN(),
299-
DefaultPort: defaultPort,
300-
DefaultProtocol: defaultProtocol,
301-
Profiles: f.Map(s.Project.Profiles, (*Profile).ToRpc),
305+
MainFile: s.MainFile.String(),
306+
LocationPath: s.FullPath.String(),
307+
OtherSketchFiles: s.OtherSketchFiles.AsStrings(),
308+
AdditionalFiles: s.AdditionalFiles.AsStrings(),
309+
RootFolderFiles: s.RootFolderFiles.AsStrings(),
310+
DefaultFqbn: s.GetDefaultFQBN(),
311+
DefaultPort: defaultPort,
312+
DefaultProtocol: defaultProtocol,
313+
DefaultProgrammer: s.GetDefaultProgrammer(),
314+
Profiles: f.Map(s.Project.Profiles, (*Profile).ToRpc),
302315
}
303316
if defaultProfile, err := s.GetProfile(s.Project.DefaultProfile); err == nil {
304317
res.DefaultProfile = defaultProfile.ToRpc()

‎internal/arduino/sketch/testdata/SketchWithProfiles/sketch.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
profiles:
22
nanorp:
33
fqbn: arduino:mbed_nano:nanorp2040connect
4+
programmer: p1
45
platforms:
56
- platform: arduino:mbed_nano (2.1.0)
67
libraries:

‎internal/cli/arguments/programmer.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ func (p *Programmer) String(inst *commands.Instance, fqbn string) string {
5656
}
5757
return details.GetDefaultProgrammerId()
5858
}
59+
60+
// GetProgrammer returns the programmer specified by the user
61+
func (p *Programmer) GetProgrammer() string {
62+
return p.programmer
63+
}

‎internal/cli/board/attach.go‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,39 @@ import (
3030
func initAttachCommand() *cobra.Command {
3131
var port arguments.Port
3232
var fqbn arguments.Fqbn
33+
var programmer arguments.Programmer
3334
attachCommand := &cobra.Command{
34-
Use: fmt.Sprintf("attach [-p <%s>] [-b <%s>] [%s]", tr("port"), tr("FQBN"), tr("sketchPath")),
35+
Use: fmt.Sprintf("attach [-p <%s>] [-b <%s>] [-P <%s>] [%s]", tr("port"), tr("FQBN"), tr("programmer"), tr("sketchPath")),
3536
Short: tr("Attaches a sketch to a board."),
36-
Long: tr("Sets the default values for port and FQBN. If no portor FQBN are specified, the current default portand FQBN are displayed."),
37+
Long: tr("Sets the default values for port and FQBN. If no port, FQBN or programmer are specified, the current default port, FQBN and programmer are displayed."),
3738
Example: " " + os.Args[0] + " board attach -p /dev/ttyACM0\n" +
3839
" " + os.Args[0] + " board attach -p /dev/ttyACM0 HelloWorld\n" +
39-
" " + os.Args[0] + " board attach -b arduino:samd:mkr1000",
40+
" " + os.Args[0] + " board attach -b arduino:samd:mkr1000" +
41+
" " + os.Args[0] + " board attach -P atmel_ice",
4042
Args: cobra.MaximumNArgs(1),
4143
Run: func(cmd *cobra.Command, args []string) {
4244
sketchPath := ""
4345
if len(args) > 0 {
4446
sketchPath = args[0]
4547
}
46-
runAttachCommand(sketchPath, &port, fqbn.String())
48+
runAttachCommand(sketchPath, &port, fqbn.String(), &programmer)
4749
},
4850
}
4951
fqbn.AddToCommand(attachCommand)
5052
port.AddToCommand(attachCommand)
53+
programmer.AddToCommand(attachCommand)
5154

5255
return attachCommand
5356
}
5457

55-
func runAttachCommand(path string, port *arguments.Port, fqbn string) {
58+
func runAttachCommand(path string, port *arguments.Port, fqbn string, programmer*arguments.Programmer) {
5659
sketchPath := arguments.InitSketchPath(path)
5760

5861
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(nil, "", "")
5962
newDefaults, err := sketch.SetSketchDefaults(context.Background(), &rpc.SetSketchDefaultsRequest{
6063
SketchPath: sketchPath.String(),
6164
DefaultFqbn: fqbn,
65+
DefaultProgrammer: programmer.GetProgrammer(),
6266
DefaultPortAddress: portAddress,
6367
DefaultPortProtocol: portProtocol,
6468
})
@@ -67,7 +71,8 @@ func runAttachCommand(path string, port *arguments.Port, fqbn string) {
6771
}
6872

6973
res := &boardAttachResult{
70-
Fqbn: newDefaults.GetDefaultFqbn(),
74+
Fqbn: newDefaults.GetDefaultFqbn(),
75+
Programmer: newDefaults.GetDefaultProgrammer(),
7176
}
7277
if newDefaults.GetDefaultPortAddress() != "" {
7378
res.Port = &boardAttachPortResult{
@@ -92,19 +97,21 @@ func (b *boardAttachPortResult) String() string {
9297
}
9398

9499
type boardAttachResult struct {
95-
Fqbn string `json:"fqbn,omitempty"`
96-
Port *boardAttachPortResult `json:"port,omitempty"`
100+
Fqbn string `json:"fqbn,omitempty"`
101+
Programmer string `json:"programmer,omitempty"`
102+
Port *boardAttachPortResult `json:"port,omitempty"`
97103
}
98104

99105
func (b *boardAttachResult) Data() interface{} {
100106
return b
101107
}
102108

103109
func (b *boardAttachResult) String() string {
104-
if b.Port == nil && b.Fqbn == "" {
105-
return tr("No default portor FQBN set")
110+
if b.Port == nil && b.Fqbn == "" &&b.Programmer==""{
111+
return tr("No default port, FQBN or programmer set")
106112
}
107113
res := fmt.Sprintf("%s: %s\n", tr("Default port set to"), b.Port)
108114
res += fmt.Sprintf("%s: %s\n", tr("Default FQBN set to"), b.Fqbn)
115+
res += fmt.Sprintf("%s: %s\n", tr("Default programmer set to"), b.Programmer)
109116
return res
110117
}

‎internal/cli/compile/compile.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
268268
}
269269
}
270270

271+
prog := profile.GetProgrammer()
272+
if prog == "" || programmer.GetProgrammer() != "" {
273+
prog = programmer.String(inst, fqbn)
274+
}
275+
if prog == "" {
276+
prog = sk.GetDefaultProgrammer()
277+
}
278+
271279
uploadRequest := &rpc.UploadRequest{
272280
Instance: inst,
273281
Fqbn: fqbn,
@@ -276,7 +284,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
276284
Verbose: verbose,
277285
Verify: verify,
278286
ImportDir: buildPath,
279-
Programmer: programmer.String(inst, fqbn),
287+
Programmer: prog,
280288
UserFields: fields,
281289
}
282290

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /