Skip to content

Commit 67a198f

Browse files
committed
Moved Source and SourceGccMinusE into Context
Some helper "Command" now accepts directly the address of the target string to work on instead of the key of the context map that contains the string. Those "arguments" are, I guess, legacy from old preprocessing and library discovery and IMHO they can be removed with a bit of refactoring. Anyway, I've intentionally limited the scope of this commit and left further optimization for the future. Signed-off-by: Cristian Maglie <c.maglie@arduino.cc>
1 parent 7520e66 commit 67a198f

20 files changed

+63
-74
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ const CTAGS = "ctags"
7676
const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore"
7777
const CTX_BUILD_CORE = "buildCore"
7878
const CTX_FILE_PATH_TO_READ = "filePathToRead"
79-
const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource"
8079
const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput"
8180
const CTX_HARDWARE = "hardware"
8281
const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults"
@@ -87,7 +86,6 @@ const CTX_OBJECT_FILES_CORE = "objectFilesCore"
8786
const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries"
8887
const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch"
8988
const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite"
90-
const CTX_SOURCE = "source"
9189
const CTX_TOOLS = "tools"
9290
const CTX_VIDPID = "VIDPID"
9391
const EMPTY_STRING = ""

src/arduino.cc/builder/container_add_prototypes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type ContainerAddPrototypes struct{}
4141
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},
44-
&ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE},
45-
&CTagsTargetFileSaver{SourceField: constants.CTX_GCC_MINUS_E_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
44+
&ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE},
45+
&CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},
4646
&ctags.CTagsRunner{},
4747
&ctags.CTagsParser{},
4848
&CollectCTagsFromSketchFiles{},

src/arduino.cc/builder/container_find_includes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s
105105
for !done {
106106
commands := []types.Command{
107107
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath},
108-
&IncludesFinderWithRegExp{ContextField: constants.CTX_GCC_MINUS_E_SOURCE},
108+
&IncludesFinderWithRegExp{Source: &ctx.SourceGccMinusE},
109109
&IncludesToIncludeFolders{},
110110
}
111111
for _, command := range commands {

src/arduino.cc/builder/ctags_target_file_saver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ import (
3737
)
3838

3939
type CTagsTargetFileSaver struct {
40-
SourceField string
40+
Source *string
4141
TargetFileName string
4242
}
4343

4444
func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Context) error {
45-
source := context[s.SourceField].(string)
45+
source := *s.Source
4646

4747
preprocPath := ctx.PreprocPath
4848
err := utils.EnsureFolderExists(preprocPath)

src/arduino.cc/builder/external_include_replacer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ import (
3636
)
3737

3838
type ExternalIncludeReplacer struct {
39-
SourceKey string
40-
TargetKey string
41-
From string
42-
To string
39+
Source *string
40+
Target *string
41+
From string
42+
To string
4343
}
4444

4545
func (s *ExternalIncludeReplacer) Run(context map[string]interface{}, ctx *types.Context) error {
46-
source := context[s.SourceKey].(string)
46+
source := *s.Source
4747
nonAbsoluteIncludes := findNonAbsoluteIncludes(ctx.Includes)
4848

4949
for _, include := range nonAbsoluteIncludes {
5050
source = strings.Replace(source, s.From+"<"+include+">", s.To+"<"+include+">", -1)
5151
source = strings.Replace(source, s.From+"\""+include+"\"", s.To+"\""+include+"\"", -1)
5252
}
5353

54-
context[s.TargetKey] = source
54+
*s.Target = source
5555

5656
return nil
5757
}

src/arduino.cc/builder/gcc_preproc_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac
9393
return i18n.WrapError(err)
9494
}
9595

96-
context[constants.CTX_GCC_MINUS_E_SOURCE] = string(stderr)
96+
ctx.SourceGccMinusE = string(stderr)
9797

9898
return nil
9999
}

src/arduino.cc/builder/gcc_preproc_source_saver.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ func (s *GCCPreprocSourceSaver) Run(context map[string]interface{}, ctx *types.C
4646
return i18n.WrapError(err)
4747
}
4848

49-
source := context[constants.CTX_SOURCE].(string)
50-
51-
err = utils.WriteFile(filepath.Join(preprocPath, constants.FILE_GCC_PREPROC_TARGET), source)
49+
err = utils.WriteFile(filepath.Join(preprocPath, constants.FILE_GCC_PREPROC_TARGET), ctx.Source)
5250
return i18n.WrapError(err)
5351
}

src/arduino.cc/builder/includes_finder_with_regexp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ import (
4040
var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
4141

4242
type IncludesFinderWithRegExp struct {
43-
ContextField string
43+
Source *string
4444
}
4545

4646
func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *types.Context) error {
47-
source := context[s.ContextField].(string)
47+
source := *s.Source
4848

4949
matches := INCLUDE_REGEXP.FindAllStringSubmatch(source, -1)
5050
includes := []string{}

src/arduino.cc/builder/print_preprocessed_source.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@
3030
package builder
3131

3232
import (
33-
"arduino.cc/builder/constants"
3433
"arduino.cc/builder/types"
3534
"fmt"
3635
)
3736

3837
type PrintPreprocessedSource struct{}
3938

4039
func (s *PrintPreprocessedSource) Run(context map[string]interface{}, ctx *types.Context) error {
41-
source := context[constants.CTX_GCC_MINUS_E_SOURCE].(string)
42-
43-
fmt.Println(source)
44-
40+
fmt.Println(ctx.SourceGccMinusE)
4541
return nil
4642
}

src/arduino.cc/builder/prototypes_adder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type PrototypesAdder struct{}
4141

4242
func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context) error {
4343
debugOutput := ctx.DebugPreprocessor
44-
source := context[constants.CTX_SOURCE].(string)
44+
source := ctx.Source
4545

4646
source = strings.Replace(source, "\r\n", "\n", -1)
4747
source = strings.Replace(source, "\r", "\n", -1)
@@ -74,7 +74,7 @@ func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context
7474
}
7575
fmt.Println("#END OF PREPROCESSED SOURCE")
7676
}
77-
context[constants.CTX_SOURCE] = source
77+
ctx.Source = source
7878

7979
return nil
8080
}

0 commit comments

Comments
 (0)