Fix handling of build flags passed via environment vars // Resolve #526

This commit is contained in:
Valeriy Koval
2016-02-25 15:09:23 +02:00
parent ff08416307
commit 1c481e0840
3 changed files with 31 additions and 12 deletions

View File

@ -77,6 +77,20 @@ Building
Allows to set :ref:`projectconf` option :ref:`projectconf_build_flags`. Allows to set :ref:`projectconf` option :ref:`projectconf_build_flags`.
Examples:
.. code-block:: bash
# Unix:
export PLATFORMIO_BUILD_FLAGS=-DFOO
export PLATFORMIO_BUILD_FLAGS="-DFOO -DBAR=1 -DFLOAT_VALUE=1.23457e+07"
export PLATFORMIO_BUILD_FLAGS="'-DWIFI_PASS=\"My password\"' '-DWIFI_SSID=\"My ssid name\"'"
# Windows:
SET PLATFORMIO_BUILD_FLAGS=-DFOO
SET PLATFORMIO_BUILD_FLAGS=-DFOO -DBAR=1 -DFLOAT_VALUE=1.23457e+07
SET PLATFORMIO_BUILD_FLAGS='-DWIFI_PASS="My password"' '-DWIFI_SSID="My ssid name"'
.. envvar:: PLATFORMIO_SRC_BUILD_FLAGS .. envvar:: PLATFORMIO_SRC_BUILD_FLAGS
Allows to set :ref:`projectconf` option :ref:`projectconf_src_build_flags`. Allows to set :ref:`projectconf` option :ref:`projectconf_src_build_flags`.

View File

@ -301,7 +301,10 @@ Example:
.. code-block:: ini .. code-block:: ini
[env:specific_defines] [env:specific_defines]
build_flags = -Dfoo -Dbar=1 build_flags = -DFOO -DBAR=1 -DFLOAT_VALUE=1.23457e+07
[env:string_defines]
build_flags = '-DHELLO="World!"' '-DWIFI_PASS="My password"'
[env:specific_inclibs] [env:specific_inclibs]
build_flags = -I/opt/include -L/opt/lib -lfoo build_flags = -I/opt/include -L/opt/lib -lfoo

View File

@ -96,17 +96,19 @@ def BuildProgram(env):
def ProcessFlags(env, flags): def ProcessFlags(env, flags):
parsed_flags = env.ParseFlags(flags) for f in flags:
for flag in parsed_flags.pop("CPPDEFINES"): if not f:
if isinstance(flag, list): continue
env.Append( parsed_flags = env.ParseFlags(str(f))
CPPDEFINES=[ print parsed_flags
'-D%s=\\"%s\\"' % (flag[0], flag[1]) for flag in parsed_flags.pop("CPPDEFINES"):
] if not isinstance(flag, list):
) env.Append(CPPDEFINES=flag)
else: continue
env.Append(CPPDEFINES=flag) if '\"' in flag[1]:
env.Append(**parsed_flags) flag[1] = flag[1].replace('\"', '\\\"')
env.Append(CPPDEFINES=[flag])
env.Append(**parsed_flags)
# fix relative CPPPATH # fix relative CPPPATH
for i, p in enumerate(env.get("CPPPATH", [])): for i, p in enumerate(env.get("CPPPATH", [])):