Skip to content

Commit 42d0550

Browse files
cmagliefacchinm
authored andcommitted
Migrated all buildProperties into types.Context
Still missing the refactoring of main.go that will be done in one of the next commits Signed-off-by: Cristian Maglie <[email protected]>
1 parent 3dcdbe5 commit 42d0550

38 files changed

+806
-732
lines changed

src/arduino.cc/builder/constants/constants.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const BUILD_PROPERTIES_RUNTIME_OS = "runtime.os"
6666
const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path"
6767
const BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX = "runtime.tools."
6868
const BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX = ".path"
69+
const BUILD_PROPERTIES_RUNTIME_IDE_VERSION = "runtime.ide.version"
6970
const BUILD_PROPERTIES_SOFTWARE = "software"
7071
const BUILD_PROPERTIES_SOURCE_FILE = "source_file"
7172
const BUILD_PROPERTIES_SOURCE_PATH = "build.source.path"
@@ -81,24 +82,19 @@ const CTX_BUILD_OPTIONS_JSON = "buildOptionsJson"
8182
const CTX_BUILD_OPTIONS_PREVIOUS_JSON = "buildOptionsPreviousJson"
8283
const CTX_BUILD_PATH = "buildPath"
8384
const CTX_BUILD_PROPERTIES = "buildProperties"
84-
const CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION = "runtime.ide.version"
85-
const CTX_BUILT_IN_LIBRARIES_FOLDERS = "builtInLibrariesFolders"
8685
const CTX_COLLECTED_CTAGS = "collectedCTags"
8786
const CTX_COLLECTED_SOURCE_FILES_QUEUE = "collectedSourceFilesQueue"
8887
const CTX_CORE_BUILD_PATH = "coreBuildPath"
8988
const CTX_CTAGS_OF_PREPROC_SOURCE = "ctagsOfPreprocSource"
9089
const CTX_CTAGS_OF_SOURCE = "ctagsOfSource"
9190
const CTX_CTAGS_OUTPUT = "ctagsOutput"
9291
const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath"
93-
const CTX_CUSTOM_BUILD_PROPERTIES = "customBuildProperties"
9492
const CTX_DEBUG_LEVEL = "debugLevel"
9593
const CTX_DEBUG_PREPROCESSOR = "debugPreprocessor"
9694
const CTX_FILE_PATH_TO_READ = "filePathToRead"
9795
const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue"
98-
const CTX_FQBN = "fqbn"
9996
const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource"
10097
const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput"
101-
const CTX_HARDWARE_FOLDERS = "hardwareFolders"
10298
const CTX_HARDWARE = "hardware"
10399
const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults"
104100
const CTX_HEADER_TO_LIBRARIES = "headerToLibraries"
@@ -108,7 +104,6 @@ const CTX_INCLUDE_SECTION = "includeSection"
108104
const CTX_INCLUDES = "includes"
109105
const CTX_INCLUDES_JUST_FOUND = "includesJustFound"
110106
const CTX_LIBRARIES_BUILD_PATH = "librariesBuildPath"
111-
const CTX_LIBRARIES_FOLDERS = "librariesFolders"
112107
const CTX_LIBRARIES = "libraries"
113108
const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults"
114109
const CTX_LINE_OFFSET = "lineOffset"
@@ -117,19 +112,16 @@ const CTX_LOGGER = "logger"
117112
const CTX_OBJECT_FILES_CORE = "objectFilesCore"
118113
const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries"
119114
const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch"
120-
const CTX_OTHER_LIBRARIES_FOLDERS = "otherLibrariesFolders"
121115
const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite"
122116
const CTX_PREPROC_PATH = "preprocPath"
123117
const CTX_PROTOTYPE_SECTION = "prototypeSection"
124118
const CTX_PROTOTYPES = "prototypes"
125119
const CTX_SKETCH_BUILD_PATH = "sketchBuildPath"
126-
const CTX_SKETCH_LOCATION = "sketchLocation"
127120
const CTX_SKETCH = "sketch"
128121
const CTX_SOURCE = "source"
129122
const CTX_TARGET_BOARD = "targetBoard"
130123
const CTX_TARGET_PACKAGE = "targetPackage"
131124
const CTX_TARGET_PLATFORM = "targetPlatform"
132-
const CTX_TOOLS_FOLDERS = "toolsFolders"
133125
const CTX_TOOLS = "tools"
134126
const CTX_VERBOSE = "verbose"
135127
const CTX_VIDPID = "VIDPID"

src/arduino.cc/builder/create_build_options_map.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,12 @@ import (
3434
"arduino.cc/builder/types"
3535
"arduino.cc/builder/utils"
3636
"encoding/json"
37-
"reflect"
38-
"strings"
3937
)
4038

4139
type CreateBuildOptionsMap struct{}
4240

4341
func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error {
44-
buildOptions := make(map[string]string)
45-
46-
buildOptionsMapKeys := []string{
47-
constants.CTX_HARDWARE_FOLDERS,
48-
constants.CTX_TOOLS_FOLDERS,
49-
constants.CTX_BUILT_IN_LIBRARIES_FOLDERS,
50-
constants.CTX_OTHER_LIBRARIES_FOLDERS,
51-
constants.CTX_FQBN,
52-
constants.CTX_SKETCH_LOCATION,
53-
constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION,
54-
constants.CTX_CUSTOM_BUILD_PROPERTIES,
55-
}
56-
57-
for _, key := range buildOptionsMapKeys {
58-
if utils.MapHas(context, key) {
59-
originalValue := context[key]
60-
value := constants.EMPTY_STRING
61-
kindOfValue := reflect.TypeOf(originalValue).Kind()
62-
if kindOfValue == reflect.Slice {
63-
value = strings.Join(originalValue.([]string), ",")
64-
} else if kindOfValue == reflect.String {
65-
value = originalValue.(string)
66-
} else {
67-
return utils.Errorf(context, constants.MSG_UNHANDLED_TYPE_IN_CONTEXT, kindOfValue.String(), key)
68-
}
69-
70-
buildOptions[key] = value
71-
}
72-
}
73-
42+
buildOptions := ctx.ExtractBuildOptions()
7443
context[constants.CTX_BUILD_OPTIONS] = buildOptions
7544

7645
bytes, err := json.MarshalIndent(buildOptions, "", " ")

src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
type FailIfBuildPathEqualsSketchPath struct{}
4040

4141
func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ctx *types.Context) error {
42-
if !utils.MapHas(context, constants.CTX_BUILD_PATH) || !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) {
42+
if !utils.MapHas(context, constants.CTX_BUILD_PATH) || ctx.SketchLocation == "" {
4343
return nil
4444
}
4545

@@ -48,7 +48,7 @@ func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ct
4848
return utils.WrapError(err)
4949
}
5050

51-
sketchPath, err := filepath.Abs(context[constants.CTX_SKETCH_LOCATION].(string))
51+
sketchPath, err := filepath.Abs(ctx.SketchLocation)
5252
if err != nil {
5353
return utils.WrapError(err)
5454
}

src/arduino.cc/builder/generate_buildpath_if_missing.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}, ctx *ty
4646
return nil
4747
}
4848

49-
sketchLocation := context[constants.CTX_SKETCH_LOCATION].(string)
50-
md5sum := utils.MD5Sum([]byte(sketchLocation))
49+
md5sum := utils.MD5Sum([]byte(ctx.SketchLocation))
5150

5251
buildPath := filepath.Join(os.TempDir(), "arduino-sketch-"+strings.ToUpper(md5sum))
5352
_, err := os.Stat(buildPath)

src/arduino.cc/builder/hardware_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context)
4848
packages.Packages = make(map[string]*types.Package)
4949
packages.Properties = make(map[string]string)
5050

51-
folders := context[constants.CTX_HARDWARE_FOLDERS].([]string)
51+
folders := ctx.HardwareFolders
5252
folders, err := utils.AbsolutizePaths(folders)
5353
if err != nil {
5454
return utils.WrapError(err)

src/arduino.cc/builder/libraries_loader.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,12 @@ import (
4343
type LibrariesLoader struct{}
4444

4545
func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context) error {
46-
sortedLibrariesFolders := []string{}
47-
48-
builtInLibrariesFolders := []string{}
49-
if utils.MapHas(context, constants.CTX_BUILT_IN_LIBRARIES_FOLDERS) {
50-
builtInLibrariesFolders = context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS].([]string)
51-
}
46+
builtInLibrariesFolders := ctx.BuiltInLibrariesFolders
5247
builtInLibrariesFolders, err := utils.AbsolutizePaths(builtInLibrariesFolders)
5348
if err != nil {
5449
return utils.WrapError(err)
5550
}
51+
sortedLibrariesFolders := []string{}
5652
sortedLibrariesFolders = utils.AppendIfNotPresent(sortedLibrariesFolders, builtInLibrariesFolders...)
5753

5854
platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform)
@@ -66,17 +62,14 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context
6662

6763
sortedLibrariesFolders = appendPathToLibrariesFolders(sortedLibrariesFolders, filepath.Join(platform.Folder, constants.FOLDER_LIBRARIES))
6864

69-
librariesFolders := []string{}
70-
if utils.MapHas(context, constants.CTX_OTHER_LIBRARIES_FOLDERS) {
71-
librariesFolders = context[constants.CTX_OTHER_LIBRARIES_FOLDERS].([]string)
72-
}
65+
librariesFolders := ctx.OtherLibrariesFolders
7366
librariesFolders, err = utils.AbsolutizePaths(librariesFolders)
7467
if err != nil {
7568
return utils.WrapError(err)
7669
}
7770
sortedLibrariesFolders = utils.AppendIfNotPresent(sortedLibrariesFolders, librariesFolders...)
7871

79-
context[constants.CTX_LIBRARIES_FOLDERS] = sortedLibrariesFolders
72+
ctx.LibrariesFolders = sortedLibrariesFolders
8073

8174
var libraries []*types.Library
8275
for _, libraryFolder := range sortedLibrariesFolders {

src/arduino.cc/builder/platform_keys_rewrite_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type PlatformKeysRewriteLoader struct{}
4646

4747
func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *types.Context) error {
4848
logger := context[constants.CTX_LOGGER].(i18n.Logger)
49-
folders := context[constants.CTX_HARDWARE_FOLDERS].([]string)
49+
folders := ctx.HardwareFolders
5050

5151
platformKeysRewriteTxtPath, err := findPlatformKeysRewriteTxt(folders)
5252
if err != nil {

src/arduino.cc/builder/set_custom_build_properties.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@ import (
4040
type SetCustomBuildProperties struct{}
4141

4242
func (s *SetCustomBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error {
43-
if !utils.MapHas(context, constants.CTX_CUSTOM_BUILD_PROPERTIES) {
44-
return nil
45-
}
46-
4743
logger := context[constants.CTX_LOGGER].(i18n.Logger)
4844
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
49-
customBuildProperties, err := props.LoadFromSlice(context[constants.CTX_CUSTOM_BUILD_PROPERTIES].([]string), logger)
45+
customBuildProperties, err := props.LoadFromSlice(ctx.CustomBuildProperties, logger)
5046
if err != nil {
5147
return utils.WrapError(err)
5248
}

src/arduino.cc/builder/setup_build_properties.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co
6767
buildProperties[constants.BUILD_PROPERTIES_BUILD_SYSTEM_PATH] = filepath.Join(actualPlatform.Folder, constants.FOLDER_SYSTEM)
6868
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH] = targetPlatform.Folder
6969
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH] = filepath.Join(targetPlatform.Folder, "..")
70-
buildProperties[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION].(string)
71-
buildProperties[constants.IDE_VERSION] = context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION].(string)
70+
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = ctx.ArduinoAPIVersion
71+
buildProperties[constants.IDE_VERSION] = ctx.ArduinoAPIVersion
7272
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS] = utils.PrettyOSName()
7373

7474
variant := buildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT]
@@ -96,8 +96,8 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co
9696
buildProperties[constants.BUILD_PROPERTIES_SOFTWARE] = DEFAULT_SOFTWARE
9797
}
9898

99-
if utils.MapHas(context, constants.CTX_SKETCH_LOCATION) {
100-
sourcePath, err := filepath.Abs(context[constants.CTX_SKETCH_LOCATION].(string))
99+
if ctx.SketchLocation != "" {
100+
sourcePath, err := filepath.Abs(ctx.SketchLocation)
101101
if err != nil {
102102
return err
103103
}

src/arduino.cc/builder/sketch_loader.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ import (
4545
type SketchLoader struct{}
4646

4747
func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) error {
48-
if !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) {
48+
if ctx.SketchLocation == "" {
4949
return nil
5050
}
5151

52-
sketchLocation := context[constants.CTX_SKETCH_LOCATION].(string)
52+
sketchLocation := ctx.SketchLocation
5353

5454
sketchLocation, err := filepath.Abs(sketchLocation)
5555
if err != nil {
@@ -62,7 +62,8 @@ func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) e
6262
if mainSketchStat.IsDir() {
6363
sketchLocation = filepath.Join(sketchLocation, mainSketchStat.Name()+".ino")
6464
}
65-
context[constants.CTX_SKETCH_LOCATION] = sketchLocation
65+
66+
ctx.SketchLocation = sketchLocation
6667

6768
allSketchFilePaths, err := collectAllSketchFiles(filepath.Dir(sketchLocation))
6869
if err != nil {
@@ -79,7 +80,7 @@ func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) e
7980
return utils.WrapError(err)
8081
}
8182

82-
context[constants.CTX_SKETCH_LOCATION] = sketchLocation
83+
ctx.SketchLocation = sketchLocation
8384
context[constants.CTX_SKETCH] = sketch
8485

8586
return nil

0 commit comments

Comments
 (0)