Inject system environment variables to configuration settings in platformio.ini // Resolve #792

This commit is contained in:
Ivan Kravets
2016-10-31 17:04:34 +02:00
parent e42387fbf4
commit e4a91b8343
3 changed files with 13 additions and 3 deletions

View File

@ -11,6 +11,9 @@ PlatformIO 3.0
Your devices are always with you!
* `PIO Account <http://docs.platformio.org/en/latest/userguide/account/index.html>`__
for extra professional features from `PlatformIO Plus <https://pioplus.com>`__
* Inject system environment variables to configuration settings in
`Project Configuration File "platformio.ini" <http://docs.platformio.org/en/stable/projectconf.html>`__
(`issue #792 <https://github.com/platformio/platformio/issues/792>`_)
* Changed default exit combination for Device Monitor from ``Ctrl+]`` to ``Ctrl+C``
* Improved detecting of ARM mbed media disk for uploading
* Improved Project Generator for CLion IDE when source folder contains nested items

View File

@ -48,10 +48,13 @@ Each variable should have a next format: ``${<section>.<option>}``, where
``<section>`` is a value from ``[<section>]`` group, and ``<option>`` is a
first item from pair ``<option> = value``.
You can inject environment variable using ``env`` as a ``section``. For example,
``${env.HOME}``, etc.
* Variable can be applied only for the option's value
* Multiple variables are allowed
* The ``platformio`` section is reserved and could not be used as custom
section. Some good section names might be ``common`` or ``global``.
* The ``platformio`` and ``env`` sections are reserved and could not be used
as custom section. Some good section names might be ``common`` or ``global``.
Example:
@ -68,6 +71,7 @@ Example:
board = uno
build_flags = ${common.build_flags}
lib_deps = ${common.lib_deps_builtin}, ${common.lib_deps_external}
lib_extra_dirs = ${env.HOME}/arduino/libs
[env:nodemcuv2]
platform = espressif8266

View File

@ -59,7 +59,10 @@ class ProjectConfig(ConfigParser):
return self.VARTPL_RE.sub(self._re_sub_handler, value)
def _re_sub_handler(self, match):
return self.get(match.group(1), match.group(2))
section, option = match.group(1), match.group(2)
if section == "env" and not self.has_section(section):
return os.getenv(option)
return self.get(section, option)
class AsyncPipe(Thread):