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 7b774e1

Browse files
authored
Implemented --show-properties in board details command (#2151)
* Renaming some variables for clarity * Moved 'build.board' property generation out of legacy package * Moved unit tests related to build properties out of legacy package * Removed legacy TargetBoardResolver and refactored unit-tests * Removed legacy HardwareLoader * Factored sketch-related build properties creation * Moved SetupBuildProperties into proper package * Removed SetCustomBuildProperties from legacy * Factored --show-properties cli flag parser * Made 'board ...' command arguments variables local * Implemented --show-properties in 'board details' * Fixed integration test
1 parent bfb5f3f commit 7b774e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2743
-1730
lines changed

‎arduino/builder/sketch.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/arduino/arduino-cli/arduino/sketch"
2525
"github.com/arduino/arduino-cli/i18n"
2626
"github.com/arduino/go-paths-helper"
27+
"github.com/arduino/go-properties-orderedmap"
2728

2829
"github.com/pkg/errors"
2930
)
@@ -169,3 +170,29 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error {
169170
// Source and destination are the same, don't write anything
170171
return nil
171172
}
173+
174+
// SetupBuildProperties adds the build properties related to the sketch to the
175+
// default board build properties map.
176+
func SetupBuildProperties(boardBuildProperties *properties.Map, buildPath *paths.Path, sketch *sketch.Sketch, optimizeForDebug bool) *properties.Map {
177+
buildProperties := properties.NewMap()
178+
buildProperties.Merge(boardBuildProperties)
179+
180+
if buildPath != nil {
181+
buildProperties.SetPath("build.path", buildPath)
182+
}
183+
if sketch != nil {
184+
buildProperties.Set("build.project_name", sketch.MainFile.Base())
185+
buildProperties.SetPath("build.source.path", sketch.FullPath)
186+
}
187+
if optimizeForDebug {
188+
if debugFlags, ok := buildProperties.GetOk("compiler.optimization_flags.debug"); ok {
189+
buildProperties.Set("compiler.optimization_flags", debugFlags)
190+
}
191+
} else {
192+
if releaseFlags, ok := buildProperties.GetOk("compiler.optimization_flags.release"); ok {
193+
buildProperties.Set("compiler.optimization_flags", releaseFlags)
194+
}
195+
}
196+
197+
return buildProperties
198+
}

‎arduino/cores/packagemanager/package_manager.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,13 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
359359
}
360360
buildProperties.Set("runtime.os", properties.GetOSSuffix())
361361
buildProperties.Set("build.library_discovery_phase", "0")
362+
363+
if buildProperties.Get("build.board") == "" {
364+
architecture := board.PlatformRelease.Platform.Architecture
365+
defaultBuildBoard := strings.ToUpper(architecture + "_" + board.BoardID)
366+
buildProperties.Set("build.board", defaultBuildBoard)
367+
}
368+
362369
// Deprecated properties
363370
buildProperties.Set("tools.avrdude.path", "{runtime.tools.avrdude.path}")
364371
buildProperties.Set("ide_version", "10607")

‎arduino/cores/packagemanager/package_manager_test.go‎

Lines changed: 139 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestResolveFQBN(t *testing.T) {
6767
pme, release := pm.NewExplorer()
6868
defer release()
6969

70-
{
70+
t.Run("NormalizeFQBN", func(t*testing.T) {
7171
testNormalization := func(in, expected string) {
7272
fqbn, err := cores.ParseFQBN(in)
7373
require.Nil(t, err)
@@ -89,9 +89,9 @@ func TestResolveFQBN(t *testing.T) {
8989
testNormalization("esp8266:esp8266:generic:baud=115200,wipe=sdk", "esp8266:esp8266:generic:wipe=sdk")
9090
testNormalization("arduino:avr:mega:cpu=nonexistent", "ERROR")
9191
testNormalization("arduino:avr:mega:nonexistent=blah", "ERROR")
92-
}
92+
})
9393

94-
{
94+
t.Run("BoardAndBuildPropertiesArduinoUno", func(t*testing.T) {
9595
fqbn, err := cores.ParseFQBN("arduino:avr:uno")
9696
require.Nil(t, err)
9797
require.NotNil(t, fqbn)
@@ -105,9 +105,14 @@ func TestResolveFQBN(t *testing.T) {
105105
require.Equal(t, board.Name(), "Arduino Uno")
106106
require.NotNil(t, props)
107107
require.Equal(t, platformRelease, buildPlatformRelease)
108-
}
109108

110-
{
109+
require.Equal(t, "arduino", pkg.Name)
110+
require.Equal(t, "avr", platformRelease.Platform.Architecture)
111+
require.Equal(t, "uno", board.BoardID)
112+
require.Equal(t, "atmega328p", props.Get("build.mcu"))
113+
})
114+
115+
t.Run("BoardAndBuildPropertiesArduinoMega", func(t *testing.T) {
111116
fqbn, err := cores.ParseFQBN("arduino:avr:mega")
112117
require.Nil(t, err)
113118
require.NotNil(t, fqbn)
@@ -121,9 +126,46 @@ func TestResolveFQBN(t *testing.T) {
121126
require.Equal(t, board.Name(), "Arduino Mega or Mega 2560")
122127
require.NotNil(t, props)
123128
require.Equal(t, platformRelease, buildPlatformRelease)
124-
}
129+
})
125130

126-
{
131+
t.Run("BoardAndBuildPropertiesArduinoMegaWithNonDefaultCpuOption", func(t *testing.T) {
132+
fqbn, err := cores.ParseFQBN("arduino:avr:mega:cpu=atmega1280")
133+
require.Nil(t, err)
134+
require.NotNil(t, fqbn)
135+
pkg, platformRelease, board, props, buildPlatformRelease, err := pme.ResolveFQBN(fqbn)
136+
require.Nil(t, err)
137+
require.Equal(t, pkg, platformRelease.Platform.Package)
138+
require.NotNil(t, platformRelease)
139+
require.NotNil(t, platformRelease.Platform)
140+
require.Equal(t, platformRelease, buildPlatformRelease)
141+
142+
require.Equal(t, "arduino", pkg.Name)
143+
require.Equal(t, "avr", platformRelease.Platform.Architecture)
144+
require.Equal(t, "mega", board.BoardID)
145+
require.Equal(t, "atmega1280", props.Get("build.mcu"))
146+
require.Equal(t, "AVR_MEGA", props.Get("build.board"))
147+
})
148+
149+
t.Run("BoardAndBuildPropertiesArduinoMegaWithDefaultCpuOption", func(t *testing.T) {
150+
fqbn, err := cores.ParseFQBN("arduino:avr:mega:cpu=atmega2560")
151+
require.Nil(t, err)
152+
require.NotNil(t, fqbn)
153+
pkg, platformRelease, board, props, buildPlatformRelease, err := pme.ResolveFQBN(fqbn)
154+
require.Nil(t, err)
155+
require.Equal(t, pkg, platformRelease.Platform.Package)
156+
require.NotNil(t, platformRelease)
157+
require.NotNil(t, platformRelease.Platform)
158+
require.Equal(t, platformRelease, buildPlatformRelease)
159+
160+
require.Equal(t, "arduino", pkg.Name)
161+
require.Equal(t, "avr", platformRelease.Platform.Architecture)
162+
require.Equal(t, "mega", board.BoardID)
163+
require.Equal(t, "atmega2560", props.Get("build.mcu"))
164+
require.Equal(t, "AVR_MEGA2560", props.Get("build.board"))
165+
166+
})
167+
168+
t.Run("BoardAndBuildPropertiesForReferencedArduinoUno", func(t *testing.T) {
127169
// Test a board referenced from the main AVR arduino platform
128170
fqbn, err := cores.ParseFQBN("referenced:avr:uno")
129171
require.Nil(t, err)
@@ -140,9 +182,56 @@ func TestResolveFQBN(t *testing.T) {
140182
require.NotNil(t, buildPlatformRelease)
141183
require.NotNil(t, buildPlatformRelease.Platform)
142184
require.Equal(t, buildPlatformRelease.Platform.String(), "arduino:avr")
143-
}
185+
})
144186

145-
{
187+
t.Run("BoardAndBuildPropertiesForArduinoDue", func(t *testing.T) {
188+
fqbn, err := cores.ParseFQBN("arduino:sam:arduino_due_x")
189+
require.Nil(t, err)
190+
require.NotNil(t, fqbn)
191+
pkg, platformRelease, board, props, buildPlatformRelease, err := pme.ResolveFQBN(fqbn)
192+
require.Nil(t, err)
193+
require.Equal(t, pkg, platformRelease.Platform.Package)
194+
require.Equal(t, platformRelease, buildPlatformRelease)
195+
196+
require.Equal(t, "arduino", pkg.Name)
197+
require.Equal(t, "sam", platformRelease.Platform.Architecture)
198+
require.Equal(t, "arduino_due_x", board.BoardID)
199+
require.Equal(t, "cortex-m3", props.Get("build.mcu"))
200+
})
201+
202+
t.Run("BoardAndBuildPropertiesForCustomArduinoYun", func(t *testing.T) {
203+
fqbn, err := cores.ParseFQBN("my_avr_platform:avr:custom_yun")
204+
require.Nil(t, err)
205+
require.NotNil(t, fqbn)
206+
pkg, platformRelease, board, props, buildPlatformRelease, err := pme.ResolveFQBN(fqbn)
207+
require.Nil(t, err)
208+
require.Equal(t, pkg, platformRelease.Platform.Package)
209+
require.NotEqual(t, platformRelease, buildPlatformRelease)
210+
211+
require.Equal(t, "my_avr_platform", pkg.Name)
212+
require.Equal(t, "avr", platformRelease.Platform.Architecture)
213+
require.Equal(t, "custom_yun", board.BoardID)
214+
require.Equal(t, "atmega32u4", props.Get("build.mcu"))
215+
require.Equal(t, "AVR_YUN", props.Get("build.board"))
216+
})
217+
218+
t.Run("BoardAndBuildPropertiesForWatterotCore", func(t *testing.T) {
219+
fqbn, err := cores.ParseFQBN("watterott:avr:attiny841:core=spencekonde,info=info")
220+
require.Nil(t, err)
221+
require.NotNil(t, fqbn)
222+
pkg, platformRelease, board, props, buildPlatformRelease, err := pme.ResolveFQBN(fqbn)
223+
require.Nil(t, err)
224+
require.Equal(t, pkg, platformRelease.Platform.Package)
225+
require.Equal(t, platformRelease, buildPlatformRelease)
226+
227+
require.Equal(t, "watterott", pkg.Name)
228+
require.Equal(t, "avr", platformRelease.Platform.Architecture)
229+
require.Equal(t, "attiny841", board.BoardID)
230+
require.Equal(t, "tiny841", props.Get("build.core"))
231+
require.Equal(t, "tiny14", props.Get("build.variant"))
232+
})
233+
234+
t.Run("BoardAndBuildPropertiesForReferencedFeatherM0", func(t *testing.T) {
146235
// Test a board referenced from the Adafruit SAMD core (this tests
147236
// deriving where the package and core name are different)
148237
fqbn, err := cores.ParseFQBN("referenced:samd:feather_m0")
@@ -160,9 +249,9 @@ func TestResolveFQBN(t *testing.T) {
160249
require.NotNil(t, buildPlatformRelease)
161250
require.NotNil(t, buildPlatformRelease.Platform)
162251
require.Equal(t, buildPlatformRelease.Platform.String(), "adafruit:samd")
163-
}
252+
})
164253

165-
{
254+
t.Run("BoardAndBuildPropertiesForNonExistentPackage", func(t*testing.T) {
166255
// Test a board referenced from a non-existent package
167256
fqbn, err := cores.ParseFQBN("referenced:avr:dummy_invalid_package")
168257
require.Nil(t, err)
@@ -177,9 +266,9 @@ func TestResolveFQBN(t *testing.T) {
177266
require.Equal(t, board.Name(), "Referenced dummy with invalid package")
178267
require.Nil(t, props)
179268
require.Nil(t, buildPlatformRelease)
180-
}
269+
})
181270

182-
{
271+
t.Run("BoardAndBuildPropertiesForNonExistentArchitecture", func(t*testing.T) {
183272
// Test a board referenced from a non-existent platform/architecture
184273
fqbn, err := cores.ParseFQBN("referenced:avr:dummy_invalid_platform")
185274
require.Nil(t, err)
@@ -194,9 +283,9 @@ func TestResolveFQBN(t *testing.T) {
194283
require.Equal(t, board.Name(), "Referenced dummy with invalid platform")
195284
require.Nil(t, props)
196285
require.Nil(t, buildPlatformRelease)
197-
}
286+
})
198287

199-
{
288+
t.Run("BoardAndBuildPropertiesForNonExistentCore", func(t*testing.T) {
200289
// Test a board referenced from a non-existent core
201290
// Note that ResolveFQBN does not actually check this currently
202291
fqbn, err := cores.ParseFQBN("referenced:avr:dummy_invalid_core")
@@ -214,7 +303,41 @@ func TestResolveFQBN(t *testing.T) {
214303
require.NotNil(t, buildPlatformRelease)
215304
require.NotNil(t, buildPlatformRelease.Platform)
216305
require.Equal(t, buildPlatformRelease.Platform.String(), "arduino:avr")
217-
}
306+
})
307+
308+
t.Run("AddBuildBoardPropertyIfMissing", func(t *testing.T) {
309+
fqbn, err := cores.ParseFQBN("my_avr_platform:avr:mymega")
310+
require.Nil(t, err)
311+
require.NotNil(t, fqbn)
312+
pkg, platformRelease, board, props, buildPlatformRelease, err := pme.ResolveFQBN(fqbn)
313+
require.Nil(t, err)
314+
require.Equal(t, pkg, platformRelease.Platform.Package)
315+
require.Equal(t, platformRelease, buildPlatformRelease)
316+
317+
require.Equal(t, "my_avr_platform", pkg.Name)
318+
require.NotNil(t, platformRelease)
319+
require.NotNil(t, platformRelease.Platform)
320+
require.Equal(t, "avr", platformRelease.Platform.Architecture)
321+
require.Equal(t, "mymega", board.BoardID)
322+
require.Equal(t, "atmega2560", props.Get("build.mcu"))
323+
require.Equal(t, "AVR_MYMEGA", props.Get("build.board"))
324+
})
325+
326+
t.Run("AddBuildBoardPropertyIfNotMissing", func(t *testing.T) {
327+
fqbn, err := cores.ParseFQBN("my_avr_platform:avr:mymega:cpu=atmega1280")
328+
require.Nil(t, err)
329+
require.NotNil(t, fqbn)
330+
pkg, platformRelease, board, props, buildPlatformRelease, err := pme.ResolveFQBN(fqbn)
331+
require.Nil(t, err)
332+
require.Equal(t, pkg, platformRelease.Platform.Package)
333+
require.Equal(t, platformRelease, buildPlatformRelease)
334+
335+
require.Equal(t, "my_avr_platform", pkg.Name)
336+
require.Equal(t, "avr", platformRelease.Platform.Architecture)
337+
require.Equal(t, "mymega", board.BoardID)
338+
require.Equal(t, "atmega1280", props.Get("build.mcu"))
339+
require.Equal(t, "MYMEGA1280", props.Get("build.board"))
340+
})
218341
}
219342

220343
func TestBoardOptionsFunctions(t *testing.T) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
arduino_due_x_dbg.name=Arduino Due (Programming Port)
3+
arduino_due_x_dbg.vid.0=0x2341
4+
arduino_due_x_dbg.pid.0=0x003d
5+
arduino_due_x_dbg.vid.1=0x2A03
6+
arduino_due_x_dbg.pid.1=0x003d
7+
arduino_due_x_dbg.upload.tool=bossac
8+
arduino_due_x_dbg.upload.protocol=sam-ba
9+
arduino_due_x_dbg.upload.maximum_size=524288
10+
arduino_due_x_dbg.upload.use_1200bps_touch=true
11+
arduino_due_x_dbg.upload.wait_for_upload_port=false
12+
arduino_due_x_dbg.upload.native_usb=false
13+
arduino_due_x_dbg.build.mcu=cortex-m3
14+
arduino_due_x_dbg.build.f_cpu=84000000L
15+
arduino_due_x_dbg.build.usb_manufacturer="Arduino LLC"
16+
arduino_due_x_dbg.build.usb_product="Arduino Due"
17+
arduino_due_x_dbg.build.board=SAM_DUE
18+
arduino_due_x_dbg.build.core=arduino
19+
arduino_due_x_dbg.build.extra_flags=-D__SAM3X8E__ -mthumb {build.usb_flags}
20+
arduino_due_x_dbg.build.ldscript=linker_scripts/gcc/flash.ld
21+
arduino_due_x_dbg.build.variant=arduino_due_x
22+
arduino_due_x_dbg.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
23+
arduino_due_x_dbg.build.vid=0x2341
24+
arduino_due_x_dbg.build.pid=0x003e
25+
26+
arduino_due_x.name=Arduino Due (Native USB Port)
27+
arduino_due_x.vid.0=0x2341
28+
arduino_due_x.pid.0=0x003e
29+
arduino_due_x.vid.1=0x2A03
30+
arduino_due_x.pid.1=0x003e
31+
arduino_due_x.upload.tool=bossac
32+
arduino_due_x.upload.protocol=sam-ba
33+
arduino_due_x.upload.maximum_size=524288
34+
arduino_due_x.upload.use_1200bps_touch=true
35+
arduino_due_x.upload.wait_for_upload_port=true
36+
arduino_due_x.upload.native_usb=true
37+
arduino_due_x.build.mcu=cortex-m3
38+
arduino_due_x.build.f_cpu=84000000L
39+
arduino_due_x.build.usb_manufacturer="Arduino LLC"
40+
arduino_due_x.build.usb_product="Arduino Due"
41+
arduino_due_x.build.board=SAM_DUE
42+
arduino_due_x.build.core=arduino
43+
arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb {build.usb_flags}
44+
arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld
45+
arduino_due_x.build.variant=arduino_due_x
46+
arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
47+
arduino_due_x.build.vid=0x2341
48+
arduino_due_x.build.pid=0x003e
49+

0 commit comments

Comments
(0)

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