Skip to content

Commit 7e8ceb0

Browse files
author
Federico Fissore
committed
Implemented rewriting=disabled (missing feature): skips platform keys rewriting
Signed-off-by: Federico Fissore <[email protected]>
1 parent 2def251 commit 7e8ceb0

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

Diff for: src/arduino.cc/builder/constants/constants.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ const BUILD_PROPERTIES_TOOLS_KEY = "tools"
6565
const BUILD_PROPERTIES_VID = "vid"
6666
const COAN = "coan"
6767
const CTAGS = "ctags"
68-
const CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH = "libraryDiscoveryRecursionDepth"
6968
const CTX_ACTUAL_PLATFORM = "actualPlatform"
7069
const CTX_BUILD_CORE = "buildCore"
7170
const CTX_BUILD_OPTIONS = "buildOptions"
@@ -93,6 +92,7 @@ const CTX_INCLUDES = "includes"
9392
const CTX_LIBRARIES_BUILD_PATH = "librariesBuildPath"
9493
const CTX_LIBRARIES_FOLDERS = "librariesFolders"
9594
const CTX_LIBRARIES = "libraries"
95+
const CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH = "libraryDiscoveryRecursionDepth"
9696
const CTX_LINE_OFFSET = "lineOffset"
9797
const CTX_LOGGER = "logger"
9898
const CTX_OBJECT_FILES_CORE = "objectFilesCore"
@@ -231,6 +231,8 @@ const RECIPE_CPP_PATTERN = "recipe.cpp.o.pattern"
231231
const RECIPE_PREPROC_INCLUDES = "recipe.preproc.includes"
232232
const RECIPE_PREPROC_MACROS = "recipe.preproc.macros"
233233
const RECIPE_S_PATTERN = "recipe.S.o.pattern"
234+
const REWRITING_DISABLED = "disabled"
235+
const REWRITING = "rewriting"
234236
const SPACE = " "
235237
const TOOL_NAME = "name"
236238
const TOOL_URL = "url"

Diff for: src/arduino.cc/builder/rewrite_hardware_keys.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ func (s *RewriteHardwareKeys) Run(context map[string]interface{}) error {
5252

5353
for _, aPackage := range hardware {
5454
for _, platform := range aPackage.Platforms {
55-
for _, rewrite := range platformKeysRewrite.Rewrites {
56-
if platform.Properties[rewrite.Key] != constants.EMPTY_STRING && platform.Properties[rewrite.Key] == rewrite.OldValue {
57-
platform.Properties[rewrite.Key] = rewrite.NewValue
58-
if warn {
59-
logger.Fprintln(os.Stderr, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
55+
if platform.Properties[constants.REWRITING] != constants.REWRITING_DISABLED {
56+
for _, rewrite := range platformKeysRewrite.Rewrites {
57+
if platform.Properties[rewrite.Key] != constants.EMPTY_STRING && platform.Properties[rewrite.Key] == rewrite.OldValue {
58+
platform.Properties[rewrite.Key] = rewrite.NewValue
59+
if warn {
60+
logger.Fprintln(os.Stderr, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
61+
}
6062
}
6163
}
6264
}

Diff for: src/arduino.cc/builder/test/rewrite_hardware_keys_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,39 @@ func TestRewriteHardwareKeys(t *testing.T) {
7070

7171
require.Equal(t, "{runtime.tools.avr-gcc.path}/bin/", platform.Properties[constants.BUILD_PROPERTIES_COMPILER_PATH])
7272
}
73+
74+
func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) {
75+
context := make(map[string]interface{})
76+
77+
hardware := make(map[string]*types.Package)
78+
aPackage := &types.Package{PackageId: "dummy"}
79+
hardware["dummy"] = aPackage
80+
aPackage.Platforms = make(map[string]*types.Platform)
81+
82+
platform := &types.Platform{PlatformId: "dummy"}
83+
aPackage.Platforms["dummy"] = platform
84+
platform.Properties = make(map[string]string)
85+
platform.Properties[constants.PLATFORM_NAME] = "A test platform"
86+
platform.Properties[constants.BUILD_PROPERTIES_COMPILER_PATH] = "{runtime.ide.path}/hardware/tools/avr/bin/"
87+
platform.Properties[constants.REWRITING] = constants.REWRITING_DISABLED
88+
89+
context[constants.CTX_HARDWARE] = hardware
90+
91+
rewrite := types.PlatforKeyRewrite{Key: constants.BUILD_PROPERTIES_COMPILER_PATH, OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"}
92+
platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}}
93+
94+
context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite
95+
96+
commands := []types.Command{
97+
&builder.SetupHumanLoggerIfMissing{},
98+
&builder.AddAdditionalEntriesToContext{},
99+
&builder.RewriteHardwareKeys{},
100+
}
101+
102+
for _, command := range commands {
103+
err := command.Run(context)
104+
NoError(t, err)
105+
}
106+
107+
require.Equal(t, "{runtime.ide.path}/hardware/tools/avr/bin/", platform.Properties[constants.BUILD_PROPERTIES_COMPILER_PATH])
108+
}

0 commit comments

Comments
 (0)