Skip to content

Commit 605ea1b

Browse files
authored
Add support for recipes to help platofrm development (#1502)
* Add --fqbn parameter to monitor command * Add support for pluggable monitors with explicit recipe in platform.txt * increase logging * fix i18n
1 parent d55ba40 commit 605ea1b

File tree

6 files changed

+66
-34
lines changed

6 files changed

+66
-34
lines changed

Diff for: arduino/cores/cores.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type PlatformRelease struct {
6363
IsTrusted bool `json:"-"`
6464
PluggableDiscoveryAware bool `json:"-"` // true if the Platform supports pluggable discovery (no compatibility layer required)
6565
Monitors map[string]*MonitorDependency `json:"-"`
66+
MonitorsDevRecipes map[string]string `json:"-"`
6667
}
6768

6869
// BoardManifest contains information about a board. These metadata are usually

Diff for: arduino/cores/packagemanager/loader.go

+9
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,20 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
368368
if len(split) != 2 {
369369
return fmt.Errorf(tr("invalid pluggable monitor reference: %s"), ref)
370370
}
371+
pm.Log.WithField("protocol", protocol).WithField("tool", ref).Info("Adding monitor tool")
371372
platform.Monitors[protocol] = &cores.MonitorDependency{
372373
Packager: split[0],
373374
Name: split[1],
374375
}
375376
}
377+
378+
// Support for pluggable monitors in debugging/development environments
379+
platform.MonitorsDevRecipes = map[string]string{}
380+
for protocol, recipe := range platform.Properties.SubTree("pluggable_monitor.pattern").AsMap() {
381+
pm.Log.WithField("protocol", protocol).WithField("recipe", recipe).Info("Adding monitor recipe")
382+
platform.MonitorsDevRecipes[protocol] = recipe
383+
}
384+
376385
return nil
377386
}
378387

Diff for: cli/monitor/monitor.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var portArgs arguments.Port
4343
var describe bool
4444
var configs []string
4545
var quiet bool
46+
var fqbn string
4647

4748
// NewCommand created a new `monitor` command
4849
func NewCommand() *cobra.Command {
@@ -59,6 +60,7 @@ func NewCommand() *cobra.Command {
5960
cmd.Flags().BoolVar(&describe, "describe", false, tr("Show all the settings of the communication port."))
6061
cmd.Flags().StringSliceVarP(&configs, "config", "c", []string{}, tr("Configuration of the port."))
6162
cmd.Flags().BoolVarP(&quiet, "quiet", "q", false, tr("Run in silent mode, show only monitor input and output."))
63+
cmd.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
6264
cmd.MarkFlagRequired("port")
6365
return cmd
6466
}
@@ -79,7 +81,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
7981
enumerateResp, err := monitor.EnumerateMonitorPortSettings(context.Background(), &rpc.EnumerateMonitorPortSettingsRequest{
8082
Instance: instance,
8183
PortProtocol: portProtocol,
82-
Fqbn: "",
84+
Fqbn: fqbn,
8385
})
8486
if err != nil {
8587
feedback.Error(tr("Error getting port settings details: %s", err))
@@ -143,7 +145,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
143145
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorRequest{
144146
Instance: instance,
145147
Port: &rpc.Port{Address: portAddress, Protocol: portProtocol},
146-
Fqbn: "",
148+
Fqbn: fqbn,
147149
PortConfiguration: configuration,
148150
})
149151
if err != nil {

Diff for: commands/monitor/monitor.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ package monitor
1717

1818
import (
1919
"context"
20+
"fmt"
2021
"io"
2122

2223
"github.com/arduino/arduino-cli/arduino/cores"
2324
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2425
pluggableMonitor "github.com/arduino/arduino-cli/arduino/monitor"
2526
"github.com/arduino/arduino-cli/commands"
27+
"github.com/arduino/arduino-cli/i18n"
2628
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
29+
"github.com/arduino/go-properties-orderedmap"
2730
)
2831

32+
var tr = i18n.Tr
33+
2934
// PortProxy is an io.ReadWriteCloser that maps into the monitor port of the board
3035
type PortProxy struct {
3136
rw io.ReadWriter
@@ -102,13 +107,22 @@ func findMonitorForProtocolAndBoard(pm *packagemanager.PackageManager, protocol,
102107
return nil, &commands.InvalidFQBNError{Cause: err}
103108
}
104109

105-
_, boardPlatform, _, _, _, err := pm.ResolveFQBN(fqbn)
110+
_, boardPlatform, _, boardProperties, _, err := pm.ResolveFQBN(fqbn)
106111
if err != nil {
107112
return nil, &commands.UnknownFQBNError{Cause: err}
108113
}
109114

110115
if mon, ok := boardPlatform.Monitors[protocol]; ok {
111116
monitorDepOrRecipe = mon
117+
} else if recipe, ok := boardPlatform.MonitorsDevRecipes[protocol]; ok {
118+
// If we have a recipe we must resolve it
119+
cmdLine := boardProperties.ExpandPropsInString(recipe)
120+
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
121+
if err != nil {
122+
return nil, &commands.InvalidArgumentError{Message: tr("Invalid recipe in platform.txt"), Cause: err}
123+
}
124+
id := fmt.Sprintf("%s-%s", boardPlatform, protocol)
125+
return pluggableMonitor.New(id, cmdArgs...), nil
112126
}
113127
}
114128

@@ -126,6 +140,7 @@ func findMonitorForProtocolAndBoard(pm *packagemanager.PackageManager, protocol,
126140
return nil, &commands.NoMonitorAvailableForProtocolError{Protocol: protocol}
127141
}
128142

143+
// If it is a monitor dependency, resolve tool and create a monitor client
129144
tool := pm.FindMonitorDependency(monitorDepOrRecipe)
130145
if tool == nil {
131146
return nil, &commands.MonitorNotFoundError{Monitor: monitorDepOrRecipe.String()}

Diff for: i18n/data/en.po

+32-27
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ msgstr "Config file already exists, use --overwrite to discard the existing one.
407407
msgid "Config file written to: %s"
408408
msgstr "Config file written to: %s"
409409

410-
#: cli/monitor/monitor.go:60
410+
#: cli/monitor/monitor.go:61
411411
msgid "Configuration of the port."
412412
msgstr "Configuration of the port."
413413

@@ -427,7 +427,7 @@ msgstr "Configuring platform."
427427
msgid "Connected"
428428
msgstr "Connected"
429429

430-
#: cli/monitor/monitor.go:172
430+
#: cli/monitor/monitor.go:174
431431
msgid "Connected to %s! Press CTRL-C to exit."
432432
msgstr "Connected to %s! Press CTRL-C to exit."
433433

@@ -504,7 +504,7 @@ msgstr "Debugging not supported for board %s"
504504
msgid "Debugging supported:"
505505
msgstr "Debugging supported:"
506506

507-
#: cli/monitor/monitor.go:190
507+
#: cli/monitor/monitor.go:192
508508
msgid "Default"
509509
msgstr "Default"
510510

@@ -790,7 +790,7 @@ msgstr "Error getting information for library %s"
790790
msgid "Error getting libraries info: %v"
791791
msgstr "Error getting libraries info: %v"
792792

793-
#: cli/monitor/monitor.go:85
793+
#: cli/monitor/monitor.go:87
794794
msgid "Error getting port settings details: %s"
795795
msgstr "Error getting port settings details: %s"
796796

@@ -1091,6 +1091,7 @@ msgstr "Force skip of post-install scripts (if the CLI is running interactively)
10911091
#: cli/burnbootloader/burnbootloader.go:53
10921092
#: cli/compile/compile.go:85
10931093
#: cli/debug/debug.go:61
1094+
#: cli/monitor/monitor.go:63
10941095
#: cli/upload/upload.go:57
10951096
msgid "Fully Qualified Board Name, e.g.: arduino:avr:uno"
10961097
msgstr "Fully Qualified Board Name, e.g.: arduino:avr:uno"
@@ -1138,7 +1139,7 @@ msgstr "Global variables use {0} bytes of dynamic memory."
11381139

11391140
#: cli/core/list.go:84
11401141
#: cli/core/search.go:114
1141-
#: cli/monitor/monitor.go:190
1142+
#: cli/monitor/monitor.go:192
11421143
#: cli/outdated/outdated.go:62
11431144
msgid "ID"
11441145
msgstr "ID"
@@ -1291,6 +1292,10 @@ msgstr "Invalid parameter %s: version not allowed"
12911292
msgid "Invalid pid value: '%s'"
12921293
msgstr "Invalid pid value: '%s'"
12931294

1295+
#: commands/monitor/monitor.go:122
1296+
msgid "Invalid recipe in platform.txt"
1297+
msgstr "Invalid recipe in platform.txt"
1298+
12941299
#: legacy/builder/phases/sizer.go:162
12951300
msgid "Invalid size regexp: %s"
12961301
msgstr "Invalid size regexp: %s"
@@ -1475,7 +1480,7 @@ msgstr "Missing sketch path"
14751480
msgid "Monitor '%s' not found"
14761481
msgstr "Monitor '%s' not found"
14771482

1478-
#: cli/monitor/monitor.go:138
1483+
#: cli/monitor/monitor.go:140
14791484
msgid "Monitor port settings:"
14801485
msgstr "Monitor port settings:"
14811486

@@ -1580,8 +1585,8 @@ msgstr "OS:"
15801585
msgid "Official Arduino board:"
15811586
msgstr "Official Arduino board:"
15821587

1583-
#: cli/monitor/monitor.go:51
15841588
#: cli/monitor/monitor.go:52
1589+
#: cli/monitor/monitor.go:53
15851590
msgid "Open a communication port with a board."
15861591
msgstr "Open a communication port with a board."
15871592

@@ -1731,8 +1736,8 @@ msgstr "Platform size (bytes):"
17311736
msgid "Port"
17321737
msgstr "Port"
17331738

1734-
#: cli/monitor/monitor.go:159
1735-
#: cli/monitor/monitor.go:166
1739+
#: cli/monitor/monitor.go:161
1740+
#: cli/monitor/monitor.go:168
17361741
msgid "Port closed:"
17371742
msgstr "Port closed:"
17381743

@@ -1815,7 +1820,7 @@ msgstr "Required tool:"
18151820
msgid "Run as a daemon on port: %s"
18161821
msgstr "Run as a daemon on port: %s"
18171822

1818-
#: cli/monitor/monitor.go:61
1823+
#: cli/monitor/monitor.go:62
18191824
msgid "Run in silent mode, show only monitor input and output."
18201825
msgstr "Run in silent mode, show only monitor input and output."
18211826

@@ -1873,7 +1878,7 @@ msgstr "Sets a setting value."
18731878
msgid "Sets where to save the configuration file."
18741879
msgstr "Sets where to save the configuration file."
18751880

1876-
#: cli/monitor/monitor.go:190
1881+
#: cli/monitor/monitor.go:192
18771882
msgid "Setting"
18781883
msgstr "Setting"
18791884

@@ -1890,7 +1895,7 @@ msgstr "Show all available core versions."
18901895
msgid "Show all build properties used instead of compiling."
18911896
msgstr "Show all build properties used instead of compiling."
18921897

1893-
#: cli/monitor/monitor.go:59
1898+
#: cli/monitor/monitor.go:60
18941899
msgid "Show all the settings of the communication port."
18951900
msgstr "Show all the settings of the communication port."
18961901

@@ -2348,7 +2353,7 @@ msgstr "VERSION"
23482353
msgid "VERSION_NUMBER"
23492354
msgstr "VERSION_NUMBER"
23502355

2351-
#: cli/monitor/monitor.go:190
2356+
#: cli/monitor/monitor.go:192
23522357
msgid "Values"
23532358
msgstr "Values"
23542359

@@ -2469,7 +2474,7 @@ msgstr "can't find latest release of %s"
24692474
msgid "can't find main Sketch file in %s"
24702475
msgstr "can't find main Sketch file in %s"
24712476

2472-
#: arduino/cores/packagemanager/loader.go:782
2477+
#: arduino/cores/packagemanager/loader.go:791
24732478
msgid "can't find pattern for discovery with id %s"
24742479
msgstr "can't find pattern for discovery with id %s"
24752480

@@ -2552,7 +2557,7 @@ msgstr "computing hash: %s"
25522557
msgid "could not find a valid build artifact"
25532558
msgstr "could not find a valid build artifact"
25542559

2555-
#: arduino/cores/packagemanager/loader.go:719
2560+
#: arduino/cores/packagemanager/loader.go:728
25562561
msgid "creating discovery: %s"
25572562
msgstr "creating discovery: %s"
25582563

@@ -2593,11 +2598,11 @@ msgstr "directory doesn't exist: %s"
25932598
msgid "discovery %[1]s process not started: %[2]w"
25942599
msgstr "discovery %[1]s process not started: %[2]w"
25952600

2596-
#: arduino/cores/packagemanager/loader.go:710
2601+
#: arduino/cores/packagemanager/loader.go:719
25972602
msgid "discovery not found: %s"
25982603
msgstr "discovery not found: %s"
25992604

2600-
#: arduino/cores/packagemanager/loader.go:714
2605+
#: arduino/cores/packagemanager/loader.go:723
26012606
msgid "discovery not installed: %s"
26022607
msgstr "discovery not installed: %s"
26032608

@@ -2734,7 +2739,7 @@ msgstr "getting build properties for board %[1]s: %[2]s"
27342739
msgid "getting discovery dependencies for platform %[1]s: %[2]s"
27352740
msgstr "getting discovery dependencies for platform %[1]s: %[2]s"
27362741

2737-
#: arduino/cores/packagemanager/loader.go:663
2742+
#: arduino/cores/packagemanager/loader.go:672
27382743
msgid "getting parent dir of %[1]s: %[2]s"
27392744
msgstr "getting parent dir of %[1]s: %[2]s"
27402745

@@ -2855,11 +2860,11 @@ msgstr "invalid platform archive size: %s"
28552860
msgid "invalid pluggable monitor reference: %s"
28562861
msgstr "invalid pluggable monitor reference: %s"
28572862

2858-
#: cli/monitor/monitor.go:121
2863+
#: cli/monitor/monitor.go:123
28592864
msgid "invalid port configuration value for %s: %s"
28602865
msgstr "invalid port configuration value for %s: %s"
28612866

2862-
#: cli/monitor/monitor.go:130
2867+
#: cli/monitor/monitor.go:132
28632868
msgid "invalid port configuration: %s"
28642869
msgstr "invalid port configuration: %s"
28652870

@@ -2918,7 +2923,7 @@ msgstr "loading %[1]s: %[2]s"
29182923
msgid "loading boards: %s"
29192924
msgstr "loading boards: %s"
29202925

2921-
#: arduino/cores/packagemanager/loader.go:618
2926+
#: arduino/cores/packagemanager/loader.go:627
29222927
msgid "loading bundled tools from %[1]s: %[2]s"
29232928
msgstr "loading bundled tools from %[1]s: %[2]s"
29242929

@@ -2945,7 +2950,7 @@ msgstr "loading platform release %[1]s: %[2]s"
29452950
msgid "loading platform.txt: %v"
29462951
msgstr "loading platform.txt: %v"
29472952

2948-
#: arduino/cores/packagemanager/loader.go:585
2953+
#: arduino/cores/packagemanager/loader.go:594
29492954
msgid "loading tool release in %[1]s: %[2]s"
29502955
msgstr "loading tool release in %[1]s: %[2]s"
29512956

@@ -3089,7 +3094,7 @@ msgstr "platform %s is not installed"
30893094

30903095
#: arduino/cores/packagemanager/install_uninstall.go:65
30913096
#: arduino/cores/packagemanager/install_uninstall.go:108
3092-
#: arduino/cores/packagemanager/loader.go:447
3097+
#: arduino/cores/packagemanager/loader.go:456
30933098
#: commands/compile/compile.go:127
30943099
msgid "platform not installed"
30953100
msgstr "platform not installed"
@@ -3126,7 +3131,7 @@ msgstr "quitting discovery %[1]s: %[2]w"
31263131
msgid "reading %[1]s directory: %[2]s"
31273132
msgstr "reading %[1]s directory: %[2]s"
31283133

3129-
#: arduino/cores/packagemanager/loader.go:668
3134+
#: arduino/cores/packagemanager/loader.go:677
31303135
msgid "reading %[1]s: %[2]s"
31313136
msgstr "reading %[1]s: %[2]s"
31323137

@@ -3136,7 +3141,7 @@ msgid "reading dir %[1]s: %[2]s"
31363141
msgstr "reading dir %[1]s: %[2]s"
31373142

31383143
#: arduino/cores/packagemanager/loader.go:162
3139-
#: arduino/cores/packagemanager/loader.go:576
3144+
#: arduino/cores/packagemanager/loader.go:585
31403145
msgid "reading directory %[1]s: %[2]s"
31413146
msgstr "reading directory %[1]s: %[2]s"
31423147

@@ -3227,7 +3232,7 @@ msgstr "retrieving Arduino public keys: %s"
32273232
msgid "scanning examples: %s"
32283233
msgstr "scanning examples: %s"
32293234

3230-
#: arduino/cores/packagemanager/loader.go:654
3235+
#: arduino/cores/packagemanager/loader.go:663
32313236
msgid "searching for builtin_tools_versions.txt in %[1]s: %[2]s"
32323237
msgstr "searching for builtin_tools_versions.txt in %[1]s: %[2]s"
32333238

@@ -3248,7 +3253,7 @@ msgstr "sketch path is not valid"
32483253
msgid "sketchPath"
32493254
msgstr "sketchPath"
32503255

3251-
#: arduino/cores/packagemanager/loader.go:510
3256+
#: arduino/cores/packagemanager/loader.go:519
32523257
msgid "skipping loading of boards %s: malformed custom board options"
32533258
msgstr "skipping loading of boards %s: malformed custom board options"
32543259

Diff for: i18n/rice-box.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)