@@ -39,54 +39,71 @@ import (
3939 "strings"
4040)
4141
42- type GCCPreprocRunner struct {}
42+ type GCCPreprocRunner struct {
43+ TargetFileName string
44+ }
4345
4446func (s * GCCPreprocRunner ) Run (context map [string ]interface {}) error {
4547 sketchBuildPath := context [constants .CTX_SKETCH_BUILD_PATH ].(string )
4648 sketch := context [constants .CTX_SKETCH ].(* types.Sketch )
47- properties := prepareGCCPreprocRecipeProperties (context , filepath .Join (sketchBuildPath , filepath .Base (sketch .MainFile .Name )+ ".cpp" ))
49+ properties , targetFilePath , err := prepareGCCPreprocRecipeProperties (context , filepath .Join (sketchBuildPath , filepath .Base (sketch .MainFile .Name )+ ".cpp" ), s .TargetFileName )
50+ if err != nil {
51+ return utils .WrapError (err )
52+ }
4853
4954 verbose := context [constants .CTX_VERBOSE ].(bool )
5055 logger := context [constants .CTX_LOGGER ].(i18n.Logger )
51- output , err : = builder_utils .ExecRecipe (properties , constants .RECIPE_PREPROC_FINAL , true , verbose , false , logger )
56+ _ , err = builder_utils .ExecRecipe (properties , constants .RECIPE_PREPROC_MACROS , true , verbose , false , logger )
5257 if err != nil {
5358 return utils .WrapError (err )
5459 }
5560
56- context [constants .CTX_GCC_MINUS_E_SOURCE ] = string ( output )
61+ context [constants .CTX_FILE_PATH_TO_READ ] = targetFilePath
5762
5863 return nil
5964}
6065
6166type GCCPreprocRunnerForDiscoveringIncludes struct {
62- SourceFile string
67+ SourceFilePath string
68+ TargetFileName string
6369}
6470
6571func (s * GCCPreprocRunnerForDiscoveringIncludes ) Run (context map [string ]interface {}) error {
66- properties := prepareGCCPreprocRecipeProperties (context , s .SourceFile )
72+ properties , _ , err := prepareGCCPreprocRecipeProperties (context , s .SourceFilePath , s .TargetFileName )
73+ if err != nil {
74+ return utils .WrapError (err )
75+ }
6776
6877 verbose := context [constants .CTX_VERBOSE ].(bool )
6978 logger := context [constants .CTX_LOGGER ].(i18n.Logger )
70- output , err := builder_utils .ExecRecipeCollectStdErr (properties , constants .RECIPE_PREPROC_MACROS , true , verbose , false , logger )
79+ stderr , err := builder_utils .ExecRecipeCollectStdErr (properties , constants .RECIPE_PREPROC_MACROS , true , verbose , false , logger )
7180 if err != nil {
7281 return utils .WrapError (err )
7382 }
7483
75- context [constants .CTX_GCC_MINUS_E_SOURCE ] = string (output )
84+ context [constants .CTX_GCC_MINUS_E_SOURCE ] = string (stderr )
7685
7786 return nil
7887}
7988
80- func prepareGCCPreprocRecipeProperties (context map [string ]interface {}, sourceFile string ) map [string ]string {
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 )
94+ }
95+ targetFilePath := filepath .Join (preprocPath , targetFileName )
96+
8197 buildProperties := utils .GetMapStringStringOrDefault (context , constants .CTX_BUILD_PROPERTIES )
8298 properties := utils .MergeMapsOfStrings (make (map [string ]string ), buildProperties )
8399
84- properties [constants .BUILD_PROPERTIES_SOURCE_FILE ] = sourceFile
100+ properties [constants .BUILD_PROPERTIES_SOURCE_FILE ] = sourceFilePath
101+ properties [constants .BUILD_PROPERTIES_PREPROCESSED_FILE_PATH ] = targetFilePath
85102
86103 includes := context [constants .CTX_INCLUDE_FOLDERS ].([]string )
87104 includes = utils .Map (includes , utils .WrapWithHyphenI )
88105 properties [constants .BUILD_PROPERTIES_INCLUDES ] = strings .Join (includes , constants .SPACE )
89106 builder_utils .RemoveHyphenMDDFlagFromGCCCommandLine (properties )
90107
91- return properties
108+ return properties , targetFilePath , nil
92109}
0 commit comments