Better removing unnecessary flags using `build_unflags` option // Resolve #698

This commit is contained in:
Ivan Kravets
2016-06-18 00:38:00 +03:00
parent 31a110c37f
commit 4035b9ac6c
8 changed files with 37 additions and 44 deletions

View File

@@ -7,6 +7,8 @@ PlatformIO 2.0
2.10.4 (2016-06-??)
~~~~~~~~~~~~~~~~~~~
* Better removing unnecessary flags using ``build_unflags`` option
(`issue #698 <https://github.com/platformio/platformio/issues/698>`_)
* Fixed issue with ``platformio init --ide`` command for Python 2.6
2.10.3 (2016-06-15)

View File

@@ -14,7 +14,7 @@
import sys
VERSION = (2, 10, "4.dev0")
VERSION = (2, 10, "4.dev1")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@@ -40,8 +40,7 @@ env.Replace(
"-fdata-sections",
"-Wall",
"-mthumb",
"-mcpu=${BOARD_OPTIONS['build']['cpu']}",
"-nostdlib"
"-mcpu=${BOARD_OPTIONS['build']['cpu']}"
],
CXXFLAGS=[
@@ -57,7 +56,9 @@ env.Replace(
"-Os",
"-Wl,--gc-sections,--relax",
"-mthumb",
"-mcpu=${BOARD_OPTIONS['build']['cpu']}"
"-mcpu=${BOARD_OPTIONS['build']['cpu']}",
"-nostdlib",
"-nostartfiles"
],
LIBS=["c", "gcc", "m"],

View File

@@ -71,8 +71,7 @@ env.Replace(
"-Wpointer-arith",
"-Wno-implicit-function-declaration",
"-Wl,-EL",
"-fno-inline-functions",
"-nostdlib"
"-fno-inline-functions"
],
CCFLAGS=[
@@ -82,8 +81,7 @@ env.Replace(
"-falign-functions=4",
"-U__STRICT_ANSI__",
"-ffunction-sections",
"-fdata-sections",
"-MMD" # output dependancy info
"-fdata-sections"
],
CXXFLAGS=[

View File

@@ -264,13 +264,12 @@ env.Replace(
)
# restore external build flags
env.ProcessFlags([
env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags")
])
env.ProcessFlags(
env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"))
# remove base flags
env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))
# apply user flags
env.ProcessFlags([env.get("BUILD_FLAGS")])
env.ProcessFlags(env.get("BUILD_FLAGS"))
# Hook for K64F and K22F
if board_type in ("frdm_k22f", "frdm_k64f"):

View File

@@ -66,11 +66,6 @@ env.Append(
],
LIBS=["stdc++", "nosys"],
LINKFLAGS=[
"-nostartfiles",
"-nostdlib"
]
)
#

View File

@@ -31,13 +31,6 @@ env.Replace(
UPLOADCMD='"$UPLOADER" $SOURCES'
)
env.Append(
LINKFLAGS=[
"-nostartfiles",
"-nostdlib"
]
)
#
# Target: Build executable and linkable firmware
#

View File

@@ -53,13 +53,12 @@ def BuildProgram(env):
)
# process extra flags from board
env.ProcessFlags([
env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags")
])
env.ProcessFlags(
env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"))
# remove base flags
env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))
# apply user flags
env.ProcessFlags([env.get("BUILD_FLAGS")])
env.ProcessFlags(env.get("BUILD_FLAGS"))
if env.get("FRAMEWORK"):
env.BuildFrameworks([
@@ -88,7 +87,7 @@ def BuildProgram(env):
)
# Handle SRC_BUILD_FLAGS
env.ProcessFlags([env.get("SRC_BUILD_FLAGS", None)])
env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))
env.Append(
CPPPATH=["$PROJECTSRC_DIR"],
@@ -117,18 +116,17 @@ def BuildProgram(env):
def ProcessFlags(env, flags):
for f in flags:
if not f:
if not flags:
return
parsed_flags = env.ParseFlags(str(flags))
for flag in parsed_flags.pop("CPPDEFINES"):
if not isinstance(flag, list):
env.Append(CPPDEFINES=flag)
continue
parsed_flags = env.ParseFlags(str(f))
for flag in parsed_flags.pop("CPPDEFINES"):
if not isinstance(flag, list):
env.Append(CPPDEFINES=flag)
continue
if '\"' in flag[1]:
flag[1] = flag[1].replace('\"', '\\\"')
env.Append(CPPDEFINES=[flag])
env.Append(**parsed_flags)
if '\"' in flag[1]:
flag[1] = flag[1].replace('\"', '\\\"')
env.Append(CPPDEFINES=[flag])
env.Append(**parsed_flags)
# fix relative CPPPATH & LIBPATH
for k in ("CPPPATH", "LIBPATH"):
@@ -153,10 +151,17 @@ def ProcessFlags(env, flags):
def ProcessUnFlags(env, flags):
if not flags:
return
for var, values in env.ParseFlags(flags).items():
for v in values:
if v in env[var]:
env[var].remove(v)
parsed_flags = env.ParseFlags(flags)
all_flags = []
for items in parsed_flags.values():
all_flags.extend(items)
all_flags = set(all_flags)
for key in parsed_flags.keys():
cur_flags = set(env.get(key, []))
common = cur_flags & all_flags
for item in common:
env[key].remove(item)
def IsFileWithExt(env, file_, ext): # pylint: disable=W0613