From f68c18d1e57357c0af2891dda5bf79a512c362f5 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 17 Jun 2022 18:58:21 +0300 Subject: [PATCH] Fixed an issue when the build_unflags option was not applied to the ASPPFLAGS scope --- HISTORY.rst | 3 ++- platformio/builder/tools/platformio.py | 34 ++++++++++---------------- tests/commands/test_run.py | 34 +++++++++++++++++++++----- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index ab73f480..d9663c0b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -34,7 +34,8 @@ PlatformIO Core 6 * Added ``env.StringifyMacro(value)`` helper function for the `Advanced Scripting `__ * Allowed to ``Import("projenv")`` in a library extra script (`issue #4305 `_) * Improved a serial port finder for a board with predefined HWIDs -* Fixed an issue when `build_unflags `__ operation ignores a flag value (`issue #4309 `_) +* Fixed an issue when the `build_unflags `__ operation ignores a flag value (`issue #4309 `_) +* Fixed an issue when the `build_unflags `__ option was not applied to the ``ASPPFLAGS`` scope 6.0.2 (2022-06-01) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 59eb6387..c828a943 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -243,27 +243,19 @@ def ProcessUnFlags(env, flags): if not flags: return parsed = env.ParseFlagsExtended(flags) - - # get all flags and copy them to each "*FLAGS" variable - all_flags = [] - for key, unflags in parsed.items(): - if key.endswith("FLAGS"): - all_flags.extend(unflags) - for key, unflags in parsed.items(): - if key.endswith("FLAGS"): - parsed[key].extend(all_flags) - - for key, unflags in parsed.items(): - for unflag in unflags: - for current in env.get(key, []): - conditions = [ - unflag == current, - not isinstance(unflag, (tuple, list)) - and isinstance(current, (tuple, list)) - and unflag == current[0], - ] - if any(conditions): - env[key].remove(current) + unflag_scopes = tuple(set(["ASPPFLAGS"] + list(parsed.keys()))) + for scope in unflag_scopes: + for unflags in parsed.values(): + for unflag in unflags: + for current in env.get(scope, []): + conditions = [ + unflag == current, + not isinstance(unflag, (tuple, list)) + and isinstance(current, (tuple, list)) + and unflag == current[0], + ] + if any(conditions): + env[scope].remove(current) def StringifyMacro(env, value): # pylint: disable=unused-argument diff --git a/tests/commands/test_run.py b/tests/commands/test_run.py index b747e427..3a2817ba 100644 --- a/tests/commands/test_run.py +++ b/tests/commands/test_run.py @@ -112,7 +112,16 @@ def test_build_unflags(clirunner, validate_cliresult, tmpdir): """ [env:native] platform = native -build_unflags = -DTMP_MACRO1=45 -I. -DNON_EXISTING_MACRO -lunknownLib -Os +build_unflags = + -DTMP_MACRO_1=45 + -DTMP_MACRO_3=13 + -DTMP_MACRO_4 + -DNON_EXISTING_MACRO + -I. + -lunknownLib + -Os +build_flags = + -DTMP_MACRO_3=10 extra_scripts = pre:extra.py """ ) @@ -121,9 +130,10 @@ extra_scripts = pre:extra.py """ Import("env") env.Append(CPPPATH="%s") -env.Append(CPPDEFINES="TMP_MACRO1") -env.Append(CPPDEFINES=["TMP_MACRO2"]) -env.Append(CPPDEFINES=("TMP_MACRO3", 13)) +env.Append(CPPDEFINES="TMP_MACRO_1") +env.Append(CPPDEFINES=["TMP_MACRO_2"]) +env.Append(CPPDEFINES=[("TMP_MACRO_3", 13)]) +env.Append(CPPDEFINES=[("TMP_MACRO_4", 4)]) env.Append(CCFLAGS=["-Os"]) env.Append(LIBS=["unknownLib"]) """ @@ -132,8 +142,20 @@ env.Append(LIBS=["unknownLib"]) tmpdir.mkdir("src").join("main.c").write( """ -#ifdef TMP_MACRO1 -#error "TMP_MACRO1 should be removed" +#ifndef TMP_MACRO_1 +#error "TMP_MACRO_1 should be defined" +#endif + +#ifndef TMP_MACRO_2 +#error "TMP_MACRO_2 should be defined" +#endif + +#if TMP_MACRO_3 != 10 +#error "TMP_MACRO_3 should be 10" +#endif + +#ifdef TMP_MACRO_4 +#error "TMP_MACRO_4 should not be defined" #endif int main() {