From c7d9ab84747e81ac16351c33e51b69ff9f2942f6 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 15 Jul 2016 18:41:16 +0300 Subject: [PATCH] Allow to use extra build options as array for library.json // Issue #289 --- docs/librarymanager/config.rst | 41 +++++++++++++++++++------- platformio/builder/tools/platformio.py | 5 +++- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/docs/librarymanager/config.rst b/docs/librarymanager/config.rst index 2072aabc..50a82cc9 100644 --- a/docs/librarymanager/config.rst +++ b/docs/librarymanager/config.rst @@ -426,14 +426,28 @@ A list of example patterns. This field is predefined with default value: Specify advanced settings, options and flags for the build system. Possible options: -* ``flags`` - extra flags to control preprocessing, compilation, assembly and - linking processes. More details :ref:`projectconf_build_flags` -* ``unflags`` - remove base/initial flags which were set by development - platform. More details :ref:`projectconf_build_unflags` -* ``srcFilter`` - specify which source files should be included/excluded - from build process. More details :ref:`projectconf_src_filter` -* ``extraScript`` - launch extra script before build process. - More details :ref:`projectconf_extra_script`. +.. list-table:: + :header-rows: 1 + + * - Option + - Type + - Description + * - ``flags`` + - ``String`` or ``Array`` + - Extra flags to control preprocessing, compilation, assembly and + linking processes. More details :ref:`projectconf_build_flags` + * - ``unflags`` + - ``String`` or ``Array`` + - Remove base/initial flags which were set by development + platform. More details :ref:`projectconf_build_unflags` + * - ``srcFilter`` + - ``String`` or ``Array`` + - Specify which source files should be included/excluded + from build process. More details :ref:`projectconf_src_filter` + * - ``extraScript`` + - ``String`` + - Launch extra script before build process. + More details :ref:`projectconf_extra_script` **Examples** @@ -450,7 +464,10 @@ options: .. code-block:: javascript "build": { - "flags": "-I inc -I inc/target_x13" + "flags": [ + "-I inc", + "-I inc/target_x13" + ] } 3. Force to use ``C99`` standard instead ``C11`` @@ -487,7 +504,11 @@ options: .. code-block:: python - # Import('env') + Import('env') # print env.Dump() + env.Append( + CPPDEFINES=["HELLO=WORLD", "TAG=1.2.3", "DEBUG"], + CPPPATH=["inc", "inc/devices"] + ) # some python code that generates headers files "on-the-fly" diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 7ce3692e..c3440897 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -114,7 +114,9 @@ def BuildProgram(env): def ProcessFlags(env, flags): if not flags: return - parsed_flags = env.ParseFlags(str(flags)) + if isinstance(flags, list): + flags = " ".join(flags) + parsed_flags = env.ParseFlags(flags) for flag in parsed_flags.pop("CPPDEFINES"): if not isinstance(flag, list): env.Append(CPPDEFINES=flag) @@ -147,6 +149,7 @@ def ProcessFlags(env, flags): def ProcessUnFlags(env, flags): if not flags: return + flags = " ".join(flags) parsed_flags = env.ParseFlags(flags) all_flags = [] for items in parsed_flags.values():