Skip to content

Commit 44d686b

Browse files
cmagliefacchinm
authored andcommitted
Moved PlatformRewrite* structures in Context
Probably these structures should be renamed to something more meaningful Signed-off-by: Cristian Maglie <[email protected]>
1 parent 62b9782 commit 44d686b

9 files changed

+16
-12
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx
7272
ctx.FoldersWithSourceFiles = &types.UniqueSourceFolderQueue{}
7373

7474
ctx.LibrariesResolutionResults = make(map[string]types.LibraryResolutionResult)
75-
context[constants.CTX_HARDWARE_REWRITE_RESULTS] = make(map[*types.Platform][]types.PlatforKeyRewrite)
75+
ctx.HardwareRewriteResults = make(map[*types.Platform][]types.PlatforKeyRewrite)
7676

7777
return nil
7878
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ const BUILD_PROPERTIES_TOOLS_KEY = "tools"
7474
const BUILD_PROPERTIES_VID = "vid"
7575
const CTAGS = "ctags"
7676
const CTX_FILE_PATH_TO_READ = "filePathToRead"
77-
const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults"
7877
const CTX_INCLUDE_SECTION = "includeSection"
7978
const CTX_INCLUDES_JUST_FOUND = "includesJustFound"
8079
const CTX_LINE_OFFSET = "lineOffset"
81-
const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite"
8280
const EMPTY_STRING = ""
8381
const FILE_BOARDS_LOCAL_TXT = "boards.local.txt"
8482
const FILE_BOARDS_TXT = "boards.txt"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *typ
7979
}
8080
}
8181

82-
context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite
82+
ctx.PlatformKeyRewrites = platformKeysRewrite
8383

8484
return nil
8585
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,18 @@ package builder
3232
import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/types"
35-
"arduino.cc/builder/utils"
3635
)
3736

3837
type RewriteHardwareKeys struct{}
3938

4039
func (s *RewriteHardwareKeys) Run(context map[string]interface{}, ctx *types.Context) error {
41-
if !utils.MapHas(context, constants.CTX_PLATFORM_KEYS_REWRITE) {
40+
if ctx.PlatformKeyRewrites.Empty() {
4241
return nil
4342
}
4443

4544
packages := ctx.Hardware
46-
platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite)
47-
hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite)
45+
platformKeysRewrite := ctx.PlatformKeyRewrites
46+
hardwareRewriteResults := ctx.HardwareRewriteResults
4847

4948
for _, aPackage := range packages.Packages {
5049
for _, platform := range aPackage.Platforms {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestLoadPlatformKeysRewrite(t *testing.T) {
5353
NoError(t, err)
5454
}
5555

56-
platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite)
56+
platformKeysRewrite := ctx.PlatformKeyRewrites
5757

5858
require.Equal(t, 13, len(platformKeysRewrite.Rewrites))
5959
require.Equal(t, constants.BUILD_PROPERTIES_COMPILER_PATH, platformKeysRewrite.Rewrites[0].Key)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestRewriteHardwareKeys(t *testing.T) {
5757

5858
rewrite := types.PlatforKeyRewrite{Key: constants.BUILD_PROPERTIES_COMPILER_PATH, OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"}
5959
platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}}
60-
context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite
60+
ctx.PlatformKeyRewrites = platformKeysRewrite
6161

6262
commands := []types.Command{
6363
&builder.AddAdditionalEntriesToContext{},
@@ -94,7 +94,7 @@ func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) {
9494
rewrite := types.PlatforKeyRewrite{Key: constants.BUILD_PROPERTIES_COMPILER_PATH, OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"}
9595
platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}}
9696

97-
context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite
97+
ctx.PlatformKeyRewrites = platformKeysRewrite
9898

9999
commands := []types.Command{
100100
&builder.AddAdditionalEntriesToContext{},

Diff for: src/arduino.cc/builder/types/context.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ type Context struct {
2828
ActualPlatform *Platform
2929
USBVidPid string
3030

31+
PlatformKeyRewrites PlatforKeysRewrite
32+
HardwareRewriteResults map[*Platform][]PlatforKeyRewrite
33+
3134
BuildProperties props.PropertiesMap
3235
BuildCore string
3336
BuildPath string

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

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ type PlatforKeysRewrite struct {
140140
Rewrites []PlatforKeyRewrite
141141
}
142142

143+
func (p *PlatforKeysRewrite) Empty() bool {
144+
return len(p.Rewrites) == 0
145+
}
146+
143147
type PlatforKeyRewrite struct {
144148
Key string
145149
OldValue string

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}, ctx *typ
4343
}
4444

4545
logger := ctx.GetLogger()
46-
hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite)
46+
hardwareRewriteResults := ctx.HardwareRewriteResults
4747
targetPlatform := ctx.TargetPlatform
4848
actualPlatform := ctx.ActualPlatform
4949

0 commit comments

Comments
 (0)