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>`__
* 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
* 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)
~~~~~~~~~~~~~~~~~~

View File

@ -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

View File

@ -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() {