@@ -23,6 +23,7 @@ import (
2323 "github.com/arduino/arduino-cli/legacy/builder/types"
2424 "github.com/arduino/arduino-cli/legacy/builder/utils"
2525 "github.com/arduino/go-paths-helper"
26+ properties "github.com/arduino/go-properties-orderedmap"
2627 "github.com/pkg/errors"
2728)
2829
@@ -55,20 +56,28 @@ func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath *
5556}
5657
5758func 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 )
6265
6366 includesStrings := utils .Map (includes .AsStrings (), utils .WrapWithHyphenI )
64- properties .Set ("includes" , strings .Join (includesStrings , " " ))
67+ buildProperties .Set ("includes" , strings .Join (includesStrings , " " ))
6568
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 )
6978 }
7079
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 ())
7281 if err != nil {
7382 return nil , errors .WithStack (err )
7483 }
@@ -79,12 +88,3 @@ func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath *paths
7988
8089 return cmd , nil
8190}
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