Skip to content

Commit

Permalink
Preprocessor calls to gcc are now saved into the NULL file: "nul" on …
Browse files Browse the repository at this point in the history
…Windows,

"/dev/null" on Linux & OSX

Signed-off-by: Federico Fissore <[email protected]>
  • Loading branch information
Federico Fissore committed Dec 2, 2015
1 parent 2d65db8 commit f4e9997
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/arduino.cc/builder/container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ import (
"arduino.cc/builder/constants"
"arduino.cc/builder/types"
"arduino.cc/builder/utils"
"math/rand"
"path/filepath"
"strconv"
)

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

func findIncludesUntilDone(context map[string]interface{}, sourceFilePath string) error {
targetFileName := filepath.Base(sourceFilePath) + "_" + strconv.Itoa(rand.Int()) + "_preprocessed.cpp"
targetFilePath := utils.NULLFile()
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
done := false
for !done {
commands := []types.Command{
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFileName: targetFileName},
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath},
&IncludesFinderWithRegExp{ContextField: constants.CTX_GCC_MINUS_E_SOURCE},
&IncludesToIncludeFolders{},
}
Expand Down
18 changes: 10 additions & 8 deletions src/arduino.cc/builder/gcc_preproc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}) error {

type GCCPreprocRunnerForDiscoveringIncludes struct {
SourceFilePath string
TargetFileName string
TargetFilePath string
}

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

func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFileName string) (map[string]string, string, error) {
preprocPath := context[constants.CTX_PREPROC_PATH].(string)
err := utils.EnsureFolderExists(preprocPath)
if err != nil {
return nil, "", utils.WrapError(err)
func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFilePath string) (map[string]string, string, error) {
if !filepath.IsAbs(targetFilePath) {
preprocPath := context[constants.CTX_PREPROC_PATH].(string)
err := utils.EnsureFolderExists(preprocPath)
if err != nil {
return nil, "", utils.WrapError(err)
}
targetFilePath = filepath.Join(preprocPath, targetFilePath)
}
targetFilePath := filepath.Join(preprocPath, targetFileName)

buildProperties := utils.GetMapStringStringOrDefault(context, constants.CTX_BUILD_PROPERTIES)
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
Expand Down
7 changes: 7 additions & 0 deletions src/arduino.cc/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,10 @@ func TagHasAtLeastOneField(tag map[string]string, fields []string) (string, bool
}
return "", false
}

func NULLFile() string {
if runtime.GOOS == "windows" {
return "nul"
}
return "/dev/null"
}

0 comments on commit f4e9997

Please sign in to comment.