Skip to content

Commit f4e9997

Browse files
author
Federico Fissore
committed
Preprocessor calls to gcc are now saved into the NULL file: "nul" on Windows,
"/dev/null" on Linux & OSX Signed-off-by: Federico Fissore <[email protected]>
1 parent 2d65db8 commit f4e9997

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Diff for: src/arduino.cc/builder/container_find_includes.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/types"
3535
"arduino.cc/builder/utils"
36-
"math/rand"
3736
"path/filepath"
38-
"strconv"
3937
)
4038

4139
type ContainerFindIncludes struct{}
@@ -100,12 +98,12 @@ func runCommand(context map[string]interface{}, command types.Command) error {
10098
}
10199

102100
func findIncludesUntilDone(context map[string]interface{}, sourceFilePath string) error {
103-
targetFileName := filepath.Base(sourceFilePath) + "_" + strconv.Itoa(rand.Int()) + "_preprocessed.cpp"
101+
targetFilePath := utils.NULLFile()
104102
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
105103
done := false
106104
for !done {
107105
commands := []types.Command{
108-
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFileName: targetFileName},
106+
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath},
109107
&IncludesFinderWithRegExp{ContextField: constants.CTX_GCC_MINUS_E_SOURCE},
110108
&IncludesToIncludeFolders{},
111109
}

Diff for: src/arduino.cc/builder/gcc_preproc_runner.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}) error {
6565

6666
type GCCPreprocRunnerForDiscoveringIncludes struct {
6767
SourceFilePath string
68-
TargetFileName string
68+
TargetFilePath string
6969
}
7070

7171
func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interface{}) error {
72-
properties, _, err := prepareGCCPreprocRecipeProperties(context, s.SourceFilePath, s.TargetFileName)
72+
properties, _, err := prepareGCCPreprocRecipeProperties(context, s.SourceFilePath, s.TargetFilePath)
7373
if err != nil {
7474
return utils.WrapError(err)
7575
}
@@ -86,13 +86,15 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac
8686
return nil
8787
}
8888

89-
func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFileName string) (map[string]string, string, error) {
90-
preprocPath := context[constants.CTX_PREPROC_PATH].(string)
91-
err := utils.EnsureFolderExists(preprocPath)
92-
if err != nil {
93-
return nil, "", utils.WrapError(err)
89+
func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFilePath string) (map[string]string, string, error) {
90+
if !filepath.IsAbs(targetFilePath) {
91+
preprocPath := context[constants.CTX_PREPROC_PATH].(string)
92+
err := utils.EnsureFolderExists(preprocPath)
93+
if err != nil {
94+
return nil, "", utils.WrapError(err)
95+
}
96+
targetFilePath = filepath.Join(preprocPath, targetFilePath)
9497
}
95-
targetFilePath := filepath.Join(preprocPath, targetFileName)
9698

9799
buildProperties := utils.GetMapStringStringOrDefault(context, constants.CTX_BUILD_PROPERTIES)
98100
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)

Diff for: src/arduino.cc/builder/utils/utils.go

+7
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,10 @@ func TagHasAtLeastOneField(tag map[string]string, fields []string) (string, bool
462462
}
463463
return "", false
464464
}
465+
466+
func NULLFile() string {
467+
if runtime.GOOS == "windows" {
468+
return "nul"
469+
}
470+
return "/dev/null"
471+
}

0 commit comments

Comments
 (0)