Skip to content

Commit 652f830

Browse files
matthijskooijmancmaglie
authored andcommitted
Refactor path generation for ctags_target_for_gcc_minus_e.cpp
Previously, the relative filename passed to GCCPreprocRunner() was made absolute by prepareGCCPreprocRecipeProperties() and then returned, so it could be used later on. There was an exception to this when /dev/null was passed. Now, the only place that passed something other than /dev/null simply does this processing up front instead. This prepares the way for removing Context::FileToRead in the next commit. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent 39e3c84 commit 652f830

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

container_add_prototypes.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,23 @@ import (
3535
"github.com/arduino/arduino-builder/constants"
3636
"github.com/arduino/arduino-builder/i18n"
3737
"github.com/arduino/arduino-builder/types"
38+
"github.com/arduino/arduino-builder/utils"
3839
)
3940

4041
type ContainerAddPrototypes struct{}
4142

4243
func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
4344
sourceFile := filepath.Join(ctx.SketchBuildPath, filepath.Base(ctx.Sketch.MainFile.Name)+".cpp")
4445

46+
// Generate the full pathname for the preproc output file
47+
err := utils.EnsureFolderExists(ctx.PreprocPath)
48+
if err != nil {
49+
return i18n.WrapError(err)
50+
}
51+
targetFilePath := filepath.Join(ctx.PreprocPath, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E)
52+
4553
// Run preprocessor
46-
err := GCCPreprocRunner(ctx, sourceFile, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E, ctx.IncludeFolders)
54+
err = GCCPreprocRunner(ctx, sourceFile, targetFilePath, ctx.IncludeFolders)
4755
if err != nil {
4856
return i18n.WrapError(err)
4957
}

gcc_preproc_runner.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
package builder
3131

3232
import (
33-
"path/filepath"
3433
"strings"
3534

3635
"github.com/arduino/arduino-builder/builder_utils"
@@ -42,7 +41,7 @@ import (
4241
)
4342

4443
func GCCPreprocRunner(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) error {
45-
properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes)
44+
properties, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes)
4645
if err != nil {
4746
return i18n.WrapError(err)
4847
}
@@ -65,7 +64,7 @@ func GCCPreprocRunner(ctx *types.Context, sourceFilePath string, targetFilePath
6564
}
6665

6766
func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) (string, error) {
68-
properties, _, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes)
67+
properties, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes)
6968
if err != nil {
7069
return "", i18n.WrapError(err)
7170
}
@@ -86,16 +85,7 @@ func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath s
8685
return string(stderr), nil
8786
}
8887

89-
func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) (properties.Map, string, error) {
90-
if targetFilePath != utils.NULLFile() {
91-
preprocPath := ctx.PreprocPath
92-
err := utils.EnsureFolderExists(preprocPath)
93-
if err != nil {
94-
return nil, "", i18n.WrapError(err)
95-
}
96-
targetFilePath = filepath.Join(preprocPath, targetFilePath)
97-
}
98-
88+
func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string, includes []string) (properties.Map, error) {
9989
properties := ctx.BuildProperties.Clone()
10090
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = sourceFilePath
10191
properties[constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH] = targetFilePath
@@ -104,7 +94,7 @@ func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string
10494
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
10595
builder_utils.RemoveHyphenMDDFlagFromGCCCommandLine(properties)
10696

107-
return properties, targetFilePath, nil
97+
return properties, nil
10898
}
10999

110100
func GeneratePreprocPatternFromCompile(compilePattern string) string {

0 commit comments

Comments
 (0)