Skip to content

Use CPP recipe to generate PREPROC if empty #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/arduino.cc/builder/gcc_preproc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}) error {
return utils.WrapError(err)
}

if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING {
//generate PREPROC_MACROS from RECIPE_CPP_PATTERN
properties[constants.RECIPE_PREPROC_MACROS] = GeneratePreprocPatternFromCompile(properties[constants.RECIPE_CPP_PATTERN])
}

verbose := context[constants.CTX_VERBOSE].(bool)
logger := context[constants.CTX_LOGGER].(i18n.Logger)
_, err = builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger)
Expand All @@ -77,6 +82,12 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac

verbose := context[constants.CTX_VERBOSE].(bool)
logger := context[constants.CTX_LOGGER].(i18n.Logger)

if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING {
//generate PREPROC_MACROS from RECIPE_CPP_PATTERN
properties[constants.RECIPE_PREPROC_MACROS] = GeneratePreprocPatternFromCompile(properties[constants.RECIPE_CPP_PATTERN])
}

stderr, err := builder_utils.ExecRecipeCollectStdErr(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger)
if err != nil {
return utils.WrapError(err)
Expand Down Expand Up @@ -112,3 +123,12 @@ func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFil

return properties, targetFilePath, nil
}

func GeneratePreprocPatternFromCompile(compilePattern string) string {
// add {preproc.macros.flags}
// replace "{object_file}" with "{preprocessed_file_path}"
returnString := compilePattern
returnString = strings.Replace(returnString, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
returnString = strings.Replace(returnString, "{object_file}", "{preprocessed_file_path}", 1)
return returnString
}
8 changes: 4 additions & 4 deletions src/arduino.cc/builder/hardware/platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ tools.ctags.pattern="{cmd.path}" -u --language-force=c++ -f - --c++-kinds=svpf -
tools.avrdude.path={runtime.tools.avrdude.path}

preproc.includes.flags=-w -x c++ -M -MG -MP
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}
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}"
#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}
#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}"

preproc.macros.flags=-w -x c++ -E -CC
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}
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}"
#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}
#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}"
14 changes: 14 additions & 0 deletions src/arduino.cc/builder/includes_finder_with_gcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error {
properties[constants.BUILD_PROPERTIES_INCLUDES] = includesParams
builder_utils.RemoveHyphenMDDFlagFromGCCCommandLine(properties)

if properties[constants.RECIPE_PREPROC_INCLUDES] == "" {
//generate RECIPE_PREPROC_INCLUDES from RECIPE_CPP_PATTERN
properties[constants.RECIPE_PREPROC_INCLUDES] = GeneratePreprocIncludePatternFromCompile(properties[constants.RECIPE_CPP_PATTERN])
}

output, err := builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_INCLUDES, true, verbose, false, logger)
if err != nil {
return utils.WrapError(err)
Expand All @@ -71,3 +76,12 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error {

return nil
}

func GeneratePreprocIncludePatternFromCompile(compilePattern string) string {
// add {preproc.includes.flags}
// remove -o "{object_file}"
returnString := compilePattern
returnString = strings.Replace(returnString, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.includes.flags}", 1)
returnString = strings.Replace(returnString, "-o {object_file}", "", 1)
return returnString
}
1 change: 0 additions & 1 deletion src/arduino.cc/builder/test/hardware_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) {
require.Equal(t, "\"{cmd.path}\" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives \"{source_file}\"", packages.Properties["tools.ctags.pattern"])
require.Equal(t, "{runtime.tools.avrdude.path}", packages.Properties["tools.avrdude.path"])
require.Equal(t, "-w -x c++ -E -CC", packages.Properties["preproc.macros.flags"])
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"])

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