Skip to content

Commit 5b805dd

Browse files
authored
[skip-changelog] legacy removing: small advances (1st chunk of #481) (#627)
* Removed legacy utils.PrettyOSName function * 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. * Removed unused Context parameter * upgrade github.com/arduino/go-properties-orderedmap to v1.0.0
1 parent c7742fa commit 5b805dd

12 files changed

+26
-62
lines changed

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
bou.ke/monkey v1.0.1
77
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
88
github.com/arduino/go-paths-helper v1.0.1
9-
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c
9+
github.com/arduino/go-properties-orderedmap v1.0.0
1010
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1111
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
1212
github.com/cmaglie/pb v1.0.27

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT9
1010
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
1111
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
1212
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
13-
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c h1:4z4PJqNH8WGXtm9ix2muUOAP7gxTGBOdQTuKEDyCnsA=
14-
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c/go.mod h1:kiSuHm7yz3chiy8rb2MphC7ECn3MlkQFAIe4SXmQg6o=
13+
github.com/arduino/go-properties-orderedmap v1.0.0 h1:caaM25TQZKkytoKQUsgqtOVbrM5i8Gb427JmW0KL05s=
14+
github.com/arduino/go-properties-orderedmap v1.0.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
1515
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
1616
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
1717
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=

Diff for: legacy/builder/constants/constants.go

-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ const BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK = "architecture.override_check"
2323
const BUILD_PROPERTIES_BOOTLOADER_FILE = "bootloader.file"
2424
const BUILD_PROPERTIES_BOOTLOADER_NOBLINK = "bootloader.noblink"
2525
const BUILD_PROPERTIES_BUILD_BOARD = "build.board"
26-
const BUILD_PROPERTIES_BUILD_CORE_PATH = "build.core.path"
2726
const BUILD_PROPERTIES_BUILD_MCU = "build.mcu"
28-
const BUILD_PROPERTIES_BUILD_VARIANT_PATH = "build.variant.path"
2927
const BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS = "compiler.c.elf.flags"
3028
const BUILD_PROPERTIES_COMPILER_LDFLAGS = "compiler.ldflags"
3129
const BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS = "compiler.libraries.ldflags"
@@ -46,7 +44,6 @@ const CTAGS = "ctags"
4644
const EMPTY_STRING = ""
4745
const FILE_CTAGS_TARGET_FOR_GCC_MINUS_E = "ctags_target_for_gcc_minus_e.cpp"
4846
const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt"
49-
const FILE_INCLUDES_CACHE = "includes.cache"
5047
const FOLDER_BOOTLOADERS = "bootloaders"
5148
const FOLDER_CORE = "core"
5249
const FOLDER_PREPROC = "preproc"
@@ -156,7 +153,6 @@ const RECIPE_SIZE_REGEXP_EEPROM = "recipe.size.regex.eeprom"
156153
const REWRITING_DISABLED = "disabled"
157154
const REWRITING = "rewriting"
158155
const SPACE = " "
159-
const SKETCH_FOLDER_SRC = "src"
160156
const TOOL_NAME = "name"
161157
const TOOL_URL = "url"
162158
const TOOL_VERSION = "version"

Diff for: legacy/builder/container_find_includes.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ import (
111111
type ContainerFindIncludes struct{}
112112

113113
func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
114-
cachePath := ctx.BuildPath.Join(constants.FILE_INCLUDES_CACHE)
114+
cachePath := ctx.BuildPath.Join("includes.cache")
115115
cache := readCache(cachePath)
116116

117-
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH))
118-
if ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH) != "" {
119-
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH))
117+
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath("build.core.path"))
118+
if ctx.BuildProperties.Get("build.variant.path") != "" {
119+
appendIncludeFolder(ctx, cache, nil, "", ctx.BuildProperties.GetPath("build.variant.path"))
120120
}
121121

122122
sketch := ctx.Sketch
@@ -128,7 +128,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
128128

129129
sourceFilePaths := ctx.CollectedSourceFiles
130130
queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, ctx.SketchBuildPath, false /* recurse */)
131-
srcSubfolderPath := ctx.SketchBuildPath.Join(constants.SKETCH_FOLDER_SRC)
131+
srcSubfolderPath := ctx.SketchBuildPath.Join("src")
132132
if srcSubfolderPath.IsDir() {
133133
queueSourceFilesFromFolder(ctx, sourceFilePaths, sketch, srcSubfolderPath, true /* recurse */)
134134
}
@@ -336,7 +336,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
336336
// other errors
337337
return errors.WithStack(preproc_err)
338338
} else {
339-
include = IncludesFinderWithRegExp(ctx, string(preproc_stderr))
339+
include = IncludesFinderWithRegExp(string(preproc_stderr))
340340
if include == "" && ctx.Verbose {
341341
ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_FIND_INCLUDES_FAILED, sourcePath)
342342
}

Diff for: legacy/builder/create_cmake_rule.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
104104
}
105105

106106
// Copy core + variant in use + preprocessed sketch in the correct folders
107-
err := utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_CORE_PATH), coreFolder.String(), extensions)
107+
err := utils.CopyDir(ctx.BuildProperties.Get("build.core.path"), coreFolder.String(), extensions)
108108
if err != nil {
109109
fmt.Println(err)
110110
}
111-
err = utils.CopyDir(ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH), coreFolder.Join("variant").String(), extensions)
111+
err = utils.CopyDir(ctx.BuildProperties.Get("build.variant.path"), coreFolder.Join("variant").String(), extensions)
112112
if err != nil {
113113
fmt.Println(err)
114114
}

Diff for: legacy/builder/includes_finder_with_regexp.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@
1616
package builder
1717

1818
import (
19-
"github.com/arduino/arduino-cli/legacy/builder/types"
2019
"regexp"
2120
"strings"
2221
)
2322

2423
var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
2524

26-
func IncludesFinderWithRegExp(ctx *types.Context, source string) string {
25+
func IncludesFinderWithRegExp(source string) string {
2726
match := INCLUDE_REGEXP.FindStringSubmatch(source)
2827
if match != nil {
2928
return strings.TrimSpace(match[1])
30-
} else {
31-
return findIncludeForOldCompilers(source)
3229
}
30+
return findIncludeForOldCompilers(source)
3331
}
3432

3533
func findIncludeForOldCompilers(source string) string {

Diff for: legacy/builder/phases/core_builder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func (s *CoreBuilder) Run(ctx *types.Context) error {
6464

6565
func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *paths.Path, buildProperties *properties.Map) (*paths.Path, paths.PathList, error) {
6666
logger := ctx.GetLogger()
67-
coreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH)
68-
variantFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH)
67+
coreFolder := buildProperties.GetPath("build.core.path")
68+
variantFolder := buildProperties.GetPath("build.variant.path")
6969

7070
targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH)
7171

Diff for: legacy/builder/phases/sketch_builder.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package phases
1717

1818
import (
1919
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
20-
"github.com/arduino/arduino-cli/legacy/builder/constants"
2120
"github.com/arduino/arduino-cli/legacy/builder/types"
2221
"github.com/arduino/arduino-cli/legacy/builder/utils"
2322
"github.com/pkg/errors"
@@ -40,7 +39,7 @@ func (s *SketchBuilder) Run(ctx *types.Context) error {
4039
}
4140

4241
// The "src/" subdirectory of a sketch is compiled recursively
43-
sketchSrcPath := sketchBuildPath.Join(constants.SKETCH_FOLDER_SRC)
42+
sketchSrcPath := sketchBuildPath.Join("src")
4443
if sketchSrcPath.IsDir() {
4544
srcObjectFiles, err := builder_utils.CompileFiles(ctx, sketchSrcPath, true, sketchSrcPath, buildProperties, includes)
4645
if err != nil {

Diff for: legacy/builder/setup_build_properties.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/arduino/arduino-cli/arduino/cores"
2626
"github.com/arduino/arduino-cli/legacy/builder/types"
27-
"github.com/arduino/arduino-cli/legacy/builder/utils"
2827
properties "github.com/arduino/go-properties-orderedmap"
2928
timeutils "github.com/arduino/go-timeutils"
3029
)
@@ -67,7 +66,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
6766
buildProperties.Set("runtime.ide.path", exPath)
6867
buildProperties.Set("build.fqbn", ctx.FQBN.String())
6968
buildProperties.Set("ide_version", ctx.ArduinoAPIVersion)
70-
buildProperties.Set("runtime.os", utils.PrettyOSName())
69+
buildProperties.Set("runtime.os", properties.GetOSSuffix())
7170

7271
if ctx.OptimizeForDebug {
7372
if buildProperties.ContainsKey("compiler.optimization_flags.debug") {

Diff for: legacy/builder/test/includes_finder_with_regexp_test.go

+8-20
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,62 @@
1616
package test
1717

1818
import (
19+
"testing"
20+
1921
"github.com/arduino/arduino-cli/legacy/builder"
20-
"github.com/arduino/arduino-cli/legacy/builder/types"
2122
"github.com/stretchr/testify/require"
22-
"testing"
2323
)
2424

2525
func TestIncludesFinderWithRegExp(t *testing.T) {
26-
ctx := &types.Context{}
27-
2826
output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" +
2927
"#include <SPI.h>\n" +
3028
"^\n" +
3129
"compilation terminated."
32-
include := builder.IncludesFinderWithRegExp(ctx, output)
30+
include := builder.IncludesFinderWithRegExp(output)
3331

3432
require.Equal(t, "SPI.h", include)
3533
}
3634

3735
func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) {
38-
ctx := &types.Context{}
39-
40-
include := builder.IncludesFinderWithRegExp(ctx, "")
36+
include := builder.IncludesFinderWithRegExp("")
4137

4238
require.Equal(t, "", include)
4339
}
4440

4541
func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) {
46-
ctx := &types.Context{}
47-
4842
output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" +
4943
" # include <Wire.h>\n" +
5044
" ^\n" +
5145
"compilation terminated.\n"
52-
include := builder.IncludesFinderWithRegExp(ctx, output)
46+
include := builder.IncludesFinderWithRegExp(output)
5347

5448
require.Equal(t, "Wire.h", include)
5549
}
5650

5751
func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) {
58-
ctx := &types.Context{}
59-
6052
output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" +
6153
" #\t\t\tinclude <Wire.h>\n" +
6254
" ^\n" +
6355
"compilation terminated.\n"
64-
include := builder.IncludesFinderWithRegExp(ctx, output)
56+
include := builder.IncludesFinderWithRegExp(output)
6557

6658
require.Equal(t, "Wire.h", include)
6759
}
6860

6961
func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) {
70-
ctx := &types.Context{}
71-
7262
output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" +
7363
"compilation terminated.\n"
7464

75-
include := builder.IncludesFinderWithRegExp(ctx, output)
65+
include := builder.IncludesFinderWithRegExp(output)
7666

7767
require.Equal(t, "SPI.h", include)
7868
}
7969

8070
func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) {
81-
ctx := &types.Context{}
82-
8371
output := "In file included from /tmp/arduino_modified_sketch_815412/binouts.ino:52:0:\n" +
8472
"/tmp/arduino_build_static/sketch/regtable.h:31:22: fatal error: register.h: No such file or directory\n"
8573

86-
include := builder.IncludesFinderWithRegExp(ctx, output)
74+
include := builder.IncludesFinderWithRegExp(output)
8775

8876
require.Equal(t, "register.h", include)
8977
}

Diff for: legacy/builder/utils/utils.go

-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"os"
2626
"os/exec"
2727
"path/filepath"
28-
"runtime"
2928
"strings"
3029
"unicode"
3130
"unicode/utf8"
@@ -40,21 +39,6 @@ import (
4039
"golang.org/x/text/unicode/norm"
4140
)
4241

43-
func PrettyOSName() string {
44-
switch osName := runtime.GOOS; osName {
45-
case "darwin":
46-
return "macosx"
47-
case "freebsd":
48-
return "freebsd"
49-
case "linux":
50-
return "linux"
51-
case "windows":
52-
return "windows"
53-
default:
54-
return "other"
55-
}
56-
}
57-
5842
func ParseCommandLine(input string, logger i18n.Logger) ([]string, error) {
5943
var parts []string
6044
escapingChar := constants.EMPTY_STRING

Diff for: legacy/builder/wipeout_build_path_if_build_options_changed.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
5454
// if so, trigger a "safety" wipe
5555
buildProperties := ctx.BuildProperties
5656
targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH)
57-
coreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_BUILD_CORE_PATH)
57+
coreFolder := buildProperties.GetPath("build.core.path")
5858
realCoreFolder := coreFolder.Parent().Parent()
5959
jsonPath := ctx.BuildPath.Join(constants.BUILD_OPTIONS_FILE)
6060
coreHasChanged := builder_utils.TXTBuildRulesHaveChanged(realCoreFolder, targetCoreFolder, jsonPath)

0 commit comments

Comments
 (0)