Skip to content

Commit e10fcc8

Browse files
committed
Removed context map[string]interface{}
This commit concludes the refactoring. Signed-off-by: Cristian Maglie <c.maglie@arduino.cc>
1 parent c1014b8 commit e10fcc8

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

src/arduino.cc/arduino-builder/main.go

Lines changed: 3 additions & 23 deletions
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 {

src/arduino.cc/builder/add_additional_entries_to_context.go

Lines changed: 1 addition & 1 deletion
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))

src/arduino.cc/builder/add_build_board_property_if_missing.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/additional_sketch_files_copier.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/builder.go

Lines changed: 15 additions & 15 deletions
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
}

src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/collect_ctags_from_sketch_files.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go

Lines changed: 3 additions & 1 deletion
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

src/arduino.cc/builder/container_add_prototypes.go

Lines changed: 2 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)