2019-05-30 17:08:00 +03:00
|
|
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
2022-03-08 14:58:01 +02:00
|
|
|
from platformio.package.commands.install import install_project_env_dependencies
|
2022-03-19 18:07:19 +02:00
|
|
|
from platformio.platform.factory import PlatformFactory
|
2019-11-28 16:15:54 +02:00
|
|
|
from platformio.project.exception import UndefinedEnvPlatformError
|
2023-04-25 20:47:04 +03:00
|
|
|
from platformio.run.helpers import KNOWN_ALLCLEAN_TARGETS
|
2022-04-26 15:09:51 +03:00
|
|
|
from platformio.test.runners.base import CTX_META_TEST_RUNNING_NAME
|
2019-05-30 17:08:00 +03:00
|
|
|
|
|
|
|
|
# pylint: disable=too-many-instance-attributes
|
|
|
|
|
|
|
|
|
|
|
2022-07-02 19:03:25 +03:00
|
|
|
class EnvironmentProcessor:
|
2019-05-30 17:08:00 +03:00
|
|
|
def __init__( # pylint: disable=too-many-arguments
|
2022-05-07 16:22:05 +03:00
|
|
|
self,
|
|
|
|
|
cmd_ctx,
|
|
|
|
|
name,
|
|
|
|
|
config,
|
|
|
|
|
targets,
|
|
|
|
|
upload_port,
|
|
|
|
|
jobs,
|
|
|
|
|
program_args,
|
|
|
|
|
silent,
|
|
|
|
|
verbose,
|
2019-09-23 23:13:48 +03:00
|
|
|
):
|
2019-05-30 17:08:00 +03:00
|
|
|
self.cmd_ctx = cmd_ctx
|
2019-06-10 19:44:18 +03:00
|
|
|
self.name = name
|
2019-05-30 17:08:00 +03:00
|
|
|
self.config = config
|
2023-04-25 20:47:04 +03:00
|
|
|
self.targets = targets
|
2019-05-30 17:08:00 +03:00
|
|
|
self.upload_port = upload_port
|
2022-05-07 16:22:05 +03:00
|
|
|
self.jobs = jobs
|
|
|
|
|
self.program_args = program_args
|
2019-05-30 17:08:00 +03:00
|
|
|
self.silent = silent
|
|
|
|
|
self.verbose = verbose
|
|
|
|
|
self.options = config.items(env=name, as_dict=True)
|
|
|
|
|
|
|
|
|
|
def get_build_variables(self):
|
2022-05-07 16:22:05 +03:00
|
|
|
variables = dict(
|
|
|
|
|
pioenv=self.name,
|
|
|
|
|
project_config=self.config.path,
|
|
|
|
|
program_args=self.program_args,
|
|
|
|
|
)
|
2019-05-31 15:47:25 +03:00
|
|
|
|
|
|
|
|
if CTX_META_TEST_RUNNING_NAME in self.cmd_ctx.meta:
|
2019-09-23 23:13:48 +03:00
|
|
|
variables["piotest_running_name"] = self.cmd_ctx.meta[
|
|
|
|
|
CTX_META_TEST_RUNNING_NAME
|
|
|
|
|
]
|
2019-05-31 15:47:25 +03:00
|
|
|
|
2019-05-30 17:08:00 +03:00
|
|
|
if self.upload_port:
|
|
|
|
|
# override upload port with a custom from CLI
|
2019-09-23 23:13:48 +03:00
|
|
|
variables["upload_port"] = self.upload_port
|
2019-05-30 17:08:00 +03:00
|
|
|
return variables
|
|
|
|
|
|
2019-08-17 20:55:16 +03:00
|
|
|
def process(self):
|
2019-05-30 17:08:00 +03:00
|
|
|
if "platform" not in self.options:
|
2019-11-28 16:15:54 +02:00
|
|
|
raise UndefinedEnvPlatformError(self.name)
|
2019-05-30 17:08:00 +03:00
|
|
|
|
|
|
|
|
build_vars = self.get_build_variables()
|
2023-04-25 20:47:04 +03:00
|
|
|
is_clean = set(KNOWN_ALLCLEAN_TARGETS) & set(self.targets)
|
2023-04-25 22:32:18 +03:00
|
|
|
build_targets = [t for t in self.targets if t not in KNOWN_ALLCLEAN_TARGETS]
|
2019-05-30 17:08:00 +03:00
|
|
|
|
2023-04-25 20:47:04 +03:00
|
|
|
# pre-clean
|
|
|
|
|
if is_clean:
|
|
|
|
|
result = PlatformFactory.new(
|
|
|
|
|
self.options["platform"], autoinstall=True
|
|
|
|
|
).run(build_vars, self.targets, self.silent, self.verbose, self.jobs)
|
|
|
|
|
if not build_targets:
|
|
|
|
|
return result["returncode"] == 0
|
2022-03-08 14:58:01 +02:00
|
|
|
|
2023-04-25 20:47:04 +03:00
|
|
|
install_project_env_dependencies(
|
|
|
|
|
self.name,
|
|
|
|
|
{
|
|
|
|
|
"project_targets": self.targets,
|
|
|
|
|
"piotest_running_name": build_vars.get("piotest_running_name"),
|
|
|
|
|
},
|
|
|
|
|
)
|
2022-04-10 13:56:44 +03:00
|
|
|
result = PlatformFactory.new(self.options["platform"], autoinstall=True).run(
|
2021-04-01 21:15:14 +03:00
|
|
|
build_vars, build_targets, self.silent, self.verbose, self.jobs
|
|
|
|
|
)
|
2019-09-23 23:13:48 +03:00
|
|
|
return result["returncode"] == 0
|