@@ -23,6 +23,7 @@ import (
23
23
"github.com/arduino/arduino-cli/legacy/builder/types"
24
24
"github.com/arduino/arduino-cli/legacy/builder/utils"
25
25
"github.com/arduino/go-paths-helper"
26
+ properties "github.com/arduino/go-properties-orderedmap"
26
27
"github.com/pkg/errors"
27
28
)
28
29
@@ -55,20 +56,28 @@ func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath *
55
56
}
56
57
57
58
func prepareGCCPreprocRecipeProperties (ctx * types.Context , sourceFilePath * paths.Path , targetFilePath * paths.Path , includes paths.PathList ) (* exec.Cmd , error ) {
58
- properties := ctx .BuildProperties .Clone ()
59
- properties .Set ("build.library_discovery_phase" , "1" )
60
- properties .SetPath ("source_file" , sourceFilePath )
61
- properties .SetPath ("preprocessed_file_path" , targetFilePath )
59
+ buildProperties := properties .NewMap ()
60
+ buildProperties .Set ("preproc.macros.flags" , "-w -x c++ -E -CC" )
61
+ buildProperties .Merge (ctx .BuildProperties )
62
+ buildProperties .Set ("build.library_discovery_phase" , "1" )
63
+ buildProperties .SetPath ("source_file" , sourceFilePath )
64
+ buildProperties .SetPath ("preprocessed_file_path" , targetFilePath )
62
65
63
66
includesStrings := utils .Map (includes .AsStrings (), utils .WrapWithHyphenI )
64
- properties .Set ("includes" , strings .Join (includesStrings , " " ))
67
+ buildProperties .Set ("includes" , strings .Join (includesStrings , " " ))
65
68
66
- if properties .Get ("recipe.preproc.macros" ) == "" {
67
- //generate PREPROC_MACROS from RECIPE_CPP_PATTERN
68
- properties .Set ("recipe.preproc.macros" , GeneratePreprocPatternFromCompile (properties .Get ("recipe.cpp.o.pattern" )))
69
+ if buildProperties .Get ("recipe.preproc.macros" ) == "" {
70
+ // autogenerate preprocess macros recipe from compile recipe
71
+ preprocPattern := buildProperties .Get ("recipe.cpp.o.pattern" )
72
+ // add {preproc.macros.flags} to {compiler.cpp.flags}
73
+ preprocPattern = strings .Replace (preprocPattern , "{compiler.cpp.flags}" , "{compiler.cpp.flags} {preproc.macros.flags}" , 1 )
74
+ // replace "{object_file}" with "{preprocessed_file_path}"
75
+ preprocPattern = strings .Replace (preprocPattern , "{object_file}" , "{preprocessed_file_path}" , 1 )
76
+
77
+ buildProperties .Set ("recipe.preproc.macros" , preprocPattern )
69
78
}
70
79
71
- cmd , err := builder_utils .PrepareCommandForRecipe (properties , "recipe.preproc.macros" , true , ctx .PackageManager .GetEnvVarsForSpawnedProcess ())
80
+ cmd , err := builder_utils .PrepareCommandForRecipe (buildProperties , "recipe.preproc.macros" , true , ctx .PackageManager .GetEnvVarsForSpawnedProcess ())
72
81
if err != nil {
73
82
return nil , errors .WithStack (err )
74
83
}
@@ -79,12 +88,3 @@ func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath *paths
79
88
80
89
return cmd , nil
81
90
}
82
-
83
- func GeneratePreprocPatternFromCompile (compilePattern string ) string {
84
- // add {preproc.macros.flags}
85
- // replace "{object_file}" with "{preprocessed_file_path}"
86
- returnString := compilePattern
87
- returnString = strings .Replace (returnString , "{compiler.cpp.flags}" , "{compiler.cpp.flags} {preproc.macros.flags}" , 1 )
88
- returnString = strings .Replace (returnString , "{object_file}" , "{preprocessed_file_path}" , 1 )
89
- return returnString
90
- }
0 commit comments