Skip to content

Commit 39e3c84

Browse files
matthijskooijmancmaglie
authored andcommitted
Convert GCCPreprocRunner(ForDiscoveringIncludes) to a normal function
Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent 85c5781 commit 39e3c84

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

container_add_prototypes.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ type ContainerAddPrototypes struct{}
4141

4242
func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
4343
sourceFile := filepath.Join(ctx.SketchBuildPath, filepath.Base(ctx.Sketch.MainFile.Name)+".cpp")
44+
45+
// Run preprocessor
46+
err := GCCPreprocRunner(ctx, sourceFile, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E, ctx.IncludeFolders)
47+
if err != nil {
48+
return i18n.WrapError(err)
49+
}
4450
commands := []types.Command{
45-
&GCCPreprocRunner{SourceFilePath: sourceFile, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E, Includes: ctx.IncludeFolders},
4651
&ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE},
4752
&FilterSketchSource{Source: &ctx.SourceGccMinusE},
4853
&CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E},

container_find_includes.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,16 +323,11 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
323323
ctx.GetLogger().Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_CACHED_INCLUDES, sourcePath)
324324
}
325325
} else {
326-
commands := []types.Command{
327-
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourcePath, TargetFilePath: targetFilePath, Includes: includes},
326+
stderr, err := GCCPreprocRunnerForDiscoveringIncludes(ctx, sourcePath, targetFilePath, includes)
327+
if err != nil {
328+
return i18n.WrapError(err)
328329
}
329-
for _, command := range commands {
330-
err := runCommand(ctx, command)
331-
if err != nil {
332-
return i18n.WrapError(err)
333-
}
334-
}
335-
include = IncludesFinderWithRegExp(ctx, ctx.SourceGccMinusE)
330+
include = IncludesFinderWithRegExp(ctx, stderr)
336331
}
337332

338333
if include == "" {
@@ -344,7 +339,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
344339
library := ResolveLibrary(ctx, include)
345340
if library == nil {
346341
// Library could not be resolved, show error
347-
err := runCommand(ctx, &GCCPreprocRunner{SourceFilePath: sourcePath, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E, Includes: includes})
342+
err := GCCPreprocRunner(ctx, sourcePath, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E, includes)
348343
return i18n.WrapError(err)
349344
}
350345

gcc_preproc_runner.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,8 @@ import (
4141
"github.com/arduino/go-properties-map"
4242
)
4343

44-
type GCCPreprocRunner struct {
45-
SourceFilePath string
46-
TargetFileName string
47-
Includes []string
48-
}
49-
50-
func (s *GCCPreprocRunner) Run(ctx *types.Context) error {
51-
properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFileName, s.Includes)
44+
func GCCPreprocRunner(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) error {
45+
properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes)
5246
if err != nil {
5347
return i18n.WrapError(err)
5448
}
@@ -70,16 +64,10 @@ func (s *GCCPreprocRunner) Run(ctx *types.Context) error {
7064
return nil
7165
}
7266

73-
type GCCPreprocRunnerForDiscoveringIncludes struct {
74-
SourceFilePath string
75-
TargetFilePath string
76-
Includes []string
77-
}
78-
79-
func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(ctx *types.Context) error {
80-
properties, _, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFilePath, s.Includes)
67+
func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) (string, error) {
68+
properties, _, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes)
8169
if err != nil {
82-
return i18n.WrapError(err)
70+
return "", i18n.WrapError(err)
8371
}
8472

8573
verbose := ctx.Verbose
@@ -92,12 +80,10 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(ctx *types.Context) error {
9280

9381
stderr, err := builder_utils.ExecRecipeCollectStdErr(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger)
9482
if err != nil {
95-
return i18n.WrapError(err)
83+
return "", i18n.WrapError(err)
9684
}
9785

98-
ctx.SourceGccMinusE = string(stderr)
99-
100-
return nil
86+
return string(stderr), nil
10187
}
10288

10389
func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) (properties.Map, string, error) {

0 commit comments

Comments
 (0)