From 68a3b3f9e721e638d1378460a12c4f88c53b396d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 7 Jun 2019 17:22:02 +0300 Subject: [PATCH] Custom platform_packages per a build environment with an option to override default // Resolve #1367 --- HISTORY.rst | 1 + docs | 2 +- platformio/builder/tools/pioplatform.py | 8 ++----- platformio/managers/platform.py | 29 +++++++++++++++++++------ platformio/project/options.py | 3 ++- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 65a57d1c..34c2cd80 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -34,6 +34,7 @@ PlatformIO 4.0 - Switched to workspace ``.pio/build`` folder for build artifacts instead of ``.pioenvs`` - Switch between `Build Configurations `__ (``release`` and ``debug``) with a new project configuration option `build_type `__ + - Custom `platform_packages `__ per a build environment with an option to override default (`issue #1367 `_) - Print platform package details, such as version, VSC source and commit (`issue #2155 `_) - Override default `"platformio.ini" (Project Configuration File) `__ with a custom using ``-c, --project-conf`` option for `platformio run `__, `platformio debug `__, or `platformio test `__ commands (`issue #1913 `_) - Override default development platform upload command with a custom `upload_command `__ (`issue #2599 `_) diff --git a/docs b/docs index 66e41937..7ea74ad0 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 66e419376752449b73bfb37aec9bb4cb47580bc3 +Subproject commit 7ea74ad00610cdcb3155c5ccdcf6f85d667ffb81 diff --git a/platformio/builder/tools/pioplatform.py b/platformio/builder/tools/pioplatform.py index a2971bce..09d71287 100644 --- a/platformio/builder/tools/pioplatform.py +++ b/platformio/builder/tools/pioplatform.py @@ -29,22 +29,18 @@ from platformio.project.config import ProjectOptions @util.memoized() -def initPioPlatform(name): - return PlatformFactory.newPlatform(name) - - def PioPlatform(env): variables = env.GetProjectOptions(as_dict=True) if "framework" in variables: # support PIO Core 3.0 dev/platforms variables['pioframework'] = variables['framework'] - p = initPioPlatform(env['PLATFORM_MANIFEST']) + p = PlatformFactory.newPlatform(env['PLATFORM_MANIFEST']) p.configure_default_packages(variables, COMMAND_LINE_TARGETS) return p def BoardConfig(env, board=None): - p = initPioPlatform(env['PLATFORM_MANIFEST']) + p = env.PioPlatform() try: board = board or env.get("BOARD") assert board, "BoardConfig: Board is not defined" diff --git a/platformio/managers/platform.py b/platformio/managers/platform.py index 506275c5..75b24417 100644 --- a/platformio/managers/platform.py +++ b/platformio/managers/platform.py @@ -490,16 +490,17 @@ class PlatformBase( # pylint: disable=too-many-public-methods _BOARDS_CACHE = {} def __init__(self, manifest_path): - self._BOARDS_CACHE = {} self.manifest_path = manifest_path + self.silent = False + self.verbose = False + + self._BOARDS_CACHE = {} self._manifest = util.load_json(manifest_path) + self._custom_packages = None self.pm = PackageManager(get_project_packages_dir(), self.package_repositories) - self.silent = False - self.verbose = False - # if self.engines and "platformio" in self.engines: # if self.PIO_VERSION not in semantic_version.Spec( # self.engines['platformio']): @@ -560,9 +561,20 @@ class PlatformBase( # pylint: disable=too-many-public-methods @property def packages(self): - if "packages" not in self._manifest: - self._manifest['packages'] = {} - return self._manifest['packages'] + packages = self._manifest.get("packages", {}) + for item in (self._custom_packages or []): + name = item + version = "*" + if "@" in item: + name, version = item.split("@", 2) + name = name.strip() + if name not in packages: + packages[name] = {} + packages[name].update({ + "version": version.strip(), + "optional": False + }) + return packages def get_dir(self): return dirname(self.manifest_path) @@ -626,6 +638,9 @@ class PlatformBase( # pylint: disable=too-many-public-methods return self.packages[name].get("type") def configure_default_packages(self, options, targets): + # override user custom packages + self._custom_packages = options.get("platform_packages") + # enable used frameworks for framework in options.get("framework", []): if not self.frameworks: diff --git a/platformio/project/options.py b/platformio/project/options.py index 846f28dc..1b49bf42 100644 --- a/platformio/project/options.py +++ b/platformio/project/options.py @@ -91,9 +91,9 @@ ProjectOptions = OrderedDict([ # Generic ConfigEnvOption(name="platform", buildenvvar="PIOPLATFORM"), + ConfigEnvOption(name="platform_packages", multiple=True), ConfigEnvOption( name="framework", multiple=True, buildenvvar="PIOFRAMEWORK"), - ConfigEnvOption(name="targets", multiple=True), # Board ConfigEnvOption(name="board", buildenvvar="BOARD"), @@ -129,6 +129,7 @@ ProjectOptions = OrderedDict([ multiple=True, sysenvvar="PLATFORMIO_SRC_FILTER", buildenvvar="SRC_FILTER"), + ConfigEnvOption(name="targets", multiple=True), # Upload ConfigEnvOption(name="upload_port",