Skip to content

Commit e6f25db

Browse files
committed
Removed context map[string]interface{}
This commit concludes the refactoring. Signed-off-by: Cristian Maglie <[email protected]>
1 parent 8b74855 commit e6f25db

File tree

99 files changed

+292
-515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+292
-515
lines changed

Diff for: src/arduino.cc/arduino-builder/main.go

+3-23
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ func main() {
169169
return
170170
}
171171

172-
context := make(map[string]interface{})
173172
ctx := &types.Context{}
174173

175174
if *buildOptionsFileFlag != "" {
@@ -305,16 +304,16 @@ func main() {
305304
}
306305

307306
if *dumpPrefsFlag {
308-
err = builder.RunParseHardwareAndDumpBuildProperties(context, ctx)
307+
err = builder.RunParseHardwareAndDumpBuildProperties(ctx)
309308
} else if *preprocessFlag {
310-
err = builder.RunPreprocess(context, ctx)
309+
err = builder.RunPreprocess(ctx)
311310
} else {
312311
if flag.NArg() == 0 {
313312
fmt.Fprintln(os.Stderr, "Last parameter must be the sketch to compile")
314313
flag.Usage()
315314
os.Exit(1)
316315
}
317-
err = builder.RunBuilder(context, ctx)
316+
err = builder.RunBuilder(ctx)
318317
}
319318

320319
if err != nil {
@@ -330,25 +329,6 @@ func main() {
330329
}
331330
}
332331

333-
func setContextSliceKeyOrLoadItFromOptions(context map[string]interface{}, cliFlag []string, buildOptions map[string]string, contextKey string, paramName string, mandatory bool) (error, bool) {
334-
values, err := toSliceOfUnquoted(cliFlag)
335-
if err != nil {
336-
return err, true
337-
}
338-
339-
if len(values) == 0 && len(buildOptions[contextKey]) > 0 {
340-
values = strings.Split(buildOptions[contextKey], ",")
341-
}
342-
343-
if mandatory && len(values) == 0 {
344-
return errors.New("Parameter '" + paramName + "' is mandatory"), false
345-
}
346-
347-
context[contextKey] = values
348-
349-
return nil, false
350-
}
351-
352332
func toExitCode(err error) int {
353333
if exiterr, ok := err.(*exec.ExitError); ok {
354334
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838

3939
type AddAdditionalEntriesToContext struct{}
4040

41-
func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx *types.Context) error {
41+
func (s *AddAdditionalEntriesToContext) Run(ctx *types.Context) error {
4242
if ctx.BuildPath != "" {
4343
buildPath := ctx.BuildPath
4444
preprocPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_PREPROC))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838

3939
type AddBuildBoardPropertyIfMissing struct{}
4040

41-
func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}, ctx *types.Context) error {
41+
func (s *AddBuildBoardPropertyIfMissing) Run(ctx *types.Context) error {
4242
packages := ctx.Hardware
4343
logger := ctx.GetLogger()
4444

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535

3636
type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{}
3737

38-
func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}, ctx *types.Context) error {
38+
func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(ctx *types.Context) error {
3939
packages := ctx.Hardware
4040
targetPackage := ctx.TargetPackage
4141
buildProperties := ctx.BuildProperties

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040

4141
type AdditionalSketchFilesCopier struct{}
4242

43-
func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *types.Context) error {
43+
func (s *AdditionalSketchFilesCopier) Run(ctx *types.Context) error {
4444
sketch := ctx.Sketch
4545
sketchBuildPath := ctx.SketchBuildPath
4646

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const DEFAULT_BUILD_CORE = "arduino"
6666

6767
type Builder struct{}
6868

69-
func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error {
69+
func (s *Builder) Run(ctx *types.Context) error {
7070
commands := []types.Command{
7171
&GenerateBuildPathIfMissing{},
7272
&EnsureBuildPathExists{},
@@ -113,14 +113,14 @@ func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error
113113
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
114114
}
115115

116-
mainErr := runCommands(context, ctx, commands, true)
116+
mainErr := runCommands(ctx, commands, true)
117117

118118
commands = []types.Command{
119119
&PrintUsedAndNotUsedLibraries{},
120120

121121
&PrintUsedLibrariesIfVerbose{},
122122
}
123-
otherErr := runCommands(context, ctx, commands, false)
123+
otherErr := runCommands(ctx, commands, false)
124124

125125
if mainErr != nil {
126126
return mainErr
@@ -131,7 +131,7 @@ func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error
131131

132132
type Preprocess struct{}
133133

134-
func (s *Preprocess) Run(context map[string]interface{}, ctx *types.Context) error {
134+
func (s *Preprocess) Run(ctx *types.Context) error {
135135
commands := []types.Command{
136136
&GenerateBuildPathIfMissing{},
137137
&EnsureBuildPathExists{},
@@ -153,12 +153,12 @@ func (s *Preprocess) Run(context map[string]interface{}, ctx *types.Context) err
153153
&PrintPreprocessedSource{},
154154
}
155155

156-
return runCommands(context, ctx, commands, true)
156+
return runCommands(ctx, commands, true)
157157
}
158158

159159
type ParseHardwareAndDumpBuildProperties struct{}
160160

161-
func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error {
161+
func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error {
162162
commands := []types.Command{
163163
&GenerateBuildPathIfMissing{},
164164

@@ -167,18 +167,18 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}
167167
&DumpBuildProperties{},
168168
}
169169

170-
return runCommands(context, ctx, commands, true)
170+
return runCommands(ctx, commands, true)
171171
}
172172

173-
func runCommands(context map[string]interface{}, ctx *types.Context, commands []types.Command, progressEnabled bool) error {
173+
func runCommands(ctx *types.Context, commands []types.Command, progressEnabled bool) error {
174174
commandsLength := len(commands)
175175
progressForEachCommand := float32(100) / float32(commandsLength)
176176

177177
progress := float32(0)
178178
for _, command := range commands {
179179
PrintRingNameIfDebug(ctx, command)
180180
printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, progress)
181-
err := command.Run(context, ctx)
181+
err := command.Run(ctx)
182182
if err != nil {
183183
return i18n.WrapError(err)
184184
}
@@ -207,17 +207,17 @@ func PrintRingNameIfDebug(ctx *types.Context, command types.Command) {
207207
}
208208
}
209209

210-
func RunBuilder(context map[string]interface{}, ctx *types.Context) error {
210+
func RunBuilder(ctx *types.Context) error {
211211
command := Builder{}
212-
return command.Run(context, ctx)
212+
return command.Run(ctx)
213213
}
214214

215-
func RunParseHardwareAndDumpBuildProperties(context map[string]interface{}, ctx *types.Context) error {
215+
func RunParseHardwareAndDumpBuildProperties(ctx *types.Context) error {
216216
command := ParseHardwareAndDumpBuildProperties{}
217-
return command.Run(context, ctx)
217+
return command.Run(ctx)
218218
}
219219

220-
func RunPreprocess(context map[string]interface{}, ctx *types.Context) error {
220+
func RunPreprocess(ctx *types.Context) error {
221221
command := Preprocess{}
222-
return command.Run(context, ctx)
222+
return command.Run(ctx)
223223
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242

4343
type CollectAllSourceFilesFromFoldersWithSources struct{}
4444

45-
func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]interface{}, ctx *types.Context) error {
45+
func (s *CollectAllSourceFilesFromFoldersWithSources) Run(ctx *types.Context) error {
4646
foldersWithSources := ctx.FoldersWithSourceFiles
4747
sourceFiles := ctx.CollectedSourceFiles
4848

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
type CollectCTagsFromSketchFiles struct{}
3939

40-
func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *types.Context) error {
40+
func (s *CollectCTagsFromSketchFiles) Run(ctx *types.Context) error {
4141
sketchFileNames := collectSketchFileNamesFrom(ctx.Sketch)
4242

4343
allCtags := ctx.CTagsOfPreprocessedSource

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929

3030
package builder
3131

32+
// XXX: Obsolete?
33+
3234
import "arduino.cc/builder/types"
3335

3436
type ComparePrototypesFromSourceAndPreprocSource struct{}
3537

36-
func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]interface{}, ctx *types.Context) error {
38+
func (s *ComparePrototypesFromSourceAndPreprocSource) Run(ctx *types.Context) error {
3739
ctagsOfSource := ctx.CTagsOfSource
3840
ctagsOfPreprocSource := ctx.CTagsOfPreprocessedSource
3941

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838

3939
type ContainerAddPrototypes struct{}
4040

41-
func (s *ContainerAddPrototypes) Run(context map[string]interface{}, ctx *types.Context) error {
41+
func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
4242
commands := []types.Command{
4343
&GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
4444
&ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE},
@@ -53,7 +53,7 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}, ctx *types.
5353

5454
for _, command := range commands {
5555
PrintRingNameIfDebug(ctx, command)
56-
err := command.Run(context, ctx)
56+
err := command.Run(ctx)
5757
if err != nil {
5858
return i18n.WrapError(err)
5959
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
type ContainerBuildOptions struct{}
3838

39-
func (s *ContainerBuildOptions) Run(context map[string]interface{}, ctx *types.Context) error {
39+
func (s *ContainerBuildOptions) Run(ctx *types.Context) error {
4040
commands := []types.Command{
4141
&CreateBuildOptionsMap{},
4242
&LoadPreviousBuildOptionsMap{},
@@ -46,7 +46,7 @@ func (s *ContainerBuildOptions) Run(context map[string]interface{}, ctx *types.C
4646

4747
for _, command := range commands {
4848
PrintRingNameIfDebug(ctx, command)
49-
err := command.Run(context, ctx)
49+
err := command.Run(ctx)
5050
if err != nil {
5151
return i18n.WrapError(err)
5252
}

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ import (
3939

4040
type ContainerFindIncludes struct{}
4141

42-
func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.Context) error {
43-
err := runCommand(context, ctx, &IncludesToIncludeFolders{})
42+
func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
43+
err := runCommand(ctx, &IncludesToIncludeFolders{})
4444
if err != nil {
4545
return i18n.WrapError(err)
4646
}
4747

4848
sketchBuildPath := ctx.SketchBuildPath
4949
sketch := ctx.Sketch
50-
err = findIncludesUntilDone(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"))
50+
err = findIncludesUntilDone(ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"))
5151
if err != nil {
5252
return i18n.WrapError(err)
5353
}
@@ -63,42 +63,42 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C
6363
}
6464
}
6565

66-
err = runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{})
66+
err = runCommand(ctx, &CollectAllSourceFilesFromFoldersWithSources{})
6767
if err != nil {
6868
return i18n.WrapError(err)
6969
}
7070

7171
sourceFilePaths := ctx.CollectedSourceFiles
7272

7373
for !sourceFilePaths.Empty() {
74-
err = findIncludesUntilDone(context, ctx, sourceFilePaths.Pop().(string))
74+
err = findIncludesUntilDone(ctx, sourceFilePaths.Pop().(string))
7575
if err != nil {
7676
return i18n.WrapError(err)
7777
}
78-
err := runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{})
78+
err := runCommand(ctx, &CollectAllSourceFilesFromFoldersWithSources{})
7979
if err != nil {
8080
return i18n.WrapError(err)
8181
}
8282
}
8383

84-
err = runCommand(context, ctx, &FailIfImportedLibraryIsWrong{})
84+
err = runCommand(ctx, &FailIfImportedLibraryIsWrong{})
8585
if err != nil {
8686
return i18n.WrapError(err)
8787
}
8888

8989
return nil
9090
}
9191

92-
func runCommand(context map[string]interface{}, ctx *types.Context, command types.Command) error {
92+
func runCommand(ctx *types.Context, command types.Command) error {
9393
PrintRingNameIfDebug(ctx, command)
94-
err := command.Run(context, ctx)
94+
err := command.Run(ctx)
9595
if err != nil {
9696
return i18n.WrapError(err)
9797
}
9898
return nil
9999
}
100100

101-
func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, sourceFilePath string) error {
101+
func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error {
102102
targetFilePath := utils.NULLFile()
103103
importedLibraries := ctx.ImportedLibraries
104104
done := false
@@ -109,15 +109,15 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s
109109
&IncludesToIncludeFolders{},
110110
}
111111
for _, command := range commands {
112-
err := runCommand(context, ctx, command)
112+
err := runCommand(ctx, command)
113113
if err != nil {
114114
return i18n.WrapError(err)
115115
}
116116
}
117117
if len(ctx.IncludesJustFound) == 0 {
118118
done = true
119119
} else if len(ctx.ImportedLibraries) == len(importedLibraries) {
120-
err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
120+
err := runCommand(ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
121121
return i18n.WrapError(err)
122122
}
123123
importedLibraries = ctx.ImportedLibraries

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
type ContainerMergeCopySketchFiles struct{}
3838

39-
func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}, ctx *types.Context) error {
39+
func (s *ContainerMergeCopySketchFiles) Run(ctx *types.Context) error {
4040
commands := []types.Command{
4141
&SketchSourceMerger{},
4242
&SketchSaver{},
@@ -45,7 +45,7 @@ func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}, ctx
4545

4646
for _, command := range commands {
4747
PrintRingNameIfDebug(ctx, command)
48-
err := command.Run(context, ctx)
48+
err := command.Run(ctx)
4949
if err != nil {
5050
return i18n.WrapError(err)
5151
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
type ContainerSetupHardwareToolsLibsSketchAndProps struct{}
3838

39-
func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]interface{}, ctx *types.Context) error {
39+
func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) error {
4040
commands := []types.Command{
4141
&AddAdditionalEntriesToContext{},
4242
&FailIfBuildPathEqualsSketchPath{},
@@ -56,7 +56,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]i
5656

5757
for _, command := range commands {
5858
PrintRingNameIfDebug(ctx, command)
59-
err := command.Run(context, ctx)
59+
err := command.Run(ctx)
6060
if err != nil {
6161
return i18n.WrapError(err)
6262
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
type CreateBuildOptionsMap struct{}
3939

40-
func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error {
40+
func (s *CreateBuildOptionsMap) Run(ctx *types.Context) error {
4141
buildOptions := ctx.ExtractBuildOptions()
4242
bytes, err := json.MarshalIndent(buildOptions, "", " ")
4343
if err != nil {

Diff for: src/arduino.cc/builder/ctags/ctags_parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var KNOWN_TAG_KINDS = map[string]bool{
5656

5757
type CTagsParser struct{}
5858

59-
func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) error {
59+
func (s *CTagsParser) Run(ctx *types.Context) error {
6060
rows := strings.Split(ctx.CTagsOutput, "\n")
6161

6262
rows = removeEmpty(rows)

0 commit comments

Comments
 (0)