Fixed an issue when the build_unflags option was not applied to the ASPPFLAGS scope

This commit is contained in:
Ivan Kravets
2022-06-17 18:58:21 +03:00
parent db6b8a6dbc
commit f68c18d1e5
3 changed files with 43 additions and 28 deletions

View File

@ -34,7 +34,8 @@ PlatformIO Core 6
* Added ``env.StringifyMacro(value)`` helper function for the `Advanced Scripting <https://docs.platformio.org/en/latest/scripting/index.html>`__ * Added ``env.StringifyMacro(value)`` helper function for the `Advanced Scripting <https://docs.platformio.org/en/latest/scripting/index.html>`__
* Allowed to ``Import("projenv")`` in a library extra script (`issue #4305 <https://github.com/platformio/platformio-core/issues/4305>`_) * Allowed to ``Import("projenv")`` in a library extra script (`issue #4305 <https://github.com/platformio/platformio-core/issues/4305>`_)
* Improved a serial port finder for a board with predefined HWIDs * Improved a serial port finder for a board with predefined HWIDs
* Fixed an issue when `build_unflags <https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-unflags>`__ operation ignores a flag value (`issue #4309 <https://github.com/platformio/platformio-core/issues/4309>`_) * Fixed an issue when the `build_unflags <https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-unflags>`__ operation ignores a flag value (`issue #4309 <https://github.com/platformio/platformio-core/issues/4309>`_)
* Fixed an issue when the `build_unflags <https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-unflags>`__ option was not applied to the ``ASPPFLAGS`` scope
6.0.2 (2022-06-01) 6.0.2 (2022-06-01)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~

View File

@ -243,27 +243,19 @@ def ProcessUnFlags(env, flags):
if not flags: if not flags:
return return
parsed = env.ParseFlagsExtended(flags) parsed = env.ParseFlagsExtended(flags)
unflag_scopes = tuple(set(["ASPPFLAGS"] + list(parsed.keys())))
# get all flags and copy them to each "*FLAGS" variable for scope in unflag_scopes:
all_flags = [] for unflags in parsed.values():
for key, unflags in parsed.items(): for unflag in unflags:
if key.endswith("FLAGS"): for current in env.get(scope, []):
all_flags.extend(unflags) conditions = [
for key, unflags in parsed.items(): unflag == current,
if key.endswith("FLAGS"): not isinstance(unflag, (tuple, list))
parsed[key].extend(all_flags) and isinstance(current, (tuple, list))
and unflag == current[0],
for key, unflags in parsed.items(): ]
for unflag in unflags: if any(conditions):
for current in env.get(key, []): env[scope].remove(current)
conditions = [
unflag == current,
not isinstance(unflag, (tuple, list))
and isinstance(current, (tuple, list))
and unflag == current[0],
]
if any(conditions):
env[key].remove(current)
def StringifyMacro(env, value): # pylint: disable=unused-argument def StringifyMacro(env, value): # pylint: disable=unused-argument

View File

@ -112,7 +112,16 @@ def test_build_unflags(clirunner, validate_cliresult, tmpdir):
""" """
[env:native] [env:native]
platform = 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 extra_scripts = pre:extra.py
""" """
) )
@ -121,9 +130,10 @@ extra_scripts = pre:extra.py
""" """
Import("env") Import("env")
env.Append(CPPPATH="%s") env.Append(CPPPATH="%s")
env.Append(CPPDEFINES="TMP_MACRO1") env.Append(CPPDEFINES="TMP_MACRO_1")
env.Append(CPPDEFINES=["TMP_MACRO2"]) env.Append(CPPDEFINES=["TMP_MACRO_2"])
env.Append(CPPDEFINES=("TMP_MACRO3", 13)) env.Append(CPPDEFINES=[("TMP_MACRO_3", 13)])
env.Append(CPPDEFINES=[("TMP_MACRO_4", 4)])
env.Append(CCFLAGS=["-Os"]) env.Append(CCFLAGS=["-Os"])
env.Append(LIBS=["unknownLib"]) env.Append(LIBS=["unknownLib"])
""" """
@ -132,8 +142,20 @@ env.Append(LIBS=["unknownLib"])
tmpdir.mkdir("src").join("main.c").write( tmpdir.mkdir("src").join("main.c").write(
""" """
#ifdef TMP_MACRO1 #ifndef TMP_MACRO_1
#error "TMP_MACRO1 should be removed" #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 #endif
int main() { int main() {