From 1a39781cff8614e155f9576fcf72b5706a1d1d31 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 7 May 2015 18:13:29 +0100 Subject: [PATCH] Fix cancelling any previous definition of name, either built in or provided with a ``-D`` option // Resolve #191 --- HISTORY.rst | 6 +++--- platformio/builder/tools/platformio.py | 26 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index d98e1a417e..9e71a5f896 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,9 +4,6 @@ Release History 1.5.0 (2015-05-??) ------------------ -* Created `PlatformIO gitter.im `_ - room - (`issue #174 `_) * Added GDB as alternative uploader to `ststm32 `__ platform (`issue #175 `_) * Added `examples `__ @@ -14,6 +11,9 @@ Release History (`issue #154 `_) * Fixed parsing of includes for PlatformIO Library Dependency Finder (`issue #189 `_) +* Fixed cancelling any previous definition of name, either built in or provided + with a ``-D`` option + (`issue #191 `_) 1.4.0 (2015-04-11) ------------------ diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 9a7c4a51f3..a3c5aac940 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -15,18 +15,13 @@ def BuildFirmware(env): # fix ASM handling under non-casitive OS - if not case_sensitive_suffixes('.s', '.S'): + if not case_sensitive_suffixes(".s", ".S"): env.Replace( AS="$CC", ASCOM="$ASPPCOM" ) - if "extra_flags" in env.get("BOARD_OPTIONS", {}).get("build", {}): - env.MergeFlags(env.subst("${BOARD_OPTIONS['build']['extra_flags']}")) - - if "BUILD_FLAGS" in env: - env.MergeFlags(env['BUILD_FLAGS']) - + env.ProcessFlags() env.BuildFramework() firmenv = env.Clone() @@ -69,6 +64,22 @@ def BuildFirmware(env): ) +def ProcessFlags(env): + if "extra_flags" in env.get("BOARD_OPTIONS", {}).get("build", {}): + env.MergeFlags(env.subst("${BOARD_OPTIONS['build']['extra_flags']}")) + + if "BUILD_FLAGS" in env: + env.MergeFlags(env['BUILD_FLAGS']) + + # Cancel any previous definition of name, either built in or + # provided with a -D option // Issue #191 + undefines = [f for f in env.get("CCFLAGS", []) if f.startswith("-U")] + if undefines: + for undef in undefines: + env['CCFLAGS'].remove(undef) + env.Append(_CPPDEFFLAGS=" %s" % " ".join(undefines)) + + def GlobCXXFiles(env, path): files = [] for suff in ["*.c", "*.cpp", "*.S"]: @@ -373,6 +384,7 @@ def exists(_): def generate(env): env.AddMethod(BuildFirmware) + env.AddMethod(ProcessFlags) env.AddMethod(GlobCXXFiles) env.AddMethod(VariantDirRecursive) env.AddMethod(BuildFramework)