Skip to content

Commit 0ae1c4f

Browse files
committed
Use CPP recipe to generate PREPROC if empty
solves #106 Signed-off-by: Martino Facchin <[email protected]>
1 parent 34d5b8d commit 0ae1c4f

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

src/arduino.cc/builder/gcc_preproc_runner.go

+20
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}) error {
5252
return utils.WrapError(err)
5353
}
5454

55+
if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING {
56+
//generate PREPROC_MACROS from RECIPE_CPP_PATTERN
57+
properties[constants.RECIPE_PREPROC_MACROS] = GeneratePreprocPatternFromCompile(properties[constants.RECIPE_CPP_PATTERN])
58+
}
59+
5560
verbose := context[constants.CTX_VERBOSE].(bool)
5661
logger := context[constants.CTX_LOGGER].(i18n.Logger)
5762
_, err = builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger)
@@ -77,6 +82,12 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac
7782

7883
verbose := context[constants.CTX_VERBOSE].(bool)
7984
logger := context[constants.CTX_LOGGER].(i18n.Logger)
85+
86+
if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING {
87+
//generate PREPROC_MACROS from RECIPE_CPP_PATTERN
88+
properties[constants.RECIPE_PREPROC_MACROS] = GeneratePreprocPatternFromCompile(properties[constants.RECIPE_CPP_PATTERN])
89+
}
90+
8091
stderr, err := builder_utils.ExecRecipeCollectStdErr(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger)
8192
if err != nil {
8293
return utils.WrapError(err)
@@ -112,3 +123,12 @@ func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFil
112123

113124
return properties, targetFilePath, nil
114125
}
126+
127+
func GeneratePreprocPatternFromCompile(compilePattern string) string {
128+
// add {preproc.macros.flags}
129+
// replace "{object_file}" with "{preprocessed_file_path}"
130+
returnString := compilePattern
131+
returnString = strings.Replace(returnString, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
132+
returnString = strings.Replace(returnString, "{object_file}", "{preprocessed_file_path}", 1)
133+
return returnString
134+
}

src/arduino.cc/builder/hardware/platform.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ tools.ctags.pattern="{cmd.path}" -u --language-force=c++ -f - --c++-kinds=svpf -
88
tools.avrdude.path={runtime.tools.avrdude.path}
99

1010
preproc.includes.flags=-w -x c++ -M -MG -MP
11-
preproc.includes.compatibility_flags={build.mbed_api_include} {build.nRF51822_api_include} {build.ble_api_include} {compiler.libsam.c.flags} {compiler.arm.cmsis.path} {build.variant_system_include}
12-
recipe.preproc.includes="{compiler.path}{compiler.cpp.cmd}" {preproc.includes.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {preproc.includes.compatibility_flags} {includes} "{source_file}"
11+
#preproc.includes.compatibility_flags={build.mbed_api_include} {build.nRF51822_api_include} {build.ble_api_include} {compiler.libsam.c.flags} {compiler.arm.cmsis.path} {build.variant_system_include}
12+
#recipe.preproc.includes="{compiler.path}{compiler.cpp.cmd}" {preproc.includes.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {preproc.includes.compatibility_flags} {includes} "{source_file}"
1313

1414
preproc.macros.flags=-w -x c++ -E -CC
15-
preproc.macros.compatibility_flags={build.mbed_api_include} {build.nRF51822_api_include} {build.ble_api_include} {compiler.libsam.c.flags} {compiler.arm.cmsis.path} {build.variant_system_include}
16-
recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} {preproc.macros.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {preproc.macros.compatibility_flags} {includes} "{source_file}" -o "{preprocessed_file_path}"
15+
#preproc.macros.compatibility_flags={build.mbed_api_include} {build.nRF51822_api_include} {build.ble_api_include} {compiler.libsam.c.flags} {compiler.arm.cmsis.path} {build.variant_system_include}
16+
#recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} {preproc.macros.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {preproc.macros.compatibility_flags} {includes} "{source_file}" -o "{preprocessed_file_path}"

src/arduino.cc/builder/includes_finder_with_gcc.go

+14
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error {
6262
properties[constants.BUILD_PROPERTIES_INCLUDES] = includesParams
6363
builder_utils.RemoveHyphenMDDFlagFromGCCCommandLine(properties)
6464

65+
if properties[constants.RECIPE_PREPROC_INCLUDES] == "" {
66+
//generate RECIPE_PREPROC_INCLUDES from RECIPE_CPP_PATTERN
67+
properties[constants.RECIPE_PREPROC_INCLUDES] = GeneratePreprocIncludePatternFromCompile(properties[constants.RECIPE_CPP_PATTERN])
68+
}
69+
6570
output, err := builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_INCLUDES, true, verbose, false, logger)
6671
if err != nil {
6772
return utils.WrapError(err)
@@ -71,3 +76,12 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error {
7176

7277
return nil
7378
}
79+
80+
func GeneratePreprocIncludePatternFromCompile(compilePattern string) string {
81+
// add {preproc.includes.flags}
82+
// remove -o "{object_file}"
83+
returnString := compilePattern
84+
returnString = strings.Replace(returnString, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.includes.flags}", 1)
85+
returnString = strings.Replace(returnString, "-o {object_file}", "", 1)
86+
return returnString
87+
}

src/arduino.cc/builder/test/hardware_loader_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) {
147147
require.Equal(t, "\"{cmd.path}\" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives \"{source_file}\"", packages.Properties["tools.ctags.pattern"])
148148
require.Equal(t, "{runtime.tools.avrdude.path}", packages.Properties["tools.avrdude.path"])
149149
require.Equal(t, "-w -x c++ -E -CC", packages.Properties["preproc.macros.flags"])
150-
require.Equal(t, "{build.mbed_api_include} {build.nRF51822_api_include} {build.ble_api_include} {compiler.libsam.c.flags} {compiler.arm.cmsis.path} {build.variant_system_include}", packages.Properties["preproc.macros.compatibility_flags"])
151150

152151
if runtime.GOOS != "windows" {
153152
require.NotNil(t, packages.Packages["my_symlinked_avr_platform"])

0 commit comments

Comments
 (0)