Skip to content

Commit 5a4a2d2

Browse files
committed
Refactored build properties overlaying logic
1 parent 52f67b9 commit 5a4a2d2

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -293,26 +293,26 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
293293
fmt.Errorf(tr("board %s not found"), fqbn.StringWithoutConfig())
294294
}
295295

296-
buildProperties, err := board.GetBuildProperties(fqbn.Configs)
296+
boardBuildProperties, err := board.GetBuildProperties(fqbn.Configs)
297297
if err != nil {
298298
return targetPackage, platformRelease, board, nil, nil,
299299
fmt.Errorf(tr("getting build properties for board %[1]s: %[2]s"), board, err)
300300
}
301301

302302
// Determine the platform used for the build (in case the board refers
303303
// to a core contained in another platform)
304-
core := buildProperties.Get("build.core")
304+
core := boardBuildProperties.Get("build.core")
305305
referredCore := ""
306306
if split := strings.Split(core, ":"); len(split) > 1 {
307307
core, referredCore = split[1], split[0]
308308
}
309-
variant := buildProperties.Get("build.variant")
309+
variant := boardBuildProperties.Get("build.variant")
310310
referredVariant := ""
311311
if split := strings.Split(variant, ":"); len(split) > 1 {
312312
variant, referredVariant = split[1], split[0]
313313
}
314314
if referredCore != "" && referredVariant != "" && referredCore != referredVariant {
315-
return targetPackage, platformRelease, board, buildProperties, nil,
315+
return targetPackage, platformRelease, board, nil, nil,
316316
fmt.Errorf(tr("'build.core' and 'build.variant' refer to different platforms: %[1]s and %[2]s"), core+":"+referredCore, variant+":"+referredVariant)
317317
}
318318

@@ -324,26 +324,34 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
324324
if referredPackageName != "" {
325325
referredPackage := pme.packages[referredPackageName]
326326
if referredPackage == nil {
327-
return targetPackage, platformRelease, board, buildProperties, nil,
327+
return targetPackage, platformRelease, board, nil, nil,
328328
fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackageName, fqbn)
329329
}
330330
referredPlatform := referredPackage.Platforms[fqbn.PlatformArch]
331331
if referredPlatform == nil {
332-
return targetPackage, platformRelease, board, buildProperties, nil,
332+
return targetPackage, platformRelease, board, nil, nil,
333333
fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn)
334334
}
335335
referredPlatformRelease = pme.GetInstalledPlatformRelease(referredPlatform)
336336
if referredPlatformRelease == nil {
337-
return targetPackage, platformRelease, board, buildProperties, nil,
337+
return targetPackage, platformRelease, board, nil, nil,
338338
fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn)
339339
}
340340
}
341341

342-
// Runtime build properties
342+
// Create the build properties map by overlaying the properties of the
343+
// referenced platform propeties, the board platform properties and the
344+
// board specific properties.
345+
buildProperties := properties.NewMap()
343346
buildPlatformRelease := platformRelease
344347
if referredCore != "" {
345348
buildPlatformRelease = referredPlatformRelease
346349
}
350+
buildProperties.Merge(buildPlatformRelease.Properties)
351+
buildProperties.Merge(platformRelease.Properties)
352+
buildProperties.Merge(boardBuildProperties)
353+
354+
// Add runtime build properties
347355
buildProperties.Merge(platformRelease.RuntimeProperties())
348356
buildProperties.SetPath("build.core.path", buildPlatformRelease.InstallDir.Join("cores", core))
349357
buildProperties.SetPath("build.system.path", buildPlatformRelease.InstallDir.Join("system"))
@@ -389,7 +397,6 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
389397
buildProperties.Set("software", "ARDUINO")
390398
}
391399

392-
// No errors... phew!
393400
return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil
394401
}
395402

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestResolveFQBN(t *testing.T) {
141141
require.Equal(t, platformRelease.Platform.String(), "referenced:avr")
142142
require.NotNil(t, board)
143143
require.Equal(t, board.Name(), "Referenced dummy with invalid package")
144-
require.NotNil(t, props)
144+
require.Nil(t, props)
145145
require.Nil(t, buildPlatformRelease)
146146

147147
// Test a board referenced from a non-existent platform/architecture
@@ -156,7 +156,7 @@ func TestResolveFQBN(t *testing.T) {
156156
require.Equal(t, platformRelease.Platform.String(), "referenced:avr")
157157
require.NotNil(t, board)
158158
require.Equal(t, board.Name(), "Referenced dummy with invalid platform")
159-
require.NotNil(t, props)
159+
require.Nil(t, props)
160160
require.Nil(t, buildPlatformRelease)
161161

162162
// Test a board referenced from a non-existent core

Diff for: legacy/builder/setup_build_properties.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ import (
2424
type SetupBuildProperties struct{}
2525

2626
func (s *SetupBuildProperties) Run(ctx *types.Context) error {
27-
targetPlatform := ctx.TargetPlatform
28-
actualPlatform := ctx.ActualPlatform
29-
3027
buildProperties := properties.NewMap()
31-
buildProperties.Merge(actualPlatform.Properties)
32-
buildProperties.Merge(targetPlatform.Properties)
3328
buildProperties.Merge(ctx.TargetBoardBuildProperties)
3429

3530
if ctx.BuildPath != nil {
@@ -59,7 +54,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
5954
encryptProp := buildProperties.ContainsKey("build.keys.encrypt_key")
6055
// we verify that all the properties for the secure boot keys are defined or none of them is defined.
6156
if (keychainProp || signProp || encryptProp) && !(keychainProp && signProp && encryptProp) {
62-
return errors.Errorf("%s platform does not specify correctly default sign and encryption keys", targetPlatform.Platform)
57+
return errors.Errorf("%s platform does not specify correctly default sign and encryption keys", ctx.TargetPlatform.Platform)
6358
}
6459

6560
ctx.BuildProperties = buildProperties

0 commit comments

Comments
 (0)