From dc007dd136836b8beed185fb35fb03a33e1052d3 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 17 Feb 2016 20:20:39 +0200 Subject: [PATCH] Handle new environment variables PLATFORMIO_UPLOAD_PORT and PLATFORMIO_UPLOAD_FLAGS --- HISTORY.rst | 4 ++++ docs/envvars.rst | 16 ++++++++++++++-- docs/projectconf.rst | 10 ++++++++++ platformio/builder/main.py | 12 +++++++++--- platformio/builder/scripts/frameworks/mbed.py | 5 ++--- platformio/builder/tools/platformio.py | 12 ++++-------- 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c2e54e39..bb5eb8bb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,6 +18,10 @@ PlatformIO 2.0 * Added ``board_flash_mode`` option to `Project Configuration File platformio.ini `__ which allows to specify `custom flash chip mode `_ for Espressif development platform +* Handle new environment variables + `PLATFORMIO_UPLOAD_PORT `_ + and `PLATFORMIO_UPLOAD_FLAGS `_ + (`IDE issue #518 `_) * Fixed issue with ``CPPDEFINES`` which contain space and break PlatformIO IDE Linter (`IDE issue #34 `_) diff --git a/docs/envvars.rst b/docs/envvars.rst index f46784bd..7085bcf7 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -70,8 +70,8 @@ Allows to override :ref:`projectconf` option :ref:`projectconf_pio_envs_dir`. Allows to override :ref:`projectconf` option :ref:`projectconf_pio_data_dir`. -Builder -------- +Building +-------- .. envvar:: PLATFORMIO_BUILD_FLAGS @@ -90,6 +90,18 @@ Allows to set :ref:`projectconf` option :ref:`projectconf_src_filter`. Allows to set :ref:`projectconf` option :ref:`projectconf_extra_script`. +Uploading +--------- + +.. envvar:: PLATFORMIO_UPLOAD_PORT + +Allows to set :ref:`projectconf` option :ref:`projectconf_upload_port`. + +.. envvar:: PLATFORMIO_UPLOAD_FLAGS + +Allows to set :ref:`projectconf` option :ref:`projectconf_upload_flags`. + + Settings -------- diff --git a/docs/projectconf.rst b/docs/projectconf.rst index b1f4ea36..09a49eb5 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -433,6 +433,8 @@ When no targets are defined, *PlatformIO* will build only sources by default. Uploading options ~~~~~~~~~~~~~~~~~ +.. _projectconf_upload_port: + ``upload_port`` ^^^^^^^^^^^^^^^ @@ -448,6 +450,9 @@ automatically. To print all available serial ports use :ref:`cmd_serialports` command. +This option can be set by global environment variable +:envvar:`PLATFORMIO_UPLOAD_PORT`. + ``upload_protocol`` ^^^^^^^^^^^^^^^^^^^ @@ -461,12 +466,17 @@ A protocol that "uploader" tool uses to talk to the board. A connection speed (`baud rate `_) which "uploader" tool uses when sending firmware to board. +.. _projectconf_upload_flags: + ``upload_flags`` ^^^^^^^^^^^^^^^^ Extra flags for uploader. Will be added to the end of uploader command. If you need to override uploader command or base flags please use :ref:`projectconf_extra_script`. +This option can be set by global environment variable +:envvar:`PLATFORMIO_UPLOAD_FLAGS`. + .. _projectconf_upload_resetmethod: ``upload_resetmethod`` diff --git a/platformio/builder/main.py b/platformio/builder/main.py index 6c7209bb..ccb4a2d5 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -139,6 +139,13 @@ if env.subst("$PIOPACKAGE_TOOLCHAIN"): env.subst(join("$PIOPACKAGES_DIR", "$PIOPACKAGE_TOOLCHAIN", "bin")) ) +# handle custom variable from system environment +for var in ("BUILD_FLAGS", "SRC_BUILD_FLAGS", "SRC_FILTER", "EXTRA_SCRIPT", + "UPLOAD_PORT", "UPLOAD_FLAGS"): + k = "PLATFORMIO_%s" % var + if environ.get(k): + env[var] = environ.get(k) + env.SConscriptChdir(0) env.SConsignFile(join("$PIOENVS_DIR", ".sconsign.dblite")) env.SConscript("$BUILD_SCRIPT") @@ -146,9 +153,8 @@ env.SConscript("$BUILD_SCRIPT") if "UPLOAD_FLAGS" in env: env.Append(UPLOADERFLAGS=["$UPLOAD_FLAGS"]) -if environ.get("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT")): - env.SConscript( - environ.get("PLATFORMIO_EXTRA_SCRIPT", env.get("EXTRA_SCRIPT"))) +if env.get("EXTRA_SCRIPT"): + env.SConscript(env.get("EXTRA_SCRIPT")) if "envdump" in COMMAND_LINE_TARGETS: print env.Dump() diff --git a/platformio/builder/scripts/frameworks/mbed.py b/platformio/builder/scripts/frameworks/mbed.py index 84465d4a..c76202b8 100644 --- a/platformio/builder/scripts/frameworks/mbed.py +++ b/platformio/builder/scripts/frameworks/mbed.py @@ -32,7 +32,7 @@ import re import sys import xml.etree.ElementTree as ElementTree from binascii import crc32 -from os import getenv, walk +from os import walk from os.path import basename, isfile, join, normpath from SCons.Script import DefaultEnvironment @@ -233,8 +233,7 @@ env.Replace( # restore external build flags env.ProcessFlags([ env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"), - env.get("BUILD_FLAGS"), - getenv("PLATFORMIO_BUILD_FLAGS"), + env.get("BUILD_FLAGS") ]) # Hook for K64F and K22F diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 6a2eb3b5..6e080614 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -16,7 +16,7 @@ from __future__ import absolute_import import re from glob import glob -from os import getenv, listdir, sep, walk +from os import listdir, sep, walk from os.path import basename, dirname, isdir, isfile, join, normpath, realpath from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript @@ -44,8 +44,7 @@ def BuildProgram(env): env.ProcessFlags([ env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"), - env.get("BUILD_FLAGS"), - getenv("PLATFORMIO_BUILD_FLAGS"), + env.get("BUILD_FLAGS") ]) if env.get("FRAMEWORK"): @@ -72,10 +71,7 @@ def BuildProgram(env): ) # Handle SRC_BUILD_FLAGS - env.ProcessFlags([ - env.get("SRC_BUILD_FLAGS", None), - getenv("PLATFORMIO_SRC_BUILD_FLAGS"), - ]) + env.ProcessFlags([env.get("SRC_BUILD_FLAGS", None)]) env.Append( CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format( @@ -86,7 +82,7 @@ def BuildProgram(env): sources = env.LookupSources( "$BUILDSRC_DIR", "$PROJECTSRC_DIR", duplicate=False, - src_filter=getenv("PLATFORMIO_SRC_FILTER", env.get("SRC_FILTER"))) + src_filter=env.get("SRC_FILTER")) if not sources and not COMMAND_LINE_TARGETS: env.Exit(