Skip to content

Commit 8c1b2d8

Browse files
author
Federico Fissore
committed
Fixed broken test in platform_keys_rewrite_loader_test. Also ensuring rewrites
are sorted as they are sorted in the text file Signed-off-by: Federico Fissore <[email protected]>
1 parent b085980 commit 8c1b2d8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"os"
3939
"path/filepath"
4040
"sort"
41+
"strconv"
4142
"strings"
4243
)
4344

@@ -65,11 +66,16 @@ func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}) error {
6566
for _, key := range keys {
6667
keyParts := strings.Split(key, ".")
6768
if keyParts[0] == constants.PLATFORM_REWRITE_OLD {
69+
index, err := strconv.Atoi(keyParts[1])
70+
if err != nil {
71+
return utils.WrapError(err)
72+
}
6873
rewriteKey := strings.Join(keyParts[2:], ".")
6974
oldValue := txt[key]
7075
newValue := txt[constants.PLATFORM_REWRITE_NEW+"."+strings.Join(keyParts[1:], ".")]
7176
platformKeyRewrite := types.PlatforKeyRewrite{Key: rewriteKey, OldValue: oldValue, NewValue: newValue}
72-
platformKeysRewrite.Rewrites = append(platformKeysRewrite.Rewrites, platformKeyRewrite)
77+
platformKeysRewrite.Rewrites = growSliceOfRewrites(platformKeysRewrite.Rewrites, index)
78+
platformKeysRewrite.Rewrites[index] = platformKeyRewrite
7379
}
7480
}
7581

@@ -92,3 +98,12 @@ func findPlatformKeysRewriteTxt(folders []string) (string, error) {
9298

9399
return constants.EMPTY_STRING, nil
94100
}
101+
102+
func growSliceOfRewrites(originalSlice []types.PlatforKeyRewrite, maxIndex int) []types.PlatforKeyRewrite {
103+
if cap(originalSlice) > maxIndex {
104+
return originalSlice
105+
}
106+
newSlice := make([]types.PlatforKeyRewrite, maxIndex+1)
107+
copy(newSlice, originalSlice)
108+
return newSlice
109+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestLoadPlatformKeysRewrite(t *testing.T) {
5454

5555
platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite)
5656

57-
require.Equal(t, 10, len(platformKeysRewrite.Rewrites))
57+
require.Equal(t, 12, len(platformKeysRewrite.Rewrites))
5858
require.Equal(t, constants.BUILD_PROPERTIES_COMPILER_PATH, platformKeysRewrite.Rewrites[0].Key)
5959
require.Equal(t, "{runtime.ide.path}/hardware/tools/avr/bin/", platformKeysRewrite.Rewrites[0].OldValue)
6060
require.Equal(t, "{runtime.tools.avr-gcc.path}/bin/", platformKeysRewrite.Rewrites[0].NewValue)

0 commit comments

Comments
 (0)