From 7a9f2c3b374b5ab2bbf18b5a267006022108d89b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 6 Sep 2023 16:54:00 +0200 Subject: [PATCH 1/5] Slightly de-entangled makeSourceFile --- arduino/builder/detector/detector.go | 68 ++++++++++++++++------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/arduino/builder/detector/detector.go b/arduino/builder/detector/detector.go index dc64b0319e5..5543236f18d 100644 --- a/arduino/builder/detector/detector.go +++ b/arduino/builder/detector/detector.go @@ -264,16 +264,16 @@ func (l *SketchLibrariesDetector) findIncludes( if !l.useCachedLibrariesResolution { sketch := sketch - mergedfile, err := makeSourceFile(sketchBuildPath, librariesBuildPath, sketch, paths.New(sketch.MainFile.Base()+".cpp")) + mergedfile, err := makeSourceFile(sketchBuildPath, sketchBuildPath, paths.New(sketch.MainFile.Base()+".cpp")) if err != nil { return errors.WithStack(err) } sourceFileQueue.push(mergedfile) - l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, sketch, sketchBuildPath, false /* recurse */) + l.queueSourceFilesFromFolder(sourceFileQueue, sketchBuildPath, false /* recurse */, sketchBuildPath, sketchBuildPath) srcSubfolderPath := sketchBuildPath.Join("src") if srcSubfolderPath.IsDir() { - l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, sketch, srcSubfolderPath, true /* recurse */) + l.queueSourceFilesFromFolder(sourceFileQueue, srcSubfolderPath, true /* recurse */, sketchBuildPath, sketchBuildPath) } for !sourceFileQueue.empty() { @@ -419,7 +419,8 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone( } } else { for _, sourceDir := range library.SourceDirs() { - l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, library, sourceDir.Dir, sourceDir.Recurse) + l.queueSourceFilesFromFolder(sourceFileQueue, sourceDir.Dir, sourceDir.Recurse, + library.SourceDir, librariesBuildPath.Join(library.DirName), library.UtilityDir) } } first = false @@ -427,12 +428,12 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone( } func (l *SketchLibrariesDetector) queueSourceFilesFromFolder( - sketchBuildPath *paths.Path, - librariesBuildPath *paths.Path, sourceFileQueue *uniqueSourceFileQueue, - origin interface{}, folder *paths.Path, recurse bool, + sourceDir *paths.Path, + buildDir *paths.Path, + extraIncludePath ...*paths.Path, ) error { sourceFileExtensions := []string{} for k := range globals.SourceFilesValidExtensions { @@ -444,7 +445,7 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder( } for _, filePath := range filePaths { - sourceFile, err := makeSourceFile(sketchBuildPath, librariesBuildPath, origin, filePath) + sourceFile, err := makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...) if err != nil { return errors.WithStack(err) } @@ -537,33 +538,42 @@ func (f *sourceFile) Equals(g *sourceFile) bool { // given origin. The given path can be absolute, or relative within the // origin's root source folder func makeSourceFile( - sketchBuildPath *paths.Path, - librariesBuildPath *paths.Path, - origin interface{}, - path *paths.Path, + sourceDir *paths.Path, + buildDir *paths.Path, + sourceFilePath *paths.Path, + extraIncludePath ...*paths.Path, ) (*sourceFile, error) { - res := &sourceFile{} - - switch o := origin.(type) { - case *sketch.Sketch: - res.buildRoot = sketchBuildPath - res.sourceRoot = sketchBuildPath - case *libraries.Library: - res.buildRoot = librariesBuildPath.Join(o.DirName) - res.sourceRoot = o.SourceDir - res.extraIncludePath = o.UtilityDir - default: - panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin)) - } - - if path.IsAbs() { + res := &sourceFile{ + buildRoot: buildDir, + sourceRoot: sourceDir, + } + + if len(extraIncludePath) > 1 { + panic("only one extra include path allowed") + } + if len(extraIncludePath) > 0 { + res.extraIncludePath = extraIncludePath[0] + } + // switch o := origin.(type) { + // case *sketch.Sketch: + // res.buildRoot = sketchBuildPath + // res.sourceRoot = sketchBuildPath + // case *libraries.Library: + // res.buildRoot = librariesBuildPath.Join(o.DirName) + // res.sourceRoot = o.SourceDir + // res.extraIncludePath = o.UtilityDir + // default: + // panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin)) + // } + + if sourceFilePath.IsAbs() { var err error - path, err = res.sourceRoot.RelTo(path) + sourceFilePath, err = res.sourceRoot.RelTo(sourceFilePath) if err != nil { return nil, err } } - res.relativePath = path + res.relativePath = sourceFilePath return res, nil } From 14c6d044c360207f46f9103b03efa3aedeb54ef5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 6 Sep 2023 16:56:31 +0200 Subject: [PATCH 2/5] Moved some initializations directly into NewBuilder --- arduino/builder/builder.go | 39 +++++++++++++++++++++++++++-- arduino/builder/sketch.go | 27 -------------------- arduino/builder/sketch_test.go | 6 ++--- commands/compile/compile.go | 19 +++++++------- legacy/builder/test/builder_test.go | 8 +++--- 5 files changed, 53 insertions(+), 46 deletions(-) diff --git a/arduino/builder/builder.go b/arduino/builder/builder.go index 70ea2ec4a07..79cfc824eda 100644 --- a/arduino/builder/builder.go +++ b/arduino/builder/builder.go @@ -18,6 +18,7 @@ package builder import ( "github.com/arduino/arduino-cli/arduino/sketch" "github.com/arduino/go-paths-helper" + "github.com/arduino/go-properties-orderedmap" ) // nolint @@ -33,16 +34,50 @@ const ( // Builder is a Sketch builder. type Builder struct { - sketch *sketch.Sketch + sketch *sketch.Sketch + buildProperties *properties.Map // core related coreBuildCachePath *paths.Path } // NewBuilder creates a sketch Builder. -func NewBuilder(sk *sketch.Sketch, coreBuildCachePath *paths.Path) *Builder { +func NewBuilder( + sk *sketch.Sketch, + boardBuildProperties *properties.Map, + buildPath *paths.Path, + optimizeForDebug bool, + coreBuildCachePath *paths.Path, +) *Builder { + buildProperties := properties.NewMap() + if boardBuildProperties != nil { + buildProperties.Merge(boardBuildProperties) + } + + if buildPath != nil { + buildProperties.SetPath("build.path", buildPath) + } + if sk != nil { + buildProperties.Set("build.project_name", sk.MainFile.Base()) + buildProperties.SetPath("build.source.path", sk.FullPath) + } + if optimizeForDebug { + if debugFlags, ok := buildProperties.GetOk("compiler.optimization_flags.debug"); ok { + buildProperties.Set("compiler.optimization_flags", debugFlags) + } + } else { + if releaseFlags, ok := buildProperties.GetOk("compiler.optimization_flags.release"); ok { + buildProperties.Set("compiler.optimization_flags", releaseFlags) + } + } + return &Builder{ sketch: sk, + buildProperties: buildProperties, coreBuildCachePath: coreBuildCachePath, } } + +func (b *Builder) GetBuildProperties() *properties.Map { + return b.buildProperties +} diff --git a/arduino/builder/sketch.go b/arduino/builder/sketch.go index 144164cf31b..43a5e635237 100644 --- a/arduino/builder/sketch.go +++ b/arduino/builder/sketch.go @@ -23,7 +23,6 @@ import ( "github.com/arduino/arduino-cli/arduino/builder/cpp" "github.com/arduino/arduino-cli/i18n" "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" ) @@ -166,29 +165,3 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error { // Source and destination are the same, don't write anything return nil } - -// SetupBuildProperties adds the build properties related to the sketch to the -// default board build properties map. -func (b *Builder) SetupBuildProperties(boardBuildProperties *properties.Map, buildPath *paths.Path, optimizeForDebug bool) *properties.Map { - buildProperties := properties.NewMap() - buildProperties.Merge(boardBuildProperties) - - if buildPath != nil { - buildProperties.SetPath("build.path", buildPath) - } - if b.sketch != nil { - buildProperties.Set("build.project_name", b.sketch.MainFile.Base()) - buildProperties.SetPath("build.source.path", b.sketch.FullPath) - } - if optimizeForDebug { - if debugFlags, ok := buildProperties.GetOk("compiler.optimization_flags.debug"); ok { - buildProperties.Set("compiler.optimization_flags", debugFlags) - } - } else { - if releaseFlags, ok := buildProperties.GetOk("compiler.optimization_flags.release"); ok { - buildProperties.Set("compiler.optimization_flags", releaseFlags) - } - } - - return buildProperties -} diff --git a/arduino/builder/sketch_test.go b/arduino/builder/sketch_test.go index d8c1df2c4c0..f00a4e68ea8 100644 --- a/arduino/builder/sketch_test.go +++ b/arduino/builder/sketch_test.go @@ -48,7 +48,7 @@ func TestMergeSketchSources(t *testing.T) { } mergedSources := strings.ReplaceAll(string(mergedBytes), "%s", pathToGoldenSource) - b := NewBuilder(sk, nil) + b := NewBuilder(sk, nil, nil, false, nil) offset, source, err := b.sketchMergeSources(nil) require.Nil(t, err) require.Equal(t, 2, offset) @@ -61,7 +61,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) { require.NotNil(t, sk) // ensure not to include Arduino.h when it's already there - b := NewBuilder(sk, nil) + b := NewBuilder(sk, nil, nil, false, nil) _, source, err := b.sketchMergeSources(nil) require.Nil(t, err) require.Equal(t, 1, strings.Count(source, "")) @@ -76,7 +76,7 @@ func TestCopyAdditionalFiles(t *testing.T) { sk1, err := sketch.New(paths.New("testdata", t.Name())) require.Nil(t, err) require.Equal(t, sk1.AdditionalFiles.Len(), 1) - b1 := NewBuilder(sk1, nil) + b1 := NewBuilder(sk1, nil, nil, false, nil) // copy the sketch over, create a fake main file we don't care about it // but we need it for `SketchLoad` to succeed later diff --git a/commands/compile/compile.go b/commands/compile/compile.go index aa81cbcbf75..a5f6c3542e8 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -98,7 +98,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream if err != nil { return nil, &arduino.InvalidFQBNError{Cause: err} } - targetPackage, targetPlatform, targetBoard, buildProperties, buildPlatform, err := pme.ResolveFQBN(fqbn) + targetPackage, targetPlatform, targetBoard, boardBuildProperties, buildPlatform, err := pme.ResolveFQBN(fqbn) if err != nil { if targetPlatform == nil { return nil, &arduino.PlatformNotFoundError{ @@ -115,21 +115,21 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream // Setup sign keys if requested if req.KeysKeychain != "" { - buildProperties.Set("build.keys.keychain", req.GetKeysKeychain()) + boardBuildProperties.Set("build.keys.keychain", req.GetKeysKeychain()) } if req.SignKey != "" { - buildProperties.Set("build.keys.sign_key", req.GetSignKey()) + boardBuildProperties.Set("build.keys.sign_key", req.GetSignKey()) } if req.EncryptKey != "" { - buildProperties.Set("build.keys.encrypt_key", req.GetEncryptKey()) + boardBuildProperties.Set("build.keys.encrypt_key", req.GetEncryptKey()) } // At the current time we do not have a way of knowing if a board supports the secure boot or not, // so, if the flags to override the default keys are used, we try override the corresponding platform property nonetheless. // It's not possible to use the default name for the keys since there could be more tools to sign and encrypt. // So it's mandatory to use all three flags to sign and encrypt the binary - keychainProp := buildProperties.ContainsKey("build.keys.keychain") - signProp := buildProperties.ContainsKey("build.keys.sign_key") - encryptProp := buildProperties.ContainsKey("build.keys.encrypt_key") + keychainProp := boardBuildProperties.ContainsKey("build.keys.keychain") + signProp := boardBuildProperties.ContainsKey("build.keys.sign_key") + encryptProp := boardBuildProperties.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 && signProp == encryptProp) { return nil, fmt.Errorf(tr("Firmware encryption/signing requires all the following properties to be defined: %s", "build.keys.keychain, build.keys.sign_key, build.keys.encrypt_key")) @@ -169,10 +169,9 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream coreBuildCachePath = buildCachePath.Join("core") } - sketchBuilder := bldr.NewBuilder(sk, coreBuildCachePath) + sketchBuilder := bldr.NewBuilder(sk, boardBuildProperties, buildPath, req.GetOptimizeForDebug(), coreBuildCachePath) - // Add build properites related to sketch data - buildProperties = sketchBuilder.SetupBuildProperties(buildProperties, buildPath, req.GetOptimizeForDebug()) + buildProperties := sketchBuilder.GetBuildProperties() // Add user provided custom build properties customBuildPropertiesArgs := append(req.GetBuildProperties(), "build.warn_data_percentage=75") diff --git a/legacy/builder/test/builder_test.go b/legacy/builder/test/builder_test.go index deafc113154..a9ba6865561 100644 --- a/legacy/builder/test/builder_test.go +++ b/legacy/builder/test/builder_test.go @@ -97,18 +97,18 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat ctx.Sketch = sk } - ctx.Builder = bldr.NewBuilder(ctx.Sketch, nil) + ctx.Builder = bldr.NewBuilder(ctx.Sketch, nil, nil, false, nil) if fqbn != "" { ctx.FQBN = parseFQBN(t, fqbn) - targetPackage, targetPlatform, targetBoard, buildProperties, buildPlatform, err := pme.ResolveFQBN(ctx.FQBN) + targetPackage, targetPlatform, targetBoard, boardBuildProperties, buildPlatform, err := pme.ResolveFQBN(ctx.FQBN) require.NoError(t, err) requiredTools, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform) require.NoError(t, err) - buildProperties = ctx.Builder.SetupBuildProperties(buildProperties, ctx.BuildPath, false /*OptimizeForDebug*/) + ctx.Builder = bldr.NewBuilder(ctx.Sketch, boardBuildProperties, ctx.BuildPath, false /*OptimizeForDebug*/, nil) ctx.PackageManager = pme ctx.TargetBoard = targetBoard - ctx.BuildProperties = buildProperties + ctx.BuildProperties = ctx.Builder.GetBuildProperties() ctx.TargetPlatform = targetPlatform ctx.TargetPackage = targetPackage ctx.ActualPlatform = buildPlatform From 69a0aaedb72f864c85ff3d1e531f0679d37cd351 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 8 Sep 2023 15:25:46 +0200 Subject: [PATCH 3/5] Pruned constants --- arduino/builder/builder.go | 11 ----------- arduino/builder/utils/utils.go | 14 +++++++------- legacy/builder/phases/linker.go | 9 ++++----- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/arduino/builder/builder.go b/arduino/builder/builder.go index 79cfc824eda..0d2ea79fb3b 100644 --- a/arduino/builder/builder.go +++ b/arduino/builder/builder.go @@ -21,17 +21,6 @@ import ( "github.com/arduino/go-properties-orderedmap" ) -// nolint -const ( - BuildPropertiesArchiveFile = "archive_file" - BuildPropertiesArchiveFilePath = "archive_file_path" - BuildPropertiesObjectFile = "object_file" - RecipeARPattern = "recipe.ar.pattern" - BuildPropertiesIncludes = "includes" - BuildPropertiesCompilerWarningFlags = "compiler.warning_flags" - Space = " " -) - // Builder is a Sketch builder. type Builder struct { sketch *sketch.Sketch diff --git a/arduino/builder/utils/utils.go b/arduino/builder/utils/utils.go index f5aad02c810..10902c46ca0 100644 --- a/arduino/builder/utils/utils.go +++ b/arduino/builder/utils/utils.go @@ -520,8 +520,8 @@ func compileFileWithRecipe( verboseStdout, verboseInfo, errOut := &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{} properties := buildProperties.Clone() - properties.Set(builder.BuildPropertiesCompilerWarningFlags, properties.Get(builder.BuildPropertiesCompilerWarningFlags+"."+warningsLevel)) - properties.Set(builder.BuildPropertiesIncludes, strings.Join(includes, builder.Space)) + properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+warningsLevel)) + properties.Set("includes", strings.Join(includes, " ")) properties.SetPath("source_file", source) relativeSource, err := sourcePath.RelTo(source) if err != nil { @@ -530,7 +530,7 @@ func compileFileWithRecipe( depsFile := buildPath.Join(relativeSource.String() + ".d") objectFile := buildPath.Join(relativeSource.String() + ".o") - properties.SetPath(builder.BuildPropertiesObjectFile, objectFile) + properties.SetPath("object_file", objectFile) err = objectFile.Parent().MkdirAll() if err != nil { return nil, nil, nil, nil, errors.WithStack(err) @@ -615,11 +615,11 @@ func ArchiveCompiledFiles( for _, objectFile := range objectFilesToArchive { properties := buildProperties.Clone() - properties.Set(builder.BuildPropertiesArchiveFile, archiveFilePath.Base()) - properties.SetPath(builder.BuildPropertiesArchiveFilePath, archiveFilePath) - properties.SetPath(builder.BuildPropertiesObjectFile, objectFile) + properties.Set("archive_file", archiveFilePath.Base()) + properties.SetPath("archive_file_path", archiveFilePath) + properties.SetPath("object_file", objectFile) - command, err := PrepareCommandForRecipe(properties, builder.RecipeARPattern, false) + command, err := PrepareCommandForRecipe(properties, "recipe.ar.pattern", false) if err != nil { return nil, verboseInfobuf.Bytes(), errors.WithStack(err) } diff --git a/legacy/builder/phases/linker.go b/legacy/builder/phases/linker.go index 654c4e29bc4..f0c1f46e2f9 100644 --- a/legacy/builder/phases/linker.go +++ b/legacy/builder/phases/linker.go @@ -20,7 +20,6 @@ import ( "io" "strings" - "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/arduino/builder/utils" f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/go-paths-helper" @@ -106,7 +105,7 @@ func link( properties.SetPath("archive_file_path", archive) properties.SetPath("object_file", object) - command, err := utils.PrepareCommandForRecipe(properties, builder.RecipeARPattern, false) + command, err := utils.PrepareCommandForRecipe(properties, "recipe.ar.pattern", false) if err != nil { return nil, errors.WithStack(err) } @@ -125,9 +124,9 @@ func link( properties := buildProperties.Clone() properties.Set("compiler.c.elf.flags", properties.Get("compiler.c.elf.flags")) - properties.Set(builder.BuildPropertiesCompilerWarningFlags, properties.Get(builder.BuildPropertiesCompilerWarningFlags+"."+warningsLevel)) - properties.Set(builder.BuildPropertiesArchiveFile, coreDotARelPath.String()) - properties.Set(builder.BuildPropertiesArchiveFilePath, coreArchiveFilePath.String()) + properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+warningsLevel)) + properties.Set("archive_file", coreDotARelPath.String()) + properties.Set("archive_file_path", coreArchiveFilePath.String()) properties.Set("object_files", objectFileList) command, err := utils.PrepareCommandForRecipe(properties, "recipe.c.combine.pattern", false) From 830cbcb93387cd3c5fc0002e73d5c23d185aedda Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 8 Sep 2023 15:29:28 +0200 Subject: [PATCH 4/5] Pruned more constants --- legacy/builder/constants/constants.go | 3 --- legacy/builder/create_cmake_rule.go | 2 +- legacy/builder/merge_sketch_with_bootloader.go | 4 ++-- legacy/builder/phases/core_builder.go | 3 +-- legacy/builder/phases/libraries_builder.go | 3 +-- legacy/builder/test/helper_tools_downloader.go | 6 +++--- .../builder/wipeout_build_path_if_build_options_changed.go | 2 +- 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/legacy/builder/constants/constants.go b/legacy/builder/constants/constants.go index d1a6e4887c6..31287e769da 100644 --- a/legacy/builder/constants/constants.go +++ b/legacy/builder/constants/constants.go @@ -21,11 +21,8 @@ const BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK = "architecture.override_check" const BUILD_PROPERTIES_BOOTLOADER_FILE = "bootloader.file" const BUILD_PROPERTIES_BOOTLOADER_NOBLINK = "bootloader.noblink" const BUILD_PROPERTIES_BUILD_BOARD = "build.board" -const BUILD_PROPERTIES_BUILD_MCU = "build.mcu" const BUILD_PROPERTIES_COMPILER_LDFLAGS = "compiler.ldflags" const BUILD_PROPERTIES_COMPILER_CPP_FLAGS = "compiler.cpp.flags" -const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path" -const EMPTY_STRING = "" const FOLDER_BOOTLOADERS = "bootloaders" const FOLDER_CORE = "core" const FOLDER_SKETCH = "sketch" diff --git a/legacy/builder/create_cmake_rule.go b/legacy/builder/create_cmake_rule.go index 9ce4b068832..262218150f2 100644 --- a/legacy/builder/create_cmake_rule.go +++ b/legacy/builder/create_cmake_rule.go @@ -200,7 +200,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error { for _, library := range ctx.SketchLibrariesDetector.ImportedLibraries() { // Copy used libraries in the correct folder libDir := libBaseFolder.Join(library.DirName) - mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) + mcu := ctx.BuildProperties.Get("build.mcu") copyDir(library.InstallDir.String(), libDir.String(), validExportExtensions) // Read cmake options if available diff --git a/legacy/builder/merge_sketch_with_bootloader.go b/legacy/builder/merge_sketch_with_bootloader.go index b16b293ea44..7b9f0da3542 100644 --- a/legacy/builder/merge_sketch_with_bootloader.go +++ b/legacy/builder/merge_sketch_with_bootloader.go @@ -55,7 +55,7 @@ func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error { return nil } - bootloader := constants.EMPTY_STRING + bootloader := "" if bootloaderNoBlink, ok := buildProperties.GetOk(constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK); ok { bootloader = bootloaderNoBlink } else { @@ -63,7 +63,7 @@ func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error { } bootloader = buildProperties.ExpandPropsInString(bootloader) - bootloaderPath := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH).Join(constants.FOLDER_BOOTLOADERS, bootloader) + bootloaderPath := buildProperties.GetPath("runtime.platform.path").Join(constants.FOLDER_BOOTLOADERS, bootloader) if bootloaderPath.NotExist() { if ctx.Verbose { ctx.Warn(tr("Bootloader file specified but missing: %[1]s", bootloaderPath)) diff --git a/legacy/builder/phases/core_builder.go b/legacy/builder/phases/core_builder.go index 5c5e0339e41..9c49fe6d787 100644 --- a/legacy/builder/phases/core_builder.go +++ b/legacy/builder/phases/core_builder.go @@ -31,7 +31,6 @@ import ( "github.com/arduino/arduino-cli/buildcache" "github.com/arduino/arduino-cli/i18n" f "github.com/arduino/arduino-cli/internal/algorithms" - "github.com/arduino/arduino-cli/legacy/builder/constants" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" @@ -102,7 +101,7 @@ func compileCore( ) (*paths.Path, paths.PathList, error) { coreFolder := buildProperties.GetPath("build.core.path") variantFolder := buildProperties.GetPath("build.variant.path") - targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH) + targetCoreFolder := buildProperties.GetPath("runtime.platform.path") includes := []string{coreFolder.String()} if variantFolder != nil && variantFolder.IsDir() { diff --git a/legacy/builder/phases/libraries_builder.go b/legacy/builder/phases/libraries_builder.go index 8608b292916..9bd03c95f0a 100644 --- a/legacy/builder/phases/libraries_builder.go +++ b/legacy/builder/phases/libraries_builder.go @@ -25,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/arduino/builder/utils" "github.com/arduino/arduino-cli/arduino/libraries" f "github.com/arduino/arduino-cli/internal/algorithms" - "github.com/arduino/arduino-cli/legacy/builder/constants" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" @@ -87,7 +86,7 @@ func findExpectedPrecompiledLibFolder( buildProperties *properties.Map, verboseInfoFn func(msg string), ) *paths.Path { - mcu := buildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) + mcu := buildProperties.Get("build.mcu") // Add fpu specifications if they exist // To do so, resolve recipe.cpp.o.pattern, // search for -mfpu=xxx -mfloat-abi=yyy and add to a subfolder diff --git a/legacy/builder/test/helper_tools_downloader.go b/legacy/builder/test/helper_tools_downloader.go index f28c29c1c5e..2d80f0417fe 100644 --- a/legacy/builder/test/helper_tools_downloader.go +++ b/legacy/builder/test/helper_tools_downloader.go @@ -275,7 +275,7 @@ func findCoreUrl(index map[string]interface{}, core Core) (string, error) { } } - return constants.EMPTY_STRING, errors.Errorf("Unable to find tool " + core.Maintainer + " " + core.Arch + " " + core.Version) + return "", errors.Errorf("Unable to find tool " + core.Maintainer + " " + core.Arch + " " + core.Version) } func downloadTools(tools []Tool, index map[string]interface{}) error { @@ -664,7 +664,7 @@ func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string } } - return constants.EMPTY_STRING, errors.Errorf("Unable to find tool " + tool.Name + " " + tool.Version) + return "", errors.Errorf("Unable to find tool " + tool.Name + " " + tool.Version) } func downloadLibraries(libraries []Library, index map[string]interface{}) error { @@ -694,7 +694,7 @@ func findLibraryUrl(index map[string]interface{}, library Library) (string, erro } } - return constants.EMPTY_STRING, errors.Errorf("Unable to find library " + library.Name + " " + library.Version) + return "", errors.Errorf("Unable to find library " + library.Name + " " + library.Version) } func downloadAndUnpackLibrary(library Library, url string, targetPath *paths.Path) error { diff --git a/legacy/builder/wipeout_build_path_if_build_options_changed.go b/legacy/builder/wipeout_build_path_if_build_options_changed.go index 72b00b8671a..5b429971901 100644 --- a/legacy/builder/wipeout_build_path_if_build_options_changed.go +++ b/legacy/builder/wipeout_build_path_if_build_options_changed.go @@ -62,7 +62,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { // since the json was generated - like platform.txt or similar // if so, trigger a "safety" wipe buildProperties := ctx.BuildProperties - targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH) + targetCoreFolder := buildProperties.GetPath("runtime.platform.path") coreFolder := buildProperties.GetPath("build.core.path") realCoreFolder := coreFolder.Parent().Parent() jsonPath := ctx.BuildPath.Join(constants.BUILD_OPTIONS_FILE) From 17defc8b8b1e636a9147f76a01f167ad824038cc Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 8 Sep 2023 15:38:40 +0200 Subject: [PATCH 5/5] Fixed lint warnings --- arduino/builder/builder.go | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino/builder/builder.go b/arduino/builder/builder.go index 0d2ea79fb3b..fa1a2ba6fef 100644 --- a/arduino/builder/builder.go +++ b/arduino/builder/builder.go @@ -67,6 +67,7 @@ func NewBuilder( } } +// GetBuildProperties returns the build properties for running this build func (b *Builder) GetBuildProperties() *properties.Map { return b.buildProperties }