From 4212ad1e9bfff8379824908ccbac687d13ee264e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 17 Aug 2023 17:48:39 +0200 Subject: [PATCH] regression: Fix property expansion of "recipe.preproc.macros" Previously the undefined template placeholders in "recipe.preproc.macros" were silently replaced the empty string. This changed after a refactoring in 0585435f8b1d05e0117606f69bea42d3f3dfec79. Previously it was: https://github.com/arduino/arduino-cli/commit/0585435f8b1d05e0117606f69bea42d3f3dfec79#diff-371f93465ca5a66f01cbe876348f67990750091d27a827781c8633456b93ef3bL62 - cmd, err := builder_utils.PrepareCommandForRecipe(buildProperties, "recipe.preproc.macros", true, ctx.PackageManager.GetEnvVarsForSpawnedProcess()) The `true` parameter in the call to `builder_utils.PrepareCommandForRecipe` is the parameter `removeUnsetProperties`. This behaviour has not been ported over after the "refactoring": https://github.com/arduino/arduino-cli/commit/0585435f8b1d05e0117606f69bea42d3f3dfec79#diff-733dda6759fe968eb8a8d7305c37c7a320a8df52764ca0cba8e88a6f1d077eb5R44-R65 + const gccPreprocRecipeProperty = "recipe.preproc.macros" + if gccBuildProperties.Get(gccPreprocRecipeProperty) == "" { + // autogenerate preprocess macros recipe from compile recipe + preprocPattern := gccBuildProperties.Get("recipe.cpp.o.pattern") + // add {preproc.macros.flags} to {compiler.cpp.flags} + preprocPattern = strings.Replace(preprocPattern, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1) + // replace "{object_file}" with "{preprocessed_file_path}" + preprocPattern = strings.Replace(preprocPattern, "{object_file}", "{preprocessed_file_path}", 1) + + gccBuildProperties.Set(gccPreprocRecipeProperty, preprocPattern) + } + + pattern := gccBuildProperties.Get(gccPreprocRecipeProperty) + if pattern == "" { + return nil, nil, errors.Errorf(tr("%s pattern is missing"), gccPreprocRecipeProperty) + } + + commandLine := gccBuildProperties.ExpandPropsInString(pattern) + args, err := properties.SplitQuotedString(commandLine, `"'`, false) + if err != nil { + return nil, nil, err + } that is missing the call to `properties.DeleteUnexpandedPropsFromString`. --- arduino/builder/preprocessor/gcc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino/builder/preprocessor/gcc.go b/arduino/builder/preprocessor/gcc.go index 0345d475900..476c1f2f5b4 100644 --- a/arduino/builder/preprocessor/gcc.go +++ b/arduino/builder/preprocessor/gcc.go @@ -59,6 +59,7 @@ func GCC(sourceFilePath *paths.Path, targetFilePath *paths.Path, includes paths. } commandLine := gccBuildProperties.ExpandPropsInString(pattern) + commandLine = properties.DeleteUnexpandedPropsFromString(commandLine) args, err := properties.SplitQuotedString(commandLine, `"'`, false) if err != nil { return nil, nil, err