Skip to content

Commit da86fe8

Browse files
committed
Introducing types.Context structure
For now it is used in conjunction with the old map[string]string, but it will be slowly populated with all the fields currently used in the map in the next commits. When the migration will be completed the old map will be removed. Signed-off-by: Cristian Maglie <c.maglie@arduino.cc>
1 parent 80849e7 commit da86fe8

File tree

94 files changed

+453
-264
lines changed

Some content is hidden

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

94 files changed

+453
-264
lines changed

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{}) error {
41+
func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx *types.Context) error {
4242
if utils.MapHas(context, constants.CTX_BUILD_PATH) {
4343
buildPath := context[constants.CTX_BUILD_PATH].(string)
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
@@ -39,7 +39,7 @@ import (
3939

4040
type AddBuildBoardPropertyIfMissing struct{}
4141

42-
func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}) error {
42+
func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}, ctx *types.Context) error {
4343
packages := context[constants.CTX_HARDWARE].(*types.Packages)
4444
logger := context[constants.CTX_LOGGER].(i18n.Logger)
4545

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
@@ -37,7 +37,7 @@ import (
3737

3838
type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{}
3939

40-
func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}) error {
40+
func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}, ctx *types.Context) error {
4141
packages := context[constants.CTX_HARDWARE].(*types.Packages)
4242
targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package)
4343
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)

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{}) error {
43+
func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *types.Context) error {
4444
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
4545
sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)
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{}) error {
69+
func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error {
7070
commands := []types.Command{
7171
&SetupHumanLoggerIfMissing{},
7272

@@ -115,14 +115,14 @@ func (s *Builder) Run(context map[string]interface{}) error {
115115
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
116116
}
117117

118-
mainErr := runCommands(context, commands, true)
118+
mainErr := runCommands(context, ctx, commands, true)
119119

120120
commands = []types.Command{
121121
&PrintUsedAndNotUsedLibraries{},
122122

123123
&PrintUsedLibrariesIfVerbose{},
124124
}
125-
otherErr := runCommands(context, commands, false)
125+
otherErr := runCommands(context, ctx, commands, false)
126126

127127
if mainErr != nil {
128128
return mainErr
@@ -133,7 +133,7 @@ func (s *Builder) Run(context map[string]interface{}) error {
133133

134134
type Preprocess struct{}
135135

136-
func (s *Preprocess) Run(context map[string]interface{}) error {
136+
func (s *Preprocess) Run(context map[string]interface{}, ctx *types.Context) error {
137137
commands := []types.Command{
138138
&SetupHumanLoggerIfMissing{},
139139

@@ -157,12 +157,12 @@ func (s *Preprocess) Run(context map[string]interface{}) error {
157157
&PrintPreprocessedSource{},
158158
}
159159

160-
return runCommands(context, commands, true)
160+
return runCommands(context, ctx, commands, true)
161161
}
162162

163163
type ParseHardwareAndDumpBuildProperties struct{}
164164

165-
func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}) error {
165+
func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error {
166166
commands := []types.Command{
167167
&SetupHumanLoggerIfMissing{},
168168

@@ -173,18 +173,18 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}
173173
&DumpBuildProperties{},
174174
}
175175

176-
return runCommands(context, commands, true)
176+
return runCommands(context, ctx, commands, true)
177177
}
178178

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

183183
progress := float32(0)
184184
for _, command := range commands {
185185
PrintRingNameIfDebug(context, command)
186186
printProgressIfProgressEnabledAndMachineLogger(progressEnabled, context, progress)
187-
err := command.Run(context)
187+
err := command.Run(context, ctx)
188188
if err != nil {
189189
return utils.WrapError(err)
190190
}
@@ -213,17 +213,17 @@ func PrintRingNameIfDebug(context map[string]interface{}, command types.Command)
213213
}
214214
}
215215

216-
func RunBuilder(context map[string]interface{}) error {
216+
func RunBuilder(context map[string]interface{}, ctx *types.Context) error {
217217
command := Builder{}
218-
return command.Run(context)
218+
return command.Run(context, ctx)
219219
}
220220

221-
func RunParseHardwareAndDumpBuildProperties(context map[string]interface{}) error {
221+
func RunParseHardwareAndDumpBuildProperties(context map[string]interface{}, ctx *types.Context) error {
222222
command := ParseHardwareAndDumpBuildProperties{}
223-
return command.Run(context)
223+
return command.Run(context, ctx)
224224
}
225225

226-
func RunPreprocess(context map[string]interface{}) error {
226+
func RunPreprocess(context map[string]interface{}, ctx *types.Context) error {
227227
command := Preprocess{}
228-
return command.Run(context)
228+
return command.Run(context, ctx)
229229
}

src/arduino.cc/builder/coan_runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/i18n"
3535
"arduino.cc/builder/props"
36+
"arduino.cc/builder/types"
3637
"arduino.cc/builder/utils"
3738
"fmt"
3839
"path/filepath"
@@ -43,7 +44,7 @@ var ALLOWED_ARG = regexp.MustCompile("^source$|\\-E$|\\-m$|\\-P$|\\-kb$|\\-D.*")
4344

4445
type CoanRunner struct{}
4546

46-
func (s *CoanRunner) Run(context map[string]interface{}) error {
47+
func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) error {
4748
source := context[constants.CTX_SOURCE].(string)
4849
source += "\n"
4950
verbose := context[constants.CTX_VERBOSE].(bool)

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{}) error {
45+
func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]interface{}, ctx *types.Context) error {
4646
foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue)
4747
sourceFiles := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue)
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
@@ -38,7 +38,7 @@ import (
3838

3939
type CollectCTagsFromSketchFiles struct{}
4040

41-
func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}) error {
41+
func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *types.Context) error {
4242
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
4343
sketchFileNames := collectSketchFileNamesFrom(sketch)
4444

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

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

src/arduino.cc/builder/container_build_options.go

Lines changed: 2 additions & 2 deletions
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{}) error {
39+
func (s *ContainerBuildOptions) Run(context map[string]interface{}, ctx *types.Context) error {
4040
commands := []types.Command{
4141
&CreateBuildOptionsMap{},
4242
&LoadPreviousBuildOptionsMap{},
@@ -46,7 +46,7 @@ func (s *ContainerBuildOptions) Run(context map[string]interface{}) error {
4646

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

src/arduino.cc/builder/container_find_includes.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ import (
3838

3939
type ContainerFindIncludes struct{}
4040

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

4747
sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)
4848
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
49-
err = findIncludesUntilDone(context, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"))
49+
err = findIncludesUntilDone(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"))
5050
if err != nil {
5151
return utils.WrapError(err)
5252
}
@@ -62,42 +62,42 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
6262
}
6363
}
6464

65-
err = runCommand(context, &CollectAllSourceFilesFromFoldersWithSources{})
65+
err = runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{})
6666
if err != nil {
6767
return utils.WrapError(err)
6868
}
6969

7070
sourceFilePaths := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue)
7171

7272
for !sourceFilePaths.Empty() {
73-
err = findIncludesUntilDone(context, sourceFilePaths.Pop().(string))
73+
err = findIncludesUntilDone(context, ctx, sourceFilePaths.Pop().(string))
7474
if err != nil {
7575
return utils.WrapError(err)
7676
}
77-
err := runCommand(context, &CollectAllSourceFilesFromFoldersWithSources{})
77+
err := runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{})
7878
if err != nil {
7979
return utils.WrapError(err)
8080
}
8181
}
8282

83-
err = runCommand(context, &FailIfImportedLibraryIsWrong{})
83+
err = runCommand(context, ctx, &FailIfImportedLibraryIsWrong{})
8484
if err != nil {
8585
return utils.WrapError(err)
8686
}
8787

8888
return nil
8989
}
9090

91-
func runCommand(context map[string]interface{}, command types.Command) error {
91+
func runCommand(context map[string]interface{}, ctx *types.Context, command types.Command) error {
9292
PrintRingNameIfDebug(context, command)
93-
err := command.Run(context)
93+
err := command.Run(context, ctx)
9494
if err != nil {
9595
return utils.WrapError(err)
9696
}
9797
return nil
9898
}
9999

100-
func findIncludesUntilDone(context map[string]interface{}, sourceFilePath string) error {
100+
func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, sourceFilePath string) error {
101101
targetFilePath := utils.NULLFile()
102102
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
103103
done := false
@@ -108,15 +108,15 @@ func findIncludesUntilDone(context map[string]interface{}, sourceFilePath string
108108
&IncludesToIncludeFolders{},
109109
}
110110
for _, command := range commands {
111-
err := runCommand(context, command)
111+
err := runCommand(context, ctx, command)
112112
if err != nil {
113113
return utils.WrapError(err)
114114
}
115115
}
116116
if len(context[constants.CTX_INCLUDES_JUST_FOUND].([]string)) == 0 {
117117
done = true
118118
} else if len(context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)) == len(importedLibraries) {
119-
err := runCommand(context, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
119+
err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
120120
return utils.WrapError(err)
121121
}
122122
importedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)

src/arduino.cc/builder/container_merge_copy_sketch_files.go

Lines changed: 2 additions & 2 deletions
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{}) error {
39+
func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}, ctx *types.Context) error {
4040
commands := []types.Command{
4141
&SketchSourceMerger{},
4242
&SketchSaver{},
@@ -45,7 +45,7 @@ func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}) erro
4545

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

src/arduino.cc/builder/container_setup.go

Lines changed: 2 additions & 2 deletions
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{}) error {
39+
func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]interface{}, 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(context, command)
59-
err := command.Run(context)
59+
err := command.Run(context, ctx)
6060
if err != nil {
6161
return utils.WrapError(err)
6262
}

src/arduino.cc/builder/create_build_options_map.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package builder
3131

3232
import (
3333
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/types"
3435
"arduino.cc/builder/utils"
3536
"encoding/json"
3637
"reflect"
@@ -39,7 +40,7 @@ import (
3940

4041
type CreateBuildOptionsMap struct{}
4142

42-
func (s *CreateBuildOptionsMap) Run(context map[string]interface{}) error {
43+
func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error {
4344
buildOptions := make(map[string]string)
4445

4546
buildOptionsMapKeys := []string{

src/arduino.cc/builder/ctags/ctags_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var KNOWN_TAG_KINDS = map[string]bool{
5757

5858
type CTagsParser struct{}
5959

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

6363
rows = removeEmpty(rows)

src/arduino.cc/builder/ctags/ctags_runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/i18n"
3535
"arduino.cc/builder/props"
36+
"arduino.cc/builder/types"
3637
"arduino.cc/builder/utils"
3738
"fmt"
3839
)
3940

4041
type CTagsRunner struct{}
4142

42-
func (s *CTagsRunner) Run(context map[string]interface{}) error {
43+
func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) error {
4344
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
4445
ctagsTargetFilePath := context[constants.CTX_CTAGS_TEMP_FILE_PATH].(string)
4546
logger := context[constants.CTX_LOGGER].(i18n.Logger)

src/arduino.cc/builder/ctags/ctags_to_prototypes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
type CTagsToPrototypes struct{}
3939

40-
func (s *CTagsToPrototypes) Run(context map[string]interface{}) error {
40+
func (s *CTagsToPrototypes) Run(context map[string]interface{}, ctx *types.Context) error {
4141
tags := context[constants.CTX_COLLECTED_CTAGS].([]*types.CTag)
4242

4343
lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes(tags)

src/arduino.cc/builder/ctags_target_file_saver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package builder
3131

3232
import (
3333
"arduino.cc/builder/constants"
34+
"arduino.cc/builder/types"
3435
"arduino.cc/builder/utils"
3536
"path/filepath"
3637
)
@@ -40,7 +41,7 @@ type CTagsTargetFileSaver struct {
4041
TargetFileName string
4142
}
4243

43-
func (s *CTagsTargetFileSaver) Run(context map[string]interface{}) error {
44+
func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Context) error {
4445
source := context[s.SourceField].(string)
4546

4647
preprocPath := context[constants.CTX_PREPROC_PATH].(string)

0 commit comments

Comments
 (0)