From 607b95b5754cc98c71aea1514e8f34e19e404f80 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 16 Oct 2019 16:38:05 +0200 Subject: [PATCH 1/4] Removed legacy utils.PrettyOSName function --- go.mod | 2 +- go.sum | 2 ++ legacy/builder/setup_build_properties.go | 3 +-- legacy/builder/utils/utils.go | 16 ---------------- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index ecd9e81aefe..5d0296a91ec 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( bou.ke/monkey v1.0.1 github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c github.com/arduino/go-paths-helper v1.0.1 - github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c + github.com/arduino/go-properties-orderedmap v0.0.0-20191016140733-00365bfa6b40 github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b github.com/cmaglie/pb v1.0.27 diff --git a/go.sum b/go.sum index a4b55be2b0b..2093f193dff 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWje github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c h1:4z4PJqNH8WGXtm9ix2muUOAP7gxTGBOdQTuKEDyCnsA= github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c/go.mod h1:kiSuHm7yz3chiy8rb2MphC7ECn3MlkQFAIe4SXmQg6o= +github.com/arduino/go-properties-orderedmap v0.0.0-20191016140733-00365bfa6b40 h1:ZJCKy0Y+m/Lj0I/3BP0KNEUmd7eQ52HYcua21e76pcA= +github.com/arduino/go-properties-orderedmap v0.0.0-20191016140733-00365bfa6b40/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4= github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ= github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20= diff --git a/legacy/builder/setup_build_properties.go b/legacy/builder/setup_build_properties.go index a69ae5099a5..b8ebd9b5e83 100644 --- a/legacy/builder/setup_build_properties.go +++ b/legacy/builder/setup_build_properties.go @@ -24,7 +24,6 @@ import ( "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/legacy/builder/types" - "github.com/arduino/arduino-cli/legacy/builder/utils" properties "github.com/arduino/go-properties-orderedmap" timeutils "github.com/arduino/go-timeutils" ) @@ -67,7 +66,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties.Set("runtime.ide.path", exPath) buildProperties.Set("build.fqbn", ctx.FQBN.String()) buildProperties.Set("ide_version", ctx.ArduinoAPIVersion) - buildProperties.Set("runtime.os", utils.PrettyOSName()) + buildProperties.Set("runtime.os", properties.GetOSSuffix()) if ctx.OptimizeForDebug { if buildProperties.ContainsKey("compiler.optimization_flags.debug") { diff --git a/legacy/builder/utils/utils.go b/legacy/builder/utils/utils.go index d58d0e997a6..acd1a6ec52f 100644 --- a/legacy/builder/utils/utils.go +++ b/legacy/builder/utils/utils.go @@ -25,7 +25,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strings" "unicode" "unicode/utf8" @@ -40,21 +39,6 @@ import ( "golang.org/x/text/unicode/norm" ) -func PrettyOSName() string { - switch osName := runtime.GOOS; osName { - case "darwin": - return "macosx" - case "freebsd": - return "freebsd" - case "linux": - return "linux" - case "windows": - return "windows" - default: - return "other" - } -} - func ParseCommandLine(input string, logger i18n.Logger) ([]string, error) { var parts []string escapingChar := constants.EMPTY_STRING From ce8368e4c0ed33ccdaac015fa5221bc165bf3b52 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 16 Oct 2019 16:53:57 +0200 Subject: [PATCH 2/4] Removed some constants Possibly a container structure for build properties may be defined later with helper methods (like GetBuildCorePath() ... etc.) to help in retrieving these properties. --- legacy/builder/constants/constants.go | 4 ---- legacy/builder/container_find_includes.go | 10 +++++----- legacy/builder/create_cmake_rule.go | 4 ++-- legacy/builder/phases/core_builder.go | 4 ++-- legacy/builder/phases/sketch_builder.go | 3 +-- .../wipeout_build_path_if_build_options_changed.go | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/legacy/builder/constants/constants.go b/legacy/builder/constants/constants.go index c73cdeae1af..15cbc352926 100644 --- a/legacy/builder/constants/constants.go +++ b/legacy/builder/constants/constants.go @@ -23,9 +23,7 @@ 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_CORE_PATH = "build.core.path" const BUILD_PROPERTIES_BUILD_MCU = "build.mcu" -const BUILD_PROPERTIES_BUILD_VARIANT_PATH = "build.variant.path" const BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS = "compiler.c.elf.flags" const BUILD_PROPERTIES_COMPILER_LDFLAGS = "compiler.ldflags" const BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS = "compiler.libraries.ldflags" @@ -46,7 +44,6 @@ const CTAGS = "ctags" const EMPTY_STRING = "" const FILE_CTAGS_TARGET_FOR_GCC_MINUS_E = "ctags_target_for_gcc_minus_e.cpp" const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt" -const FILE_INCLUDES_CACHE = "includes.cache" const FOLDER_BOOTLOADERS = "bootloaders" const FOLDER_CORE = "core" const FOLDER_PREPROC = "preproc" @@ -156,7 +153,6 @@ const RECIPE_SIZE_REGEXP_EEPROM = "recipe.size.regex.eeprom" const REWRITING_DISABLED = "disabled" const REWRITING = "rewriting" const SPACE = " " -const SKETCH_FOLDER_SRC = "src" const TOOL_NAME = "name" const TOOL_URL = "url" const TOOL_VERSION = "version" diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 08b6796e6cc..6c012835e58 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -111,12 +111,12 @@ import ( type ContainerFindIncludes struct{} func (s *ContainerFindIncludes) Run(ctx *types.Context) error { - cachePath := ctx.BuildPath.Join(constants.FILE_INCLUDES_CACHE) + cachePath := ctx.BuildPath.Join("includes.cache") cache := readCache(cachePath) - appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH)) - if ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH) != "" { - appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH)) + appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath("build.core.path")) + if ctx.BuildProperties.Get("build.variant.path") != "" { + appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath("build.variant.path")) } sketch := ctx.Sketch @@ -128,7 +128,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error { sourceFilePaths := ctx.CollectedSourceFiles queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, ctx.SketchBuildPath, false /* recurse */) - srcSubfolderPath := ctx.SketchBuildPath.Join(constants.SKETCH_FOLDER_SRC) + srcSubfolderPath := ctx.SketchBuildPath.Join("src") if srcSubfolderPath.IsDir() { queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, srcSubfolderPath, true /* recurse */) } diff --git a/legacy/builder/create_cmake_rule.go b/legacy/builder/create_cmake_rule.go index 325435ed140..dc09db6e65d 100644 --- a/legacy/builder/create_cmake_rule.go +++ b/legacy/builder/create_cmake_rule.go @@ -104,11 +104,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error { } // Copy core + variant in use + preprocessed sketch in the correct folders - err := utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_CORE_PATH), coreFolder.String(), extensions) + err := utils.CopyDir(ctx.BuildProperties.Get("build.core.path"), coreFolder.String(), extensions) if err != nil { fmt.Println(err) } - err = utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH), coreFolder.Join("variant").String(), extensions) + err = utils.CopyDir(ctx.BuildProperties.Get("build.variant.path"), coreFolder.Join("variant").String(), extensions) if err != nil { fmt.Println(err) } diff --git a/legacy/builder/phases/core_builder.go b/legacy/builder/phases/core_builder.go index 52ecfcb1ae1..92e017acb72 100644 --- a/legacy/builder/phases/core_builder.go +++ b/legacy/builder/phases/core_builder.go @@ -64,8 +64,8 @@ func (s *CoreBuilder) Run(ctx *types.Context) error { func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *paths.Path, buildProperties *properties.Map) (*paths.Path, paths.PathList, error) { logger := ctx.GetLogger() - coreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH) - variantFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH) + coreFolder := buildProperties.GetPath("build.core.path") + variantFolder := buildProperties.GetPath("build.variant.path") targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH) diff --git a/legacy/builder/phases/sketch_builder.go b/legacy/builder/phases/sketch_builder.go index 59055375fb5..8fea0f129c0 100644 --- a/legacy/builder/phases/sketch_builder.go +++ b/legacy/builder/phases/sketch_builder.go @@ -17,7 +17,6 @@ package phases import ( "github.com/arduino/arduino-cli/legacy/builder/builder_utils" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/pkg/errors" @@ -40,7 +39,7 @@ func (s *SketchBuilder) Run(ctx *types.Context) error { } // The "src/" subdirectory of a sketch is compiled recursively - sketchSrcPath := sketchBuildPath.Join(constants.SKETCH_FOLDER_SRC) + sketchSrcPath := sketchBuildPath.Join("src") if sketchSrcPath.IsDir() { srcObjectFiles, err := builder_utils.CompileFiles(ctx, sketchSrcPath, true, sketchSrcPath, buildProperties, includes) if err != nil { 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 d00d282fbc2..72237b875fb 100644 --- a/legacy/builder/wipeout_build_path_if_build_options_changed.go +++ b/legacy/builder/wipeout_build_path_if_build_options_changed.go @@ -54,7 +54,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { // if so, trigger a "safety" wipe buildProperties := ctx.BuildProperties targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH) - coreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH) + coreFolder := buildProperties.GetPath("build.core.path") realCoreFolder := coreFolder.Parent().Parent() jsonPath := ctx.BuildPath.Join(constants.BUILD_OPTIONS_FILE) coreHasChanged := builder_utils.TXTBuildRulesHaveChanged(realCoreFolder, targetCoreFolder, jsonPath) From 9c63b53b42c17d25e0ff9abc574b735c40db8249 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 17 Oct 2019 19:09:35 +0200 Subject: [PATCH 3/4] Removed unused Context parameter --- legacy/builder/container_find_includes.go | 2 +- legacy/builder/includes_finder_with_regexp.go | 6 ++-- .../test/includes_finder_with_regexp_test.go | 28 ++++++------------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 6c012835e58..2d980aca4ec 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -336,7 +336,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t // other errors return errors.WithStack(preproc_err) } else { - include = IncludesFinderWithRegExp(ctx, string(preproc_stderr)) + include = IncludesFinderWithRegExp(string(preproc_stderr)) if include == "" && ctx.Verbose { ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_FIND_INCLUDES_FAILED, sourcePath) } diff --git a/legacy/builder/includes_finder_with_regexp.go b/legacy/builder/includes_finder_with_regexp.go index 994ef26ff2b..0ad876a26e3 100644 --- a/legacy/builder/includes_finder_with_regexp.go +++ b/legacy/builder/includes_finder_with_regexp.go @@ -16,20 +16,18 @@ package builder import ( - "github.com/arduino/arduino-cli/legacy/builder/types" "regexp" "strings" ) var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]") -func IncludesFinderWithRegExp(ctx *types.Context, source string) string { +func IncludesFinderWithRegExp(source string) string { match := INCLUDE_REGEXP.FindStringSubmatch(source) if match != nil { return strings.TrimSpace(match[1]) - } else { - return findIncludeForOldCompilers(source) } + return findIncludeForOldCompilers(source) } func findIncludeForOldCompilers(source string) string { diff --git a/legacy/builder/test/includes_finder_with_regexp_test.go b/legacy/builder/test/includes_finder_with_regexp_test.go index 0276082d490..3a55415aa88 100644 --- a/legacy/builder/test/includes_finder_with_regexp_test.go +++ b/legacy/builder/test/includes_finder_with_regexp_test.go @@ -16,74 +16,62 @@ package test import ( + "testing" + "github.com/arduino/arduino-cli/legacy/builder" - "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/stretchr/testify/require" - "testing" ) func TestIncludesFinderWithRegExp(t *testing.T) { - ctx := &types.Context{} - output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" + "#include \n" + "^\n" + "compilation terminated." - include := builder.IncludesFinderWithRegExp(ctx, output) + include := builder.IncludesFinderWithRegExp(output) require.Equal(t, "SPI.h", include) } func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { - ctx := &types.Context{} - - include := builder.IncludesFinderWithRegExp(ctx, "") + include := builder.IncludesFinderWithRegExp("") require.Equal(t, "", include) } func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { - ctx := &types.Context{} - output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" + " # include \n" + " ^\n" + "compilation terminated.\n" - include := builder.IncludesFinderWithRegExp(ctx, output) + include := builder.IncludesFinderWithRegExp(output) require.Equal(t, "Wire.h", include) } func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { - ctx := &types.Context{} - output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" + " #\t\t\tinclude \n" + " ^\n" + "compilation terminated.\n" - include := builder.IncludesFinderWithRegExp(ctx, output) + include := builder.IncludesFinderWithRegExp(output) require.Equal(t, "Wire.h", include) } func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { - ctx := &types.Context{} - output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" + "compilation terminated.\n" - include := builder.IncludesFinderWithRegExp(ctx, output) + include := builder.IncludesFinderWithRegExp(output) require.Equal(t, "SPI.h", include) } func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) { - ctx := &types.Context{} - output := "In file included from /tmp/arduino_modified_sketch_815412/binouts.ino:52:0:\n" + "/tmp/arduino_build_static/sketch/regtable.h:31:22: fatal error: register.h: No such file or directory\n" - include := builder.IncludesFinderWithRegExp(ctx, output) + include := builder.IncludesFinderWithRegExp(output) require.Equal(t, "register.h", include) } From 2bce67933485851b9a783b212853a3d485c797ea Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 20 Mar 2020 11:54:51 +0100 Subject: [PATCH 4/4] upgrade github.com/arduino/go-properties-orderedmap to v1.0.0 --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 5d0296a91ec..dc0a46b304a 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( bou.ke/monkey v1.0.1 github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c github.com/arduino/go-paths-helper v1.0.1 - github.com/arduino/go-properties-orderedmap v0.0.0-20191016140733-00365bfa6b40 + github.com/arduino/go-properties-orderedmap v1.0.0 github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b github.com/cmaglie/pb v1.0.27 diff --git a/go.sum b/go.sum index 2093f193dff..93467d7115d 100644 --- a/go.sum +++ b/go.sum @@ -10,10 +10,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT9 github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8= github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q= github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= -github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c h1:4z4PJqNH8WGXtm9ix2muUOAP7gxTGBOdQTuKEDyCnsA= -github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c/go.mod h1:kiSuHm7yz3chiy8rb2MphC7ECn3MlkQFAIe4SXmQg6o= -github.com/arduino/go-properties-orderedmap v0.0.0-20191016140733-00365bfa6b40 h1:ZJCKy0Y+m/Lj0I/3BP0KNEUmd7eQ52HYcua21e76pcA= -github.com/arduino/go-properties-orderedmap v0.0.0-20191016140733-00365bfa6b40/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= +github.com/arduino/go-properties-orderedmap v1.0.0 h1:caaM25TQZKkytoKQUsgqtOVbrM5i8Gb427JmW0KL05s= +github.com/arduino/go-properties-orderedmap v1.0.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4= github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ= github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=