Skip to content

Commit

Permalink
Override any option from board manifest in Project Configuration File…
Browse files Browse the repository at this point in the history
… "platformio.ini" // Resolve #1612
  • Loading branch information
ivankravets committed May 25, 2018
1 parent 5011c3e commit 9ba5dc0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ PlatformIO 3.0

* Simplify configuration for `PIO Unit Testing <http://docs.platformio.org/page/plus/unit-testing.html>`__: separate main program from a test build process, drop
requirement for ``#ifdef UNIT_TEST`` guard
* Override any option from board manifest in `Project Configuration File "platformio.ini" <http://docs.platformio.org/page/projectconf/section_env_board.html#more-options>`__
(`issue #1612 <https://github.com/platformio/platformio-core/issues/1612>`_)
* Configure a custom path to SVD file using `debug_svd_path <http://docs.platformio.org/page/projectconf/section_env_debug.html#debug-svd-path>`__
option
* Custom project `description <http://docs.platformio.org/en/latest/projectconf/section_platformio.html#description>`_
Expand Down
2 changes: 2 additions & 0 deletions platformio/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@

# board options
("BOARD",),
# deprecated options, use board_{object.path} instead
("BOARD_MCU",),
("BOARD_F_CPU",),
("BOARD_F_FLASH",),
("BOARD_FLASH_MODE",),
# end of deprecated options

# upload options
("UPLOAD_PORT",),
Expand Down
18 changes: 13 additions & 5 deletions platformio/builder/tools/pioplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import absolute_import

import base64
import sys
from os.path import isdir, isfile, join

Expand Down Expand Up @@ -83,16 +84,23 @@ def LoadPioPlatform(env, variables):
if "BOARD" not in env:
return

# update board manifest with a custom data
board_config = env.BoardConfig()
for k in variables.keys():
if k in env or \
not any([k.startswith("BOARD_"), k.startswith("UPLOAD_")]):
for key, value in variables.UnknownVariables().items():
if not key.startswith("BOARD_"):
continue
_opt, _val = k.lower().split("_", 1)
board_config.update(key.lower()[6:], base64.b64decode(value))

# update default environment variables
for key in variables.keys():
if key in env or \
not any([key.startswith("BOARD_"), key.startswith("UPLOAD_")]):
continue
_opt, _val = key.lower().split("_", 1)
if _opt == "board":
_opt = "build"
if _val in board_config.get(_opt):
env.Replace(**{k: board_config.get("%s.%s" % (_opt, _val))})
env.Replace(**{key: board_config.get("%s.%s" % (_opt, _val))})

if "build.ldscript" in board_config:
env.Replace(LDSCRIPT_PATH=board_config.get("build.ldscript"))
Expand Down
6 changes: 3 additions & 3 deletions platformio/builder/tools/platformio.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from os import sep, walk
from os.path import basename, dirname, isdir, join, realpath

from SCons import Action, Builder, Util
from SCons import Builder, Util
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild,
DefaultEnvironment, SConscript)

Expand Down Expand Up @@ -108,8 +108,8 @@ def _append_pio_macros():
program = env.Program(
join("$BUILD_DIR", env.subst("$PROGNAME")), env['PIOBUILDFILES'])

checksize_action = Action.Action(env.CheckUploadSize,
"Checking program size")
checksize_action = env.VerboseAction(env.CheckUploadSize,
"Checking program size")
AlwaysBuild(env.Alias("checkprogsize", program, checksize_action))
if set(["upload", "program"]) & set(COMMAND_LINE_TARGETS):
env.AddPostAction(program, checksize_action)
Expand Down
31 changes: 19 additions & 12 deletions platformio/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,15 @@ class EnvironmentProcessor(object):
"src_dir", "build_dir", "data_dir", "test_dir",
"boards_dir", "lib_extra_dirs")

KNOWN_ENV_OPTIONS = ("platform", "framework", "board", "board_mcu",
"board_f_cpu", "board_f_flash", "board_flash_mode",
"build_flags", "src_build_flags", "build_unflags",
"src_filter", "extra_scripts", "targets",
"upload_port", "upload_protocol", "upload_speed",
"upload_flags", "upload_resetmethod", "lib_deps",
"lib_ignore", "lib_extra_dirs", "lib_ldf_mode",
"lib_compat_mode", "lib_archive", "piotest",
"test_transport", "test_filter", "test_ignore",
"test_port", "test_speed", "debug_tool", "debug_port",
KNOWN_ENV_OPTIONS = ("platform", "framework", "board", "build_flags",
"src_build_flags", "build_unflags", "src_filter",
"extra_scripts", "targets", "upload_port",
"upload_protocol", "upload_speed", "upload_flags",
"upload_resetmethod", "lib_deps", "lib_ignore",
"lib_extra_dirs", "lib_ldf_mode", "lib_compat_mode",
"lib_archive", "piotest", "test_transport",
"test_filter", "test_ignore", "test_port",
"test_speed", "debug_tool", "debug_port",
"debug_init_cmds", "debug_extra_cmds", "debug_server",
"debug_init_break", "debug_load_cmd",
"debug_load_mode", "debug_svd_path", "monitor_port",
Expand All @@ -160,7 +159,11 @@ class EnvironmentProcessor(object):
"lib_use": "lib_deps",
"lib_force": "lib_deps",
"extra_script": "extra_scripts",
"monitor_baud": "monitor_speed"
"monitor_baud": "monitor_speed",
"board_mcu": "board_build.mcu",
"board_f_cpu": "board_build.f_cpu",
"board_f_flash": "board_build.f_flash",
"board_flash_mode": "board_build.flash_mode"
}

RENAMED_PLATFORMS = {"espressif": "espressif8266"}
Expand Down Expand Up @@ -238,7 +241,11 @@ def _validate_options(self, options):
v = self.RENAMED_PLATFORMS[v]

# warn about unknown options
if k not in self.KNOWN_ENV_OPTIONS and not k.startswith("custom_"):
unknown_conditions = [
k not in self.KNOWN_ENV_OPTIONS, not k.startswith("custom_"),
not k.startswith("board_")
]
if all(unknown_conditions):
click.secho(
"Detected non-PlatformIO `%s` option in `[env:%s]` section"
% (k, self.name),
Expand Down

0 comments on commit 9ba5dc0

Please sign in to comment.