From 7e270d6229fbd38ff36e0b714b992a93c3d9325b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 13:52:40 +0100 Subject: [PATCH 01/12] Moved 'build.fqbn' and 'build.arch' properties generation --- arduino/cores/board.go | 2 ++ arduino/cores/board_test.go | 6 ++++++ legacy/builder/setup_build_properties.go | 2 -- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arduino/cores/board.go b/arduino/cores/board.go index a59c6d31d16..3c839766bd8 100644 --- a/arduino/cores/board.go +++ b/arduino/cores/board.go @@ -125,6 +125,8 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map // Start with board's base properties buildProperties := b.Properties.Clone() + buildProperties.Set("build.fqbn", b.FQBN()) + buildProperties.Set("build.arch", strings.ToUpper(b.PlatformRelease.Platform.Architecture)) // Add all sub-configurations one by one (a config is: option=value) // Check for residual invalid options... diff --git a/arduino/cores/board_test.go b/arduino/cores/board_test.go index a0665e26c5f..95639bd8171 100644 --- a/arduino/cores/board_test.go +++ b/arduino/cores/board_test.go @@ -216,9 +216,11 @@ func TestBoardOptions(t *testing.T) { expConf2560.Set("bootloader.low_fuses", "0xFF") expConf2560.Set("bootloader.tool", "avrdude") expConf2560.Set("bootloader.unlock_bits", "0x3F") + expConf2560.Set("build.arch", "AVR") expConf2560.Set("build.board", "AVR_MEGA2560") expConf2560.Set("build.core", "arduino") expConf2560.Set("build.f_cpu", "16000000L") + expConf2560.Set("build.fqbn", "arduino:avr:mega") expConf2560.Set("build.mcu", "atmega2560") expConf2560.Set("build.variant", "mega") expConf2560.Set("menu.cpu.atmega1280", "ATmega1280") @@ -275,9 +277,11 @@ func TestBoardOptions(t *testing.T) { expConf1280.Set("bootloader.low_fuses", "0xFF") expConf1280.Set("bootloader.tool", "avrdude") expConf1280.Set("bootloader.unlock_bits", "0x3F") + expConf1280.Set("build.arch", "AVR") expConf1280.Set("build.board", "AVR_MEGA") expConf1280.Set("build.core", "arduino") expConf1280.Set("build.f_cpu", "16000000L") + expConf1280.Set("build.fqbn", "arduino:avr:mega") expConf1280.Set("build.mcu", "atmega1280") expConf1280.Set("build.variant", "mega") expConf1280.Set("menu.cpu.atmega1280", "ATmega1280") @@ -334,9 +338,11 @@ func TestBoardOptions(t *testing.T) { expWatterott.Set("bootloader.low_fuses", "0xE2") expWatterott.Set("bootloader.tool", "avrdude") expWatterott.Set("bootloader.unlock_bits", "0xFF") + expWatterott.Set("build.arch", "AVR") expWatterott.Set("build.board", "AVR_ATTINY841") expWatterott.Set("build.core", "tiny841") expWatterott.Set("build.f_cpu", "8000000L") + expWatterott.Set("build.fqbn", "watterott:avr:attiny841") expWatterott.Set("build.mcu", "attiny841") expWatterott.Set("build.variant", "tiny14") expWatterott.Set("menu.core.arduino", "Standard Arduino") diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index 917da83faf7..99cf298a9af 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -48,7 +48,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { if ctx.Sketch != nil { buildProperties.Set("build.project_name", ctx.Sketch.MainFile.Base()) } - buildProperties.Set("build.arch", strings.ToUpper(targetPlatform.Platform.Architecture)) // get base folder and use it to populate BUILD_PROPERTIES_RUNTIME_IDE_PATH (arduino and arduino-builder live in the same dir) ex, err := os.Executable() @@ -64,7 +63,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties.Set("runtime.hardware.path", targetPlatform.InstallDir.Join("..").String()) buildProperties.Set("runtime.ide.version", ctx.ArduinoAPIVersion) buildProperties.Set("runtime.ide.path", exPath) - buildProperties.Set("build.fqbn", ctx.FQBN.String()) buildProperties.Set("ide_version", ctx.ArduinoAPIVersion) buildProperties.Set("runtime.os", properties.GetOSSuffix()) buildProperties.Set("build.library_discovery_phase", "0") From 5ea38976b5595faf6cdb6775bbaf99e548d38189 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 14:04:20 +0100 Subject: [PATCH 02/12] Moved some runtime build path properties to proper function --- arduino/cores/cores.go | 4 ++-- arduino/cores/packagemanager/package_manager.go | 5 +++++ legacy/builder/setup_build_properties.go | 4 ---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arduino/cores/cores.go b/arduino/cores/cores.go index aa6886d9948..33301b3d986 100644 --- a/arduino/cores/cores.go +++ b/arduino/cores/cores.go @@ -336,8 +336,8 @@ func (release *PlatformRelease) RequiresToolRelease(toolRelease *ToolRelease) bo func (release *PlatformRelease) RuntimeProperties() *properties.Map { res := properties.NewMap() if release.InstallDir != nil { - res.Set("runtime.platform.path", release.InstallDir.String()) - res.Set("runtime.hardware.path", release.InstallDir.Join("..").String()) + res.SetPath("runtime.platform.path", release.InstallDir) + res.SetPath("runtime.hardware.path", release.InstallDir.Join("..")) } return res diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 8cd630e87d8..43c8bbf2f93 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -317,6 +317,11 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( } } + // Runtime build properties + buildProperties.Merge(platformRelease.RuntimeProperties()) + buildProperties.SetPath("build.core.path", buildPlatformRelease.InstallDir.Join("cores", coreParts[0])) + buildProperties.SetPath("build.system.path", buildPlatformRelease.InstallDir.Join("system")) + // No errors... phew! return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil } diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index 99cf298a9af..bd92e27f64f 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -57,10 +57,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { } buildProperties.Set("build.core", ctx.BuildCore) - buildProperties.SetPath("build.core.path", actualPlatform.InstallDir.Join("cores", buildProperties.Get("build.core"))) - buildProperties.Set("build.system.path", actualPlatform.InstallDir.Join("system").String()) - buildProperties.Set("runtime.platform.path", targetPlatform.InstallDir.String()) - buildProperties.Set("runtime.hardware.path", targetPlatform.InstallDir.Join("..").String()) buildProperties.Set("runtime.ide.version", ctx.ArduinoAPIVersion) buildProperties.Set("runtime.ide.path", exPath) buildProperties.Set("ide_version", ctx.ArduinoAPIVersion) From 1fe73d8485a305e58ed10ff12ea178f4ac066e2d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 14:28:58 +0100 Subject: [PATCH 03/12] Factored tools runtime properties generation --- arduino/cores/packagemanager/package_manager.go | 10 ++++++++++ commands/upload/upload.go | 14 -------------- legacy/builder/setup_build_properties.go | 9 --------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 43c8bbf2f93..fa19b49f777 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -321,6 +321,16 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( buildProperties.Merge(platformRelease.RuntimeProperties()) buildProperties.SetPath("build.core.path", buildPlatformRelease.InstallDir.Join("cores", coreParts[0])) buildProperties.SetPath("build.system.path", buildPlatformRelease.InstallDir.Join("system")) + for _, tool := range pme.GetAllInstalledToolsReleases() { + buildProperties.Merge(tool.RuntimeProperties()) + } + requiredTools, err := pme.FindToolsRequiredForBuild(platformRelease, buildPlatformRelease) + if err != nil { + return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, err + } + for _, tool := range requiredTools { + buildProperties.Merge(tool.RuntimeProperties()) + } // No errors... phew! return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 3168281fa03..b9c4f248656 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -292,20 +292,6 @@ func runProgramAction(pme *packagemanager.Explorer, uploadProperties.Merge(programmer.Properties) } - for _, tool := range pme.GetAllInstalledToolsReleases() { - uploadProperties.Merge(tool.RuntimeProperties()) - } - if requiredTools, err := pme.FindToolsRequiredForBuild(boardPlatform, buildPlatform); err == nil { - for _, requiredTool := range requiredTools { - logrus.WithField("tool", requiredTool).Info("Tool required for upload") - if requiredTool.IsInstalled() { - uploadProperties.Merge(requiredTool.RuntimeProperties()) - } else { - errStream.Write([]byte(tr("Warning: tool '%s' is not installed. It might not be available for your OS.", requiredTool))) - } - } - } - // Certain tools require the user to provide custom fields at run time, // if they've been provided set them // For more info: diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index bd92e27f64f..eed0e16ef9e 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -90,15 +90,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties.SetPath("build.variant.path", variantPlatformRelease.InstallDir.Join("variants", variant)) } - for _, tool := range ctx.AllTools { - buildProperties.SetPath("runtime.tools."+tool.Tool.Name+".path", tool.InstallDir) - buildProperties.SetPath("runtime.tools."+tool.Tool.Name+"-"+tool.Version.String()+".path", tool.InstallDir) - } - for _, tool := range ctx.RequiredTools { - buildProperties.SetPath("runtime.tools."+tool.Tool.Name+".path", tool.InstallDir) - buildProperties.SetPath("runtime.tools."+tool.Tool.Name+"-"+tool.Version.String()+".path", tool.InstallDir) - } - if !buildProperties.ContainsKey("software") { buildProperties.Set("software", DEFAULT_SOFTWARE) } From a899fcc6c762b7866e3cda56e8123f54f0aa0263 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 14:32:26 +0100 Subject: [PATCH 04/12] Factored subroutine for time-related properties generation --- arduino/cores/packagemanager/package_manager.go | 8 ++++++++ legacy/builder/setup_build_properties.go | 9 --------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index fa19b49f777..11241ce7741 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -19,8 +19,10 @@ import ( "fmt" "net/url" "path" + "strconv" "strings" "sync" + "time" "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores/packageindex" @@ -29,6 +31,7 @@ import ( "github.com/arduino/arduino-cli/i18n" paths "github.com/arduino/go-paths-helper" properties "github.com/arduino/go-properties-orderedmap" + "github.com/arduino/go-timeutils" "github.com/sirupsen/logrus" semver "go.bug.st/relaxed-semver" ) @@ -331,6 +334,11 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( for _, tool := range requiredTools { buildProperties.Merge(tool.RuntimeProperties()) } + now := time.Now() + buildProperties.Set("extra.time.utc", strconv.FormatInt(now.Unix(), 10)) + buildProperties.Set("extra.time.local", strconv.FormatInt(timeutils.LocalUnix(now), 10)) + buildProperties.Set("extra.time.zone", strconv.Itoa(timeutils.TimezoneOffsetNoDST(now))) + buildProperties.Set("extra.time.dst", strconv.Itoa(timeutils.DaylightSavingsOffset(now))) // No errors... phew! return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index eed0e16ef9e..ca7a7e06631 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -18,14 +18,11 @@ package builder import ( "os" "path/filepath" - "strconv" "strings" - "time" "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/legacy/builder/types" properties "github.com/arduino/go-properties-orderedmap" - timeutils "github.com/arduino/go-timeutils" "github.com/pkg/errors" ) @@ -96,12 +93,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties.SetPath("build.source.path", ctx.Sketch.FullPath) - now := time.Now() - buildProperties.Set("extra.time.utc", strconv.FormatInt(now.Unix(), 10)) - buildProperties.Set("extra.time.local", strconv.FormatInt(timeutils.LocalUnix(now), 10)) - buildProperties.Set("extra.time.zone", strconv.Itoa(timeutils.TimezoneOffsetNoDST(now))) - buildProperties.Set("extra.time.dst", strconv.Itoa(timeutils.DaylightSavingsOffset(now))) - buildProperties.Merge(ctx.PackageManager.GetCustomGlobalProperties()) keychainProp := buildProperties.ContainsKey("build.keys.keychain") From 64bb23e849757f0e1dd241133ec731e1f599dfbc Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 15:46:48 +0100 Subject: [PATCH 05/12] Made the referenced-core determination a bit more readable Equivalent change, should not change behaviour --- .../cores/packagemanager/package_manager.go | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 11241ce7741..007c892e2c0 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -299,30 +299,39 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( // Determine the platform used for the build (in case the board refers // to a core contained in another platform) - buildPlatformRelease := platformRelease - coreParts := strings.Split(buildProperties.Get("build.core"), ":") - if len(coreParts) > 1 { - referredPackage := coreParts[0] - buildPackage := pme.packages[referredPackage] - if buildPackage == nil { + core := buildProperties.Get("build.core") + referredCore := "" + if split := strings.Split(core, ":"); len(split) > 1 { + core, referredCore = split[1], split[0] + } + + var referredPlatformRelease *cores.PlatformRelease + referredPackageName := referredCore + if referredPackageName != "" { + referredPackage := pme.packages[referredPackageName] + if referredPackage == nil { return targetPackage, platformRelease, board, buildProperties, nil, - fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackage, fqbn) + fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackageName, fqbn) } - buildPlatform := buildPackage.Platforms[fqbn.PlatformArch] - if buildPlatform == nil { + referredPlatform := referredPackage.Platforms[fqbn.PlatformArch] + if referredPlatform == nil { return targetPackage, platformRelease, board, buildProperties, nil, - fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackage, fqbn.PlatformArch, fqbn) + fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) } - buildPlatformRelease = pme.GetInstalledPlatformRelease(buildPlatform) - if buildPlatformRelease == nil { + referredPlatformRelease = pme.GetInstalledPlatformRelease(referredPlatform) + if referredPlatformRelease == nil { return targetPackage, platformRelease, board, buildProperties, nil, - fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackage, fqbn.PlatformArch, fqbn) + fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) } } // Runtime build properties + buildPlatformRelease := platformRelease + if referredCore != "" { + buildPlatformRelease = referredPlatformRelease + } buildProperties.Merge(platformRelease.RuntimeProperties()) - buildProperties.SetPath("build.core.path", buildPlatformRelease.InstallDir.Join("cores", coreParts[0])) + buildProperties.SetPath("build.core.path", buildPlatformRelease.InstallDir.Join("cores", core)) buildProperties.SetPath("build.system.path", buildPlatformRelease.InstallDir.Join("system")) for _, tool := range pme.GetAllInstalledToolsReleases() { buildProperties.Merge(tool.RuntimeProperties()) From c8ff308bea2f58488e9443a543361468e06aa393 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 15:55:23 +0100 Subject: [PATCH 06/12] Factored 'build.variant' and related properties calculation --- .../cores/packagemanager/package_manager.go | 22 +++++++++++++++++++ legacy/builder/setup_build_properties.go | 20 ----------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 007c892e2c0..35a0e6458c1 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -304,9 +304,21 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( if split := strings.Split(core, ":"); len(split) > 1 { core, referredCore = split[1], split[0] } + variant := buildProperties.Get("build.variant") + referredVariant := "" + if split := strings.Split(variant, ":"); len(split) > 1 { + variant, referredVariant = split[1], split[0] + } + if referredCore != "" && referredVariant != "" && referredCore != referredVariant { + return targetPackage, platformRelease, board, buildProperties, nil, + fmt.Errorf(tr("'build.core' and 'build.variant' refer to different platforms: %[1]s and %[2]s"), core+":"+referredCore, variant+":"+referredVariant) + } var referredPlatformRelease *cores.PlatformRelease referredPackageName := referredCore + if referredPackageName == "" { + referredPackageName = referredVariant + } if referredPackageName != "" { referredPackage := pme.packages[referredPackageName] if referredPackage == nil { @@ -336,6 +348,16 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( for _, tool := range pme.GetAllInstalledToolsReleases() { buildProperties.Merge(tool.RuntimeProperties()) } + + buildProperties.Set("build.variant.path", "") + if variant != "" { + variantPlatformRelease := platformRelease + if referredVariant != "" { + variantPlatformRelease = referredPlatformRelease + } + buildProperties.SetPath("build.variant.path", variantPlatformRelease.InstallDir.Join("variants", variant)) + } + requiredTools, err := pme.FindToolsRequiredForBuild(platformRelease, buildPlatformRelease) if err != nil { return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, err diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index ca7a7e06631..7de8dfd84c3 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -18,9 +18,7 @@ package builder import ( "os" "path/filepath" - "strings" - "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/legacy/builder/types" properties "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" @@ -29,8 +27,6 @@ import ( type SetupBuildProperties struct{} func (s *SetupBuildProperties) Run(ctx *types.Context) error { - packages := ctx.Hardware - targetPlatform := ctx.TargetPlatform actualPlatform := ctx.ActualPlatform @@ -71,22 +67,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { } ctx.OptimizationFlags = buildProperties.Get("compiler.optimization_flags") - variant := buildProperties.Get("build.variant") - if variant == "" { - buildProperties.Set("build.variant.path", "") - } else { - var variantPlatformRelease *cores.PlatformRelease - variantParts := strings.Split(variant, ":") - if len(variantParts) > 1 { - variantPlatform := packages[variantParts[0]].Platforms[targetPlatform.Platform.Architecture] - variantPlatformRelease = ctx.PackageManager.GetInstalledPlatformRelease(variantPlatform) - variant = variantParts[1] - } else { - variantPlatformRelease = targetPlatform - } - buildProperties.SetPath("build.variant.path", variantPlatformRelease.InstallDir.Join("variants", variant)) - } - if !buildProperties.ContainsKey("software") { buildProperties.Set("software", DEFAULT_SOFTWARE) } From f57c3ae2ec9fd82f212905b13eba2cb5b555da3e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 16:01:40 +0100 Subject: [PATCH 07/12] Removed useless state variable 'BuildCore' --- legacy/builder/setup_build_properties.go | 1 - legacy/builder/target_board_resolver.go | 14 ++++++-------- legacy/builder/test/target_board_resolver_test.go | 2 +- legacy/builder/types/context.go | 1 - 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index 7de8dfd84c3..73caf34d355 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -49,7 +49,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { exPath = filepath.Dir(ex) } - buildProperties.Set("build.core", ctx.BuildCore) buildProperties.Set("runtime.ide.version", ctx.ArduinoAPIVersion) buildProperties.Set("runtime.ide.path", exPath) buildProperties.Set("ide_version", ctx.ArduinoAPIVersion) diff --git a/legacy/builder/target_board_resolver.go b/legacy/builder/target_board_resolver.go index 59d1361b557..c8d4f4a4b96 100644 --- a/legacy/builder/target_board_resolver.go +++ b/legacy/builder/target_board_resolver.go @@ -30,14 +30,13 @@ func (s *TargetBoardResolver) Run(ctx *types.Context) error { return fmt.Errorf("%s: %w", tr("Error resolving FQBN"), err) } - core := buildProperties.Get("build.core") - if core == "" { - core = "arduino" - } - // select the core name in case of "package:core" format - core = core[strings.Index(core, ":")+1:] - if ctx.Verbose { + core := buildProperties.Get("build.core") + if core == "" { + core = "arduino" + } + // select the core name in case of "package:core" format + core = core[strings.Index(core, ":")+1:] ctx.Info(tr("Using board '%[1]s' from platform in folder: %[2]s", targetBoard.BoardID, targetPlatform.InstallDir)) ctx.Info(tr("Using core '%[1]s' from platform in folder: %[2]s", core, buildPlatform.InstallDir)) } @@ -55,7 +54,6 @@ func (s *TargetBoardResolver) Run(ctx *types.Context) error { return err } - ctx.BuildCore = core ctx.TargetBoard = targetBoard ctx.TargetBoardBuildProperties = buildProperties ctx.TargetPlatform = targetPlatform diff --git a/legacy/builder/test/target_board_resolver_test.go b/legacy/builder/test/target_board_resolver_test.go index db344a38448..2ce650f081d 100644 --- a/legacy/builder/test/target_board_resolver_test.go +++ b/legacy/builder/test/target_board_resolver_test.go @@ -180,7 +180,7 @@ func TestTargetBoardResolverCustomCore(t *testing.T) { require.Equal(t, "avr", targetPlatform.Platform.Architecture) targetBoard := ctx.TargetBoard require.Equal(t, "attiny841", targetBoard.BoardID) - require.Equal(t, "tiny841", ctx.BuildCore) + require.Equal(t, "tiny841", ctx.TargetBoardBuildProperties.Get("build.core")) targetBoardBuildProperties := ctx.TargetBoardBuildProperties require.Equal(t, "tiny14", targetBoardBuildProperties.Get("build.variant")) } diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go index 3286416fbb8..1ef5de77984 100644 --- a/legacy/builder/types/context.go +++ b/legacy/builder/types/context.go @@ -95,7 +95,6 @@ type Context struct { HardwareRewriteResults map[*cores.PlatformRelease][]PlatforKeyRewrite BuildProperties *properties.Map - BuildCore string BuildPath *paths.Path SketchBuildPath *paths.Path CoreBuildPath *paths.Path From 1fc8e9af00d1950bf07a30084c1ff0c4ccf6443f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 16:37:28 +0100 Subject: [PATCH 08/12] Refactoring of some legacy properties generation subroutines --- .../cores/packagemanager/package_manager.go | 15 +++++++ commands/compile/compile.go | 3 -- legacy/builder/setup_build_properties.go | 16 -------- legacy/builder/test/builder_test.go | 1 - .../test/create_build_options_map_test.go | 2 - legacy/builder/test/ctags_runner_test.go | 5 --- .../test/includes_to_include_folders_test.go | 8 ---- .../load_vid_pid_specific_properties_test.go | 18 ++++----- .../test/merge_sketch_with_bootloader_test.go | 4 -- legacy/builder/test/prototypes_adder_test.go | 21 ---------- .../test/setup_build_properties_test.go | 40 +++++++++---------- .../test/store_build_options_map_test.go | 2 - .../try_build_of_problematic_sketch_test.go | 1 - legacy/builder/types/context.go | 2 - legacy/builder/types/context_test.go | 2 - 15 files changed, 41 insertions(+), 99 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 35a0e6458c1..ca5b3dd4af9 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -18,7 +18,9 @@ package packagemanager import ( "fmt" "net/url" + "os" "path" + "path/filepath" "strconv" "strings" "sync" @@ -371,6 +373,19 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( buildProperties.Set("extra.time.zone", strconv.Itoa(timeutils.TimezoneOffsetNoDST(now))) buildProperties.Set("extra.time.dst", strconv.Itoa(timeutils.DaylightSavingsOffset(now))) + if !buildProperties.ContainsKey("runtime.ide.path") { + if ex, err := os.Executable(); err == nil { + buildProperties.Set("runtime.ide.path", filepath.Dir(ex)) + } else { + buildProperties.Set("runtime.ide.path", "") + } + } + buildProperties.Set("runtime.os", properties.GetOSSuffix()) + buildProperties.Set("build.library_discovery_phase", "0") + // Deprecated properties + buildProperties.Set("ide_version", "10607") + buildProperties.Set("runtime.ide.version", "10607") + // No errors... phew! return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 664368e067c..55b90fc9004 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -174,9 +174,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings) - // Will be deprecated. - builderCtx.ArduinoAPIVersion = "10607" - builderCtx.Stdout = outStream builderCtx.Stderr = errStream builderCtx.Clean = req.GetClean() diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index 73caf34d355..d14b6f2c3ab 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -16,9 +16,6 @@ package builder import ( - "os" - "path/filepath" - "github.com/arduino/arduino-cli/legacy/builder/types" properties "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" @@ -42,19 +39,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties.Set("build.project_name", ctx.Sketch.MainFile.Base()) } - // get base folder and use it to populate BUILD_PROPERTIES_RUNTIME_IDE_PATH (arduino and arduino-builder live in the same dir) - ex, err := os.Executable() - exPath := "" - if err == nil { - exPath = filepath.Dir(ex) - } - - buildProperties.Set("runtime.ide.version", ctx.ArduinoAPIVersion) - buildProperties.Set("runtime.ide.path", exPath) - buildProperties.Set("ide_version", ctx.ArduinoAPIVersion) - buildProperties.Set("runtime.os", properties.GetOSSuffix()) - buildProperties.Set("build.library_discovery_phase", "0") - if ctx.OptimizeForDebug { if buildProperties.ContainsKey("compiler.optimization_flags.debug") { buildProperties.Set("compiler.optimization_flags", buildProperties.Get("compiler.optimization_flags.debug")) diff --git a/legacy/builder/test/builder_test.go b/legacy/builder/test/builder_test.go index 16887bfc679..79da75775c0 100644 --- a/legacy/builder/test/builder_test.go +++ b/legacy/builder/test/builder_test.go @@ -41,7 +41,6 @@ func prepareBuilderTestContext(t *testing.T, sketchPath *paths.Path, fqbn string BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), BuiltInLibrariesDirs: paths.New("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), - ArduinoAPIVersion: "10600", Verbose: false, } } diff --git a/legacy/builder/test/create_build_options_map_test.go b/legacy/builder/test/create_build_options_map_test.go index e3ba6ca71d6..ea62780ebe1 100644 --- a/legacy/builder/test/create_build_options_map_test.go +++ b/legacy/builder/test/create_build_options_map_test.go @@ -32,7 +32,6 @@ func TestCreateBuildOptionsMap(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: &sketch.Sketch{FullPath: paths.New("sketchLocation")}, FQBN: parseFQBN(t, "my:nice:fqbn"), - ArduinoAPIVersion: "ideVersion", Verbose: true, BuildPath: paths.New("buildPath"), OptimizationFlags: "-Os", @@ -50,7 +49,6 @@ func TestCreateBuildOptionsMap(t *testing.T) { "fqbn": "my:nice:fqbn", "hardwareFolders": "hardware,hardware2", "otherLibrariesFolders": "libraries", - "runtime.ide.version": "ideVersion", "sketchLocation": "sketchLocation" }`, ctx.BuildOptionsJson) } diff --git a/legacy/builder/test/ctags_runner_test.go b/legacy/builder/test/ctags_runner_test.go index 77d52f5c916..08b477e2911 100644 --- a/legacy/builder/test/ctags_runner_test.go +++ b/legacy/builder/test/ctags_runner_test.go @@ -38,7 +38,6 @@ func TestCTagsRunner(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -88,7 +87,6 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -136,7 +134,6 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -183,7 +180,6 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -229,7 +225,6 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } diff --git a/legacy/builder/test/includes_to_include_folders_test.go b/legacy/builder/test/includes_to_include_folders_test.go index 0e8a513b740..e7deabaddb1 100644 --- a/legacy/builder/test/includes_to_include_folders_test.go +++ b/legacy/builder/test/includes_to_include_folders_test.go @@ -36,7 +36,6 @@ func TestIncludesToIncludeFolders(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -72,7 +71,6 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("SketchWithIfDef", "SketchWithIfDef.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -107,7 +105,6 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch9", "sketch9.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -145,7 +142,6 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch10", "sketch10.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -179,7 +175,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { BuiltInLibrariesDirs: paths.New("downloaded_libraries"), Sketch: OpenSketch(t, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino")), FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -217,7 +212,6 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino")), FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -255,7 +249,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch_usbhost", "sketch_usbhost.ino")), FQBN: parseFQBN(t, "arduino:samd:arduino_zero_native"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -293,7 +286,6 @@ func TestIncludesToIncludeFoldersSubfolders(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } diff --git a/legacy/builder/test/load_vid_pid_specific_properties_test.go b/legacy/builder/test/load_vid_pid_specific_properties_test.go index b80f16b3d44..0152310605a 100644 --- a/legacy/builder/test/load_vid_pid_specific_properties_test.go +++ b/legacy/builder/test/load_vid_pid_specific_properties_test.go @@ -29,11 +29,10 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"), - Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), - FQBN: parseFQBN(t, "arduino:avr:micro"), - ArduinoAPIVersion: "10600", + HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), + BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"), + Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), + FQBN: parseFQBN(t, "arduino:avr:micro"), } buildPath := SetupBuildPath(t, ctx) @@ -59,11 +58,10 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"), - Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), - FQBN: parseFQBN(t, "arduino:avr:micro"), - ArduinoAPIVersion: "10600", + HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), + BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"), + Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), + FQBN: parseFQBN(t, "arduino:avr:micro"), } buildPath := SetupBuildPath(t, ctx) diff --git a/legacy/builder/test/merge_sketch_with_bootloader_test.go b/legacy/builder/test/merge_sketch_with_bootloader_test.go index fcce8942ad0..47c1b4d545c 100644 --- a/legacy/builder/test/merge_sketch_with_bootloader_test.go +++ b/legacy/builder/test/merge_sketch_with_bootloader_test.go @@ -38,7 +38,6 @@ func TestMergeSketchWithBootloader(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", } buildPath := SetupBuildPath(t, ctx) @@ -108,7 +107,6 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", } buildPath := SetupBuildPath(t, ctx) @@ -179,7 +177,6 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", } buildPath := SetupBuildPath(t, ctx) @@ -217,7 +214,6 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), FQBN: parseFQBN(t, "my_avr_platform:avr:mymega:cpu=atmega2560"), - ArduinoAPIVersion: "10600", } buildPath := SetupBuildPath(t, ctx) diff --git a/legacy/builder/test/prototypes_adder_test.go b/legacy/builder/test/prototypes_adder_test.go index 871536def19..159beb3923e 100644 --- a/legacy/builder/test/prototypes_adder_test.go +++ b/legacy/builder/test/prototypes_adder_test.go @@ -41,7 +41,6 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -81,7 +80,6 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("SketchWithIfDef", "SketchWithIfDef.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -121,7 +119,6 @@ func TestPrototypesAdderBaladuino(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("Baladuino", "Baladuino.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -161,7 +158,6 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -201,7 +197,6 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino")), FQBN: parseFQBN(t, "arduino:sam:arduino_due_x_dbg"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -241,7 +236,6 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("LineContinuations", "LineContinuations.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -281,7 +275,6 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("StringWithComment", "StringWithComment.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -321,7 +314,6 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("SketchWithStruct", "SketchWithStruct.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -369,7 +361,6 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -415,7 +406,6 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -455,7 +445,6 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("sketch_no_functions", "sketch_no_functions.ino")), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -501,7 +490,6 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -544,7 +532,6 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -598,7 +585,6 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -641,7 +627,6 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { BuiltInLibrariesDirs: paths.New("downloaded_libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -683,7 +668,6 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -732,7 +716,6 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:yun"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -778,7 +761,6 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:sam:arduino_due_x_dbg"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -824,7 +806,6 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -864,7 +845,6 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, paths.New("eol_processing", "eol_processing.ino")), FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", Verbose: true, } @@ -904,7 +884,6 @@ func TestPrototypesAdderSketchWithSubstringFunctionMember(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: OpenSketch(t, sketchLocation), FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", Verbose: true, } diff --git a/legacy/builder/test/setup_build_properties_test.go b/legacy/builder/test/setup_build_properties_test.go index 815d78c0398..f59847d81ff 100644 --- a/legacy/builder/test/setup_build_properties_test.go +++ b/legacy/builder/test/setup_build_properties_test.go @@ -29,11 +29,10 @@ func TestSetupBuildProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), - FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", + HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), + BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), + Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), + FQBN: parseFQBN(t, "arduino:avr:uno"), } buildPath := SetupBuildPath(t, ctx) @@ -63,7 +62,7 @@ func TestSetupBuildProperties(t *testing.T) { requireEquivalentPaths(t, buildProperties.Get("runtime.platform.path"), "downloaded_hardware/arduino/avr") requireEquivalentPaths(t, buildProperties.Get("runtime.hardware.path"), "downloaded_hardware/arduino") - require.Equal(t, "10600", buildProperties.Get("runtime.ide.version")) + require.Equal(t, "10607", buildProperties.Get("runtime.ide.version")) require.NotEmpty(t, buildProperties.Get("runtime.os")) requireEquivalentPaths(t, buildProperties.Get("runtime.tools.arm-none-eabi-gcc.path"), "downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1") @@ -93,11 +92,10 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), - FQBN: parseFQBN(t, "arduino:avr:uno"), - ArduinoAPIVersion: "10600", + HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), + BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), + Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), + FQBN: parseFQBN(t, "arduino:avr:uno"), CustomBuildProperties: []string{"name=fake name", "tools.avrdude.config.path=non existent path with space and a ="}, } @@ -132,11 +130,10 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), - FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), - ArduinoAPIVersion: "10600", + HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), + BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), + Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), + FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), } buildPath := SetupBuildPath(t, ctx) @@ -168,11 +165,10 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi DownloadCoresAndToolsAndLibraries(t) ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), - Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), - FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), - ArduinoAPIVersion: "10600", + HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), + BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"), + Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")), + FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"), } buildPath := SetupBuildPath(t, ctx) @@ -199,7 +195,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi requireEquivalentPaths(t, buildProperties.Get("runtime.platform.path"), "user_hardware/my_avr_platform/avr") requireEquivalentPaths(t, buildProperties.Get("runtime.hardware.path"), "user_hardware/my_avr_platform") - require.Equal(t, "10600", buildProperties.Get("runtime.ide.version")) + require.Equal(t, "10607", buildProperties.Get("runtime.ide.version")) require.NotEmpty(t, buildProperties.Get("runtime.os")) requireEquivalentPaths(t, buildProperties.Get("runtime.tools.arm-none-eabi-gcc.path"), "downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1") diff --git a/legacy/builder/test/store_build_options_map_test.go b/legacy/builder/test/store_build_options_map_test.go index 24f757708a0..aeee52e5154 100644 --- a/legacy/builder/test/store_build_options_map_test.go +++ b/legacy/builder/test/store_build_options_map_test.go @@ -34,7 +34,6 @@ func TestStoreBuildOptionsMap(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("libraries"), Sketch: &sketch.Sketch{FullPath: paths.New("sketchLocation")}, FQBN: parseFQBN(t, "my:nice:fqbn"), - ArduinoAPIVersion: "ideVersion", CustomBuildProperties: []string{"custom=prop"}, Verbose: true, OptimizationFlags: "-Os", @@ -69,7 +68,6 @@ func TestStoreBuildOptionsMap(t *testing.T) { "fqbn": "my:nice:fqbn", "hardwareFolders": "hardware", "otherLibrariesFolders": "libraries", - "runtime.ide.version": "ideVersion", "sketchLocation": "sketchLocation" }`, string(bytes)) } diff --git a/legacy/builder/test/try_build_of_problematic_sketch_test.go b/legacy/builder/test/try_build_of_problematic_sketch_test.go index 3227d3fa381..c8b61a3db74 100644 --- a/legacy/builder/test/try_build_of_problematic_sketch_test.go +++ b/legacy/builder/test/try_build_of_problematic_sketch_test.go @@ -213,7 +213,6 @@ func makeDefaultContext(t *testing.T) *types.Context { BuiltInLibrariesDirs: paths.New("downloaded_libraries"), OtherLibrariesDirs: paths.NewPathList("libraries"), FQBN: parseFQBN(t, "arduino:avr:leonardo"), - ArduinoAPIVersion: "10607", Verbose: true, DebugPreprocessor: true, } diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go index 1ef5de77984..569d53e4d29 100644 --- a/legacy/builder/types/context.go +++ b/legacy/builder/types/context.go @@ -71,7 +71,6 @@ type Context struct { OtherLibrariesDirs paths.PathList LibraryDirs paths.PathList // List of paths pointing to individual library root folders WatchedLocations paths.PathList - ArduinoAPIVersion string FQBN *cores.FQBN CodeCompleteAt string Clean bool @@ -219,7 +218,6 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map { additionalFilesRelative = append(additionalFilesRelative, relPath.String()) } opts.Set("fqbn", ctx.FQBN.String()) - opts.Set("runtime.ide.version", ctx.ArduinoAPIVersion) opts.Set("customBuildProperties", strings.Join(ctx.CustomBuildProperties, ",")) opts.Set("additionalFiles", strings.Join(additionalFilesRelative, ",")) opts.Set("compiler.optimization_flags", ctx.OptimizationFlags) diff --git a/legacy/builder/types/context_test.go b/legacy/builder/types/context_test.go index 55af78c506c..33339cbb9e1 100644 --- a/legacy/builder/types/context_test.go +++ b/legacy/builder/types/context_test.go @@ -36,7 +36,6 @@ func TestInjectBuildOption(t *testing.T) { OtherLibrariesDirs: paths.NewPathList("fff", "ggg"), Sketch: &sketch.Sketch{FullPath: paths.New("hhh")}, FQBN: fqbn, - ArduinoAPIVersion: "iii", CustomBuildProperties: []string{"jjj", "kkk"}, OptimizationFlags: "lll", } @@ -48,7 +47,6 @@ func TestInjectBuildOption(t *testing.T) { "otherLibrariesFolders": "fff,ggg", "sketchLocation": "hhh", "fqbn": "aaa:bbb:ccc", - "runtime.ide.version": "iii", "customBuildProperties": "jjj,kkk", "additionalFiles": "", "compiler.optimization_flags": "lll", From ca7cd4cba174adbb508a04628ae011b6e302c86e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 16:38:48 +0100 Subject: [PATCH 09/12] Refactored generation of 'software' build property --- arduino/cores/packagemanager/package_manager.go | 3 +++ legacy/builder/builder.go | 1 - legacy/builder/setup_build_properties.go | 4 ---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index ca5b3dd4af9..8fd6a58165e 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -385,6 +385,9 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( // Deprecated properties buildProperties.Set("ide_version", "10607") buildProperties.Set("runtime.ide.version", "10607") + if !buildProperties.ContainsKey("software") { + buildProperties.Set("software", "ARDUINO") + } // No errors... phew! return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index 68ed660639e..75876ba4bb7 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -31,7 +31,6 @@ var tr = i18n.Tr const DEFAULT_DEBUG_LEVEL = 5 const DEFAULT_WARNINGS_LEVEL = "none" -const DEFAULT_SOFTWARE = "ARDUINO" type Builder struct{} diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index d14b6f2c3ab..49d61d2d632 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -50,10 +50,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { } ctx.OptimizationFlags = buildProperties.Get("compiler.optimization_flags") - if !buildProperties.ContainsKey("software") { - buildProperties.Set("software", DEFAULT_SOFTWARE) - } - buildProperties.SetPath("build.source.path", ctx.Sketch.FullPath) buildProperties.Merge(ctx.PackageManager.GetCustomGlobalProperties()) From 24c996e87f1c01c037c29b41cc3578b0dc0050ed Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 17:34:00 +0100 Subject: [PATCH 10/12] Refactored build properties overlaying logic --- .../cores/packagemanager/package_manager.go | 25 ++++++++++++------- .../packagemanager/package_manager_test.go | 4 +-- legacy/builder/setup_build_properties.go | 7 +----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 8fd6a58165e..f32d817d9c8 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -293,7 +293,7 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( fmt.Errorf(tr("board %s not found"), fqbn.StringWithoutConfig()) } - buildProperties, err := board.GetBuildProperties(fqbn.Configs) + boardBuildProperties, err := board.GetBuildProperties(fqbn.Configs) if err != nil { return targetPackage, platformRelease, board, nil, nil, fmt.Errorf(tr("getting build properties for board %[1]s: %[2]s"), board, err) @@ -301,18 +301,18 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( // Determine the platform used for the build (in case the board refers // to a core contained in another platform) - core := buildProperties.Get("build.core") + core := boardBuildProperties.Get("build.core") referredCore := "" if split := strings.Split(core, ":"); len(split) > 1 { core, referredCore = split[1], split[0] } - variant := buildProperties.Get("build.variant") + variant := boardBuildProperties.Get("build.variant") referredVariant := "" if split := strings.Split(variant, ":"); len(split) > 1 { variant, referredVariant = split[1], split[0] } if referredCore != "" && referredVariant != "" && referredCore != referredVariant { - return targetPackage, platformRelease, board, buildProperties, nil, + return targetPackage, platformRelease, board, nil, nil, fmt.Errorf(tr("'build.core' and 'build.variant' refer to different platforms: %[1]s and %[2]s"), core+":"+referredCore, variant+":"+referredVariant) } @@ -324,26 +324,34 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( if referredPackageName != "" { referredPackage := pme.packages[referredPackageName] if referredPackage == nil { - return targetPackage, platformRelease, board, buildProperties, nil, + return targetPackage, platformRelease, board, nil, nil, fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackageName, fqbn) } referredPlatform := referredPackage.Platforms[fqbn.PlatformArch] if referredPlatform == nil { - return targetPackage, platformRelease, board, buildProperties, nil, + return targetPackage, platformRelease, board, nil, nil, fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) } referredPlatformRelease = pme.GetInstalledPlatformRelease(referredPlatform) if referredPlatformRelease == nil { - return targetPackage, platformRelease, board, buildProperties, nil, + return targetPackage, platformRelease, board, nil, nil, fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) } } - // Runtime build properties + // Create the build properties map by overlaying the properties of the + // referenced platform propeties, the board platform properties and the + // board specific properties. + buildProperties := properties.NewMap() buildPlatformRelease := platformRelease if referredCore != "" { buildPlatformRelease = referredPlatformRelease } + buildProperties.Merge(buildPlatformRelease.Properties) + buildProperties.Merge(platformRelease.Properties) + buildProperties.Merge(boardBuildProperties) + + // Add runtime build properties buildProperties.Merge(platformRelease.RuntimeProperties()) buildProperties.SetPath("build.core.path", buildPlatformRelease.InstallDir.Join("cores", core)) buildProperties.SetPath("build.system.path", buildPlatformRelease.InstallDir.Join("system")) @@ -389,7 +397,6 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( buildProperties.Set("software", "ARDUINO") } - // No errors... phew! return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil } diff --git a/arduino/cores/packagemanager/package_manager_test.go b/arduino/cores/packagemanager/package_manager_test.go index ef94087c6fc..32dc4d3a23c 100644 --- a/arduino/cores/packagemanager/package_manager_test.go +++ b/arduino/cores/packagemanager/package_manager_test.go @@ -141,7 +141,7 @@ func TestResolveFQBN(t *testing.T) { require.Equal(t, platformRelease.Platform.String(), "referenced:avr") require.NotNil(t, board) require.Equal(t, board.Name(), "Referenced dummy with invalid package") - require.NotNil(t, props) + require.Nil(t, props) require.Nil(t, buildPlatformRelease) // Test a board referenced from a non-existent platform/architecture @@ -156,7 +156,7 @@ func TestResolveFQBN(t *testing.T) { require.Equal(t, platformRelease.Platform.String(), "referenced:avr") require.NotNil(t, board) require.Equal(t, board.Name(), "Referenced dummy with invalid platform") - require.NotNil(t, props) + require.Nil(t, props) require.Nil(t, buildPlatformRelease) // Test a board referenced from a non-existent core diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index 49d61d2d632..7c117e2d335 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -24,12 +24,7 @@ import ( type SetupBuildProperties struct{} func (s *SetupBuildProperties) Run(ctx *types.Context) error { - targetPlatform := ctx.TargetPlatform - actualPlatform := ctx.ActualPlatform - buildProperties := properties.NewMap() - buildProperties.Merge(actualPlatform.Properties) - buildProperties.Merge(targetPlatform.Properties) buildProperties.Merge(ctx.TargetBoardBuildProperties) if ctx.BuildPath != nil { @@ -59,7 +54,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { encryptProp := buildProperties.ContainsKey("build.keys.encrypt_key") // we verify that all the properties for the secure boot keys are defined or none of them is defined. if (keychainProp || signProp || encryptProp) && !(keychainProp && signProp && encryptProp) { - return errors.Errorf("%s platform does not specify correctly default sign and encryption keys", targetPlatform.Platform) + return errors.Errorf("%s platform does not specify correctly default sign and encryption keys", ctx.TargetPlatform.Platform) } ctx.BuildProperties = buildProperties From 271718f566bd1e92bcf2556eaf5f83e9d0810383 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 21 Feb 2023 17:34:29 +0100 Subject: [PATCH 11/12] Refactored custom global properties handling --- arduino/cores/packagemanager/package_manager.go | 2 ++ legacy/builder/setup_build_properties.go | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index f32d817d9c8..5091443b80e 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -397,6 +397,8 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( buildProperties.Set("software", "ARDUINO") } + buildProperties.Merge(pme.GetCustomGlobalProperties()) + return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil } diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index 7c117e2d335..5b191dd8dff 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -47,8 +47,6 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties.SetPath("build.source.path", ctx.Sketch.FullPath) - buildProperties.Merge(ctx.PackageManager.GetCustomGlobalProperties()) - keychainProp := buildProperties.ContainsKey("build.keys.keychain") signProp := buildProperties.ContainsKey("build.keys.sign_key") encryptProp := buildProperties.ContainsKey("build.keys.encrypt_key") From 6ad5342f4ec04597668b6fc682c4c3c5cade81e0 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 27 Feb 2023 18:34:20 +0100 Subject: [PATCH 12/12] Moved corePlatform and variantPlatform determination inside a specific method --- .../cores/packagemanager/package_manager.go | 139 ++++++++++-------- 1 file changed, 77 insertions(+), 62 deletions(-) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 5091443b80e..df7dafb7842 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -280,97 +280,56 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( return targetPackage, nil, nil, nil, nil, fmt.Errorf(tr("unknown platform %s:%s"), targetPackage, fqbn.PlatformArch) } - platformRelease := pme.GetInstalledPlatformRelease(platform) - if platformRelease == nil { + boardPlatformRelease := pme.GetInstalledPlatformRelease(platform) + if boardPlatformRelease == nil { return targetPackage, nil, nil, nil, nil, fmt.Errorf(tr("platform %s is not installed"), platform) } // Find board - board := platformRelease.Boards[fqbn.BoardID] + board := boardPlatformRelease.Boards[fqbn.BoardID] if board == nil { - return targetPackage, platformRelease, nil, nil, nil, + return targetPackage, boardPlatformRelease, nil, nil, nil, fmt.Errorf(tr("board %s not found"), fqbn.StringWithoutConfig()) } boardBuildProperties, err := board.GetBuildProperties(fqbn.Configs) if err != nil { - return targetPackage, platformRelease, board, nil, nil, + return targetPackage, boardPlatformRelease, board, nil, nil, fmt.Errorf(tr("getting build properties for board %[1]s: %[2]s"), board, err) } - // Determine the platform used for the build (in case the board refers + // Determine the platform used for the build and the variant (in case the board refers // to a core contained in another platform) - core := boardBuildProperties.Get("build.core") - referredCore := "" - if split := strings.Split(core, ":"); len(split) > 1 { - core, referredCore = split[1], split[0] - } - variant := boardBuildProperties.Get("build.variant") - referredVariant := "" - if split := strings.Split(variant, ":"); len(split) > 1 { - variant, referredVariant = split[1], split[0] - } - if referredCore != "" && referredVariant != "" && referredCore != referredVariant { - return targetPackage, platformRelease, board, nil, nil, - fmt.Errorf(tr("'build.core' and 'build.variant' refer to different platforms: %[1]s and %[2]s"), core+":"+referredCore, variant+":"+referredVariant) - } - - var referredPlatformRelease *cores.PlatformRelease - referredPackageName := referredCore - if referredPackageName == "" { - referredPackageName = referredVariant - } - if referredPackageName != "" { - referredPackage := pme.packages[referredPackageName] - if referredPackage == nil { - return targetPackage, platformRelease, board, nil, nil, - fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackageName, fqbn) - } - referredPlatform := referredPackage.Platforms[fqbn.PlatformArch] - if referredPlatform == nil { - return targetPackage, platformRelease, board, nil, nil, - fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) - } - referredPlatformRelease = pme.GetInstalledPlatformRelease(referredPlatform) - if referredPlatformRelease == nil { - return targetPackage, platformRelease, board, nil, nil, - fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) - } + core, corePlatformRelease, variant, variantPlatformRelease, err := pme.determineReferencedPlatformRelease(boardBuildProperties, boardPlatformRelease, fqbn) + if err != nil { + return targetPackage, boardPlatformRelease, board, nil, nil, err } // Create the build properties map by overlaying the properties of the // referenced platform propeties, the board platform properties and the // board specific properties. buildProperties := properties.NewMap() - buildPlatformRelease := platformRelease - if referredCore != "" { - buildPlatformRelease = referredPlatformRelease - } - buildProperties.Merge(buildPlatformRelease.Properties) - buildProperties.Merge(platformRelease.Properties) + buildProperties.Merge(variantPlatformRelease.Properties) + buildProperties.Merge(corePlatformRelease.Properties) + buildProperties.Merge(boardPlatformRelease.Properties) buildProperties.Merge(boardBuildProperties) // Add runtime build properties - buildProperties.Merge(platformRelease.RuntimeProperties()) - buildProperties.SetPath("build.core.path", buildPlatformRelease.InstallDir.Join("cores", core)) - buildProperties.SetPath("build.system.path", buildPlatformRelease.InstallDir.Join("system")) - for _, tool := range pme.GetAllInstalledToolsReleases() { - buildProperties.Merge(tool.RuntimeProperties()) - } - + buildProperties.Merge(boardPlatformRelease.RuntimeProperties()) + buildProperties.SetPath("build.core.path", corePlatformRelease.InstallDir.Join("cores", core)) + buildProperties.SetPath("build.system.path", corePlatformRelease.InstallDir.Join("system")) buildProperties.Set("build.variant.path", "") if variant != "" { - variantPlatformRelease := platformRelease - if referredVariant != "" { - variantPlatformRelease = referredPlatformRelease - } buildProperties.SetPath("build.variant.path", variantPlatformRelease.InstallDir.Join("variants", variant)) } - requiredTools, err := pme.FindToolsRequiredForBuild(platformRelease, buildPlatformRelease) + for _, tool := range pme.GetAllInstalledToolsReleases() { + buildProperties.Merge(tool.RuntimeProperties()) + } + requiredTools, err := pme.FindToolsRequiredForBuild(boardPlatformRelease, corePlatformRelease) if err != nil { - return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, err + return targetPackage, boardPlatformRelease, board, buildProperties, corePlatformRelease, err } for _, tool := range requiredTools { buildProperties.Merge(tool.RuntimeProperties()) @@ -399,7 +358,63 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) ( buildProperties.Merge(pme.GetCustomGlobalProperties()) - return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil + return targetPackage, boardPlatformRelease, board, buildProperties, corePlatformRelease, nil +} + +func (pme *Explorer) determineReferencedPlatformRelease(boardBuildProperties *properties.Map, boardPlatformRelease *cores.PlatformRelease, fqbn *cores.FQBN) (string, *cores.PlatformRelease, string, *cores.PlatformRelease, error) { + core := boardBuildProperties.Get("build.core") + referredCore := "" + if split := strings.Split(core, ":"); len(split) > 1 { + referredCore, core = split[0], split[1] + } + + variant := boardBuildProperties.Get("build.variant") + referredVariant := "" + if split := strings.Split(variant, ":"); len(split) > 1 { + referredVariant, variant = split[0], split[1] + } + + // core and variant cannot refer to two different platforms + if referredCore != "" && referredVariant != "" && referredCore != referredVariant { + return "", nil, "", nil, + fmt.Errorf(tr("'build.core' and 'build.variant' refer to different platforms: %[1]s and %[2]s"), referredCore+":"+core, referredVariant+":"+variant) + } + + // extract the referred platform + var referredPlatformRelease *cores.PlatformRelease + referredPackageName := referredCore + if referredPackageName == "" { + referredPackageName = referredVariant + } + if referredPackageName != "" { + referredPackage := pme.packages[referredPackageName] + if referredPackage == nil { + return "", nil, "", nil, + fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackageName, fqbn) + } + referredPlatform := referredPackage.Platforms[fqbn.PlatformArch] + if referredPlatform == nil { + return "", nil, "", nil, + fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) + } + referredPlatformRelease = pme.GetInstalledPlatformRelease(referredPlatform) + if referredPlatformRelease == nil { + return "", nil, "", nil, + fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn) + } + } + + corePlatformRelease := boardPlatformRelease + if referredCore != "" { + corePlatformRelease = referredPlatformRelease + } + + variantPlatformRelease := boardPlatformRelease + if referredVariant != "" { + variantPlatformRelease = referredPlatformRelease + } + + return core, corePlatformRelease, variant, variantPlatformRelease, nil } // LoadPackageIndex loads a package index by looking up the local cached file from the specified URL