From da308d81f543fb49966d9ddeba034d5448d1be79 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Tue, 12 Sep 2023 18:24:10 +0200 Subject: [PATCH] remove legacy/constans pkg --- arduino/builder/export_cmake.go | 3 +- legacy/builder/constants/constants.go | 47 ------------------- .../builder/test/helper_tools_downloader.go | 21 ++++----- legacy/builder/test/libraries_loader_test.go | 5 +- .../test/merge_sketch_with_bootloader_test.go | 5 +- 5 files changed, 15 insertions(+), 66 deletions(-) delete mode 100644 legacy/builder/constants/constants.go diff --git a/arduino/builder/export_cmake.go b/arduino/builder/export_cmake.go index 00535076b19..6be00fb5175 100644 --- a/arduino/builder/export_cmake.go +++ b/arduino/builder/export_cmake.go @@ -30,7 +30,6 @@ import ( "github.com/arduino/arduino-cli/arduino/builder/utils" "github.com/arduino/arduino-cli/arduino/globals" "github.com/arduino/arduino-cli/arduino/libraries" - "github.com/arduino/arduino-cli/legacy/builder/constants" ) var lineMatcher = regexp.MustCompile(`^#line\s\d+\s"`) @@ -283,7 +282,7 @@ func (b *Builder) ExportProjectCMake( var dynamicLibsFromGccMinusL []string var linkDirectories []string - extractCompileFlags(b.buildProperties, constants.RECIPE_C_COMBINE_PATTERN, &defines, &dynamicLibsFromGccMinusL, &linkerflags, &linkDirectories) + extractCompileFlags(b.buildProperties, "recipe.c.combine.pattern", &defines, &dynamicLibsFromGccMinusL, &linkerflags, &linkDirectories) extractCompileFlags(b.buildProperties, "recipe.c.o.pattern", &defines, &dynamicLibsFromGccMinusL, &linkerflags, &linkDirectories) extractCompileFlags(b.buildProperties, "recipe.cpp.o.pattern", &defines, &dynamicLibsFromGccMinusL, &linkerflags, &linkDirectories) diff --git a/legacy/builder/constants/constants.go b/legacy/builder/constants/constants.go deleted file mode 100644 index 31287e769da..00000000000 --- a/legacy/builder/constants/constants.go +++ /dev/null @@ -1,47 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// Copyright 2015 Matthijs Kooijman -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package constants - -const BUILD_OPTIONS_FILE = "build.options.json" -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_COMPILER_LDFLAGS = "compiler.ldflags" -const BUILD_PROPERTIES_COMPILER_CPP_FLAGS = "compiler.cpp.flags" -const FOLDER_BOOTLOADERS = "bootloaders" -const FOLDER_CORE = "core" -const FOLDER_SKETCH = "sketch" -const FOLDER_TOOLS = "tools" -const FOLDER_LIBRARIES = "libraries" -const LIBRARY_ALL_ARCHS = "*" -const LIBRARY_EMAIL = "email" -const LIBRARY_FOLDER_SRC = "src" -const LOG_LEVEL_DEBUG = "debug" -const LOG_LEVEL_ERROR = "error" -const LOG_LEVEL_INFO = "info" -const LOG_LEVEL_WARN = "warn" - -const PACKAGE_NAME = "name" -const PACKAGE_TOOLS = "tools" -const PLATFORM_ARCHITECTURE = "architecture" -const PLATFORM_URL = "url" -const PLATFORM_VERSION = "version" -const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern" -const TOOL_NAME = "name" -const TOOL_URL = "url" -const TOOL_VERSION = "version" diff --git a/legacy/builder/test/helper_tools_downloader.go b/legacy/builder/test/helper_tools_downloader.go index 2d80f0417fe..ee4b60df572 100644 --- a/legacy/builder/test/helper_tools_downloader.go +++ b/legacy/builder/test/helper_tools_downloader.go @@ -26,7 +26,6 @@ import ( "strings" "testing" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" @@ -264,12 +263,12 @@ func findCoreUrl(index map[string]interface{}, core Core) (string, error) { packages := index["packages"].([]interface{}) for _, p := range packages { pack := p.(map[string]interface{}) - if pack[constants.PACKAGE_NAME].(string) == core.Maintainer { + if pack["name"].(string) == core.Maintainer { packagePlatforms := pack["platforms"].([]interface{}) for _, pt := range packagePlatforms { packagePlatform := pt.(map[string]interface{}) - if packagePlatform[constants.PLATFORM_ARCHITECTURE] == core.Arch && packagePlatform[constants.PLATFORM_VERSION] == core.Version { - return packagePlatform[constants.PLATFORM_URL].(string), nil + if packagePlatform["architecture"] == core.Arch && packagePlatform["version"] == core.Version { + return packagePlatform["url"].(string), nil } } } @@ -394,7 +393,7 @@ func allBoardsManagerToolsAlreadyDownloadedAndUnpacked(targetPath *paths.Path, t } func boardManagerToolAlreadyDownloadedAndUnpacked(targetPath *paths.Path, tool Tool) bool { - return targetPath.Join(tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version).Exist() + return targetPath.Join(tool.Package, "tools", tool.Name, tool.Version).Exist() } func allToolsAlreadyDownloadedAndUnpacked(targetPath *paths.Path, tools []Tool) bool { @@ -513,10 +512,10 @@ func downloadAndUnpackBoardsManagerTool(tool Tool, url string, targetPath *paths } defer unpackFolder.RemoveAll() - if err := targetPath.Join(tool.Package, constants.FOLDER_TOOLS, tool.Name).MkdirAll(); err != nil { + if err := targetPath.Join(tool.Package, "tools", tool.Name).MkdirAll(); err != nil { return errors.WithStack(err) } - if err := unpackFolder.Join(files[0].Base()).CopyDirTo(targetPath.Join(tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version)); err != nil { + if err := unpackFolder.Join(files[0].Base()).CopyDirTo(targetPath.Join(tool.Package, "tools", tool.Name, tool.Version)); err != nil { return errors.WithStack(err) } return nil @@ -646,17 +645,17 @@ func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string packages := index["packages"].([]interface{}) for _, p := range packages { pack := p.(map[string]interface{}) - packageTools := pack[constants.PACKAGE_TOOLS].([]interface{}) + packageTools := pack["tools"].([]interface{}) for _, pt := range packageTools { packageTool := pt.(map[string]interface{}) - name := packageTool[constants.TOOL_NAME].(string) - version := packageTool[constants.TOOL_VERSION].(string) + name := packageTool["name"].(string) + version := packageTool["version"].(string) if name == tool.Name && version == tool.Version { systems := packageTool["systems"].([]interface{}) for _, s := range systems { system := s.(map[string]interface{}) if slices.Contains(host, system["host"].(string)) { - return system[constants.TOOL_URL].(string), nil + return system["url"].(string), nil } } } diff --git a/legacy/builder/test/libraries_loader_test.go b/legacy/builder/test/libraries_loader_test.go index 5866fbcfa98..eae7d3a121b 100644 --- a/legacy/builder/test/libraries_loader_test.go +++ b/legacy/builder/test/libraries_loader_test.go @@ -22,7 +22,6 @@ import ( "github.com/arduino/arduino-cli/arduino/builder/detector" "github.com/arduino/arduino-cli/arduino/libraries" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/types" paths "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" @@ -74,7 +73,7 @@ func TestLoadLibrariesAVR(t *testing.T) { require.True(t, Abs(t, paths.New("downloaded_libraries/Adafruit_PN532")).EquivalentTo(libs[idx].InstallDir)) require.True(t, Abs(t, paths.New("downloaded_libraries/Adafruit_PN532")).EquivalentTo(libs[idx].SourceDir)) require.Equal(t, 1, len(libs[idx].Architectures)) - require.Equal(t, constants.LIBRARY_ALL_ARCHS, libs[idx].Architectures[0]) + require.Equal(t, "*", libs[idx].Architectures[0]) require.False(t, libs[idx].IsLegacy) idx++ @@ -90,7 +89,7 @@ func TestLoadLibrariesAVR(t *testing.T) { require.True(t, Abs(t, paths.New("downloaded_libraries/Bridge")).EquivalentTo(bridgeLib.InstallDir)) require.True(t, Abs(t, paths.New("downloaded_libraries/Bridge/src")).EquivalentTo(bridgeLib.SourceDir)) require.Equal(t, 1, len(bridgeLib.Architectures)) - require.Equal(t, constants.LIBRARY_ALL_ARCHS, bridgeLib.Architectures[0]) + require.Equal(t, "*", bridgeLib.Architectures[0]) require.Equal(t, "Arduino", bridgeLib.Author) require.Equal(t, "Arduino ", bridgeLib.Maintainer) diff --git a/legacy/builder/test/merge_sketch_with_bootloader_test.go b/legacy/builder/test/merge_sketch_with_bootloader_test.go index 0478641d241..a418b94543e 100644 --- a/legacy/builder/test/merge_sketch_with_bootloader_test.go +++ b/legacy/builder/test/merge_sketch_with_bootloader_test.go @@ -21,7 +21,6 @@ import ( "strings" "testing" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/types" paths "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" @@ -138,8 +137,8 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { buildPath := ctx.Builder.GetBuildPath() buildProperties := ctx.Builder.GetBuildProperties() - buildProperties.Remove(constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) - buildProperties.Remove(constants.BUILD_PROPERTIES_BOOTLOADER_FILE) + buildProperties.Remove("bootloader.noblink") + buildProperties.Remove("bootloader.file") err := ctx.Builder.MergeSketchWithBootloader(ctx.OnlyUpdateCompilationDatabase) require.NoError(t, err)