forked from platformio/platformio-core
Better handling "clean" & "monitor" targets
This commit is contained in:
@ -168,7 +168,7 @@ env.SConsignFile(
|
|||||||
env.SConscript(env.GetExtraScripts("pre"), exports="env")
|
env.SConscript(env.GetExtraScripts("pre"), exports="env")
|
||||||
|
|
||||||
if env.IsCleanTarget():
|
if env.IsCleanTarget():
|
||||||
env.CleanProject("cleanall" in COMMAND_LINE_TARGETS)
|
env.CleanProject(fullclean=int(ARGUMENTS.get("FULLCLEAN", 0)))
|
||||||
env.Exit(0)
|
env.Exit(0)
|
||||||
|
|
||||||
env.SConscript("$BUILD_SCRIPT")
|
env.SConscript("$BUILD_SCRIPT")
|
||||||
|
@ -16,7 +16,6 @@ import os
|
|||||||
|
|
||||||
from SCons.Action import Action # pylint: disable=import-error
|
from SCons.Action import Action # pylint: disable=import-error
|
||||||
from SCons.Script import ARGUMENTS # pylint: disable=import-error
|
from SCons.Script import ARGUMENTS # pylint: disable=import-error
|
||||||
from SCons.Script import COMMAND_LINE_TARGETS # pylint: disable=import-error
|
|
||||||
from SCons.Script import AlwaysBuild # pylint: disable=import-error
|
from SCons.Script import AlwaysBuild # pylint: disable=import-error
|
||||||
|
|
||||||
from platformio import compat, fs
|
from platformio import compat, fs
|
||||||
@ -29,10 +28,10 @@ def VerboseAction(_, act, actstr):
|
|||||||
|
|
||||||
|
|
||||||
def IsCleanTarget(env):
|
def IsCleanTarget(env):
|
||||||
return env.GetOption("clean") or ("cleanall" in COMMAND_LINE_TARGETS)
|
return env.GetOption("clean")
|
||||||
|
|
||||||
|
|
||||||
def CleanProject(env, clean_all=False):
|
def CleanProject(env, fullclean=False):
|
||||||
def _relpath(path):
|
def _relpath(path):
|
||||||
if compat.IS_WINDOWS:
|
if compat.IS_WINDOWS:
|
||||||
prefix = os.getcwd()[:2].lower()
|
prefix = os.getcwd()[:2].lower()
|
||||||
@ -56,7 +55,7 @@ def CleanProject(env, clean_all=False):
|
|||||||
else:
|
else:
|
||||||
print("Build environment is clean")
|
print("Build environment is clean")
|
||||||
|
|
||||||
if clean_all and os.path.isdir(libdeps_dir):
|
if fullclean and os.path.isdir(libdeps_dir):
|
||||||
_clean_dir(libdeps_dir)
|
_clean_dir(libdeps_dir)
|
||||||
|
|
||||||
print("Done cleaning")
|
print("Done cleaning")
|
||||||
|
@ -25,6 +25,7 @@ from platformio import app, fs, proc, telemetry
|
|||||||
from platformio.compat import hashlib_encode_data
|
from platformio.compat import hashlib_encode_data
|
||||||
from platformio.package.manager.core import get_core_package_dir
|
from platformio.package.manager.core import get_core_package_dir
|
||||||
from platformio.platform.exception import BuildScriptNotFound
|
from platformio.platform.exception import BuildScriptNotFound
|
||||||
|
from platformio.run.helpers import KNOWN_CLEAN_TARGETS, KNOWN_FULLCLEAN_TARGETS
|
||||||
|
|
||||||
|
|
||||||
class PlatformRunMixin:
|
class PlatformRunMixin:
|
||||||
@ -56,9 +57,6 @@ class PlatformRunMixin:
|
|||||||
self.silent = silent
|
self.silent = silent
|
||||||
self.verbose = verbose or app.get_setting("force_verbose")
|
self.verbose = verbose or app.get_setting("force_verbose")
|
||||||
|
|
||||||
if "clean" in targets:
|
|
||||||
targets = ["-c", "."]
|
|
||||||
|
|
||||||
variables["platform_manifest"] = self.manifest_path
|
variables["platform_manifest"] = self.manifest_path
|
||||||
|
|
||||||
if "build_script" not in variables:
|
if "build_script" not in variables:
|
||||||
@ -92,10 +90,18 @@ class PlatformRunMixin:
|
|||||||
"--sconstruct",
|
"--sconstruct",
|
||||||
os.path.join(fs.get_source_dir(), "builder", "main.py"),
|
os.path.join(fs.get_source_dir(), "builder", "main.py"),
|
||||||
]
|
]
|
||||||
args.append("PIOVERBOSE=%d" % (1 if self.verbose else 0))
|
args.append("PIOVERBOSE=%d" % int(self.verbose))
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
args.append("ISATTY=%d" % (1 if click._compat.isatty(sys.stdout) else 0))
|
args.append("ISATTY=%d" % int(click._compat.isatty(sys.stdout)))
|
||||||
args += targets
|
|
||||||
|
if set(KNOWN_CLEAN_TARGETS + KNOWN_FULLCLEAN_TARGETS) & set(targets):
|
||||||
|
args.append("--clean")
|
||||||
|
args.append(
|
||||||
|
"FULLCLEAN=%d"
|
||||||
|
% (1 if set(KNOWN_FULLCLEAN_TARGETS) & set(targets) else 0)
|
||||||
|
)
|
||||||
|
elif targets:
|
||||||
|
args.extend(targets)
|
||||||
|
|
||||||
# encode and append variables
|
# encode and append variables
|
||||||
for key, value in variables.items():
|
for key, value in variables.items():
|
||||||
|
@ -26,7 +26,7 @@ from platformio.device.monitor.command import device_monitor_cmd
|
|||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
from platformio.project.exception import ProjectError
|
from platformio.project.exception import ProjectError
|
||||||
from platformio.project.helpers import find_project_dir_above, load_build_metadata
|
from platformio.project.helpers import find_project_dir_above, load_build_metadata
|
||||||
from platformio.run.helpers import clean_build_dir, handle_legacy_libdeps
|
from platformio.run.helpers import clean_build_dir
|
||||||
from platformio.run.processor import EnvironmentProcessor
|
from platformio.run.processor import EnvironmentProcessor
|
||||||
from platformio.test.runners.base import CTX_META_TEST_IS_RUNNING
|
from platformio.test.runners.base import CTX_META_TEST_IS_RUNNING
|
||||||
|
|
||||||
@ -97,10 +97,12 @@ def cli(
|
|||||||
if os.path.isfile(project_dir):
|
if os.path.isfile(project_dir):
|
||||||
project_dir = find_project_dir_above(project_dir)
|
project_dir = find_project_dir_above(project_dir)
|
||||||
|
|
||||||
|
targets = list(target) if target else []
|
||||||
|
del target
|
||||||
|
only_monitor = targets == ["monitor"]
|
||||||
is_test_running = CTX_META_TEST_IS_RUNNING in ctx.meta
|
is_test_running = CTX_META_TEST_IS_RUNNING in ctx.meta
|
||||||
|
|
||||||
only_monitor = "monitor" in target and len(target) == 1
|
|
||||||
command_failed = False
|
command_failed = False
|
||||||
|
|
||||||
with fs.cd(project_dir):
|
with fs.cd(project_dir):
|
||||||
config = ProjectConfig.get_instance(project_conf)
|
config = ProjectConfig.get_instance(project_conf)
|
||||||
config.validate(environment)
|
config.validate(environment)
|
||||||
@ -108,59 +110,60 @@ def cli(
|
|||||||
if list_targets:
|
if list_targets:
|
||||||
return print_target_list(list(environment) or config.envs())
|
return print_target_list(list(environment) or config.envs())
|
||||||
|
|
||||||
if not only_monitor:
|
# clean obsolete build dir
|
||||||
# clean obsolete build dir
|
if not only_monitor and not disable_auto_clean:
|
||||||
if not disable_auto_clean:
|
build_dir = config.get("platformio", "build_dir")
|
||||||
build_dir = config.get("platformio", "build_dir")
|
try:
|
||||||
try:
|
clean_build_dir(build_dir, config)
|
||||||
clean_build_dir(build_dir, config)
|
except ProjectError as exc:
|
||||||
except ProjectError as exc:
|
raise exc
|
||||||
raise exc
|
except: # pylint: disable=bare-except
|
||||||
except: # pylint: disable=bare-except
|
click.secho(
|
||||||
click.secho(
|
"Can not remove temporary directory `%s`. Please remove "
|
||||||
"Can not remove temporary directory `%s`. Please remove "
|
"it manually to avoid build issues" % build_dir,
|
||||||
"it manually to avoid build issues" % build_dir,
|
fg="yellow",
|
||||||
fg="yellow",
|
|
||||||
)
|
|
||||||
|
|
||||||
default_envs = config.default_envs()
|
|
||||||
results = []
|
|
||||||
for env in config.envs():
|
|
||||||
skipenv = any(
|
|
||||||
[
|
|
||||||
environment and env not in environment,
|
|
||||||
not environment and default_envs and env not in default_envs,
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
if skipenv:
|
|
||||||
results.append({"env": env})
|
|
||||||
continue
|
|
||||||
|
|
||||||
# print empty line between multi environment project
|
default_envs = config.default_envs()
|
||||||
if not silent and any(r.get("succeeded") is not None for r in results):
|
results = []
|
||||||
click.echo()
|
for env in config.envs():
|
||||||
|
skipenv = any(
|
||||||
|
[
|
||||||
|
environment and env not in environment,
|
||||||
|
not environment and default_envs and env not in default_envs,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if skipenv:
|
||||||
|
results.append({"env": env})
|
||||||
|
continue
|
||||||
|
|
||||||
results.append(
|
# print empty line between multi environment project
|
||||||
process_env(
|
if not silent and any(r.get("succeeded") is not None for r in results):
|
||||||
ctx,
|
click.echo()
|
||||||
env,
|
|
||||||
config,
|
results.append(
|
||||||
target,
|
process_env(
|
||||||
upload_port,
|
ctx,
|
||||||
jobs,
|
env,
|
||||||
program_args,
|
config,
|
||||||
is_test_running,
|
targets,
|
||||||
silent,
|
upload_port,
|
||||||
verbose,
|
monitor_port,
|
||||||
)
|
jobs,
|
||||||
|
program_args,
|
||||||
|
is_test_running,
|
||||||
|
silent,
|
||||||
|
verbose,
|
||||||
)
|
)
|
||||||
command_failed = any(r.get("succeeded") is False for r in results)
|
)
|
||||||
if (
|
command_failed = any(r.get("succeeded") is False for r in results)
|
||||||
not is_test_running
|
if (
|
||||||
and (command_failed or not silent)
|
not is_test_running
|
||||||
and len(results) > 1
|
and not only_monitor
|
||||||
):
|
and (command_failed or not silent)
|
||||||
print_processing_summary(results, verbose)
|
and len(results) > 1
|
||||||
|
):
|
||||||
|
print_processing_summary(results, verbose)
|
||||||
|
|
||||||
# Reset custom project config
|
# Reset custom project config
|
||||||
app.set_session_var("custom_project_conf", None)
|
app.set_session_var("custom_project_conf", None)
|
||||||
@ -168,14 +171,6 @@ def cli(
|
|||||||
if command_failed:
|
if command_failed:
|
||||||
raise exception.ReturnErrorCode(1)
|
raise exception.ReturnErrorCode(1)
|
||||||
|
|
||||||
if "monitor" in target and "nobuild" not in target:
|
|
||||||
ctx.invoke(
|
|
||||||
device_monitor_cmd,
|
|
||||||
project_dir=project_dir,
|
|
||||||
port=monitor_port,
|
|
||||||
environment=environment[0] if environment else None,
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -185,6 +180,7 @@ def process_env(
|
|||||||
config,
|
config,
|
||||||
targets,
|
targets,
|
||||||
upload_port,
|
upload_port,
|
||||||
|
monitor_port,
|
||||||
jobs,
|
jobs,
|
||||||
program_args,
|
program_args,
|
||||||
is_test_running,
|
is_test_running,
|
||||||
@ -194,22 +190,38 @@ def process_env(
|
|||||||
if not is_test_running and not silent:
|
if not is_test_running and not silent:
|
||||||
print_processing_header(name, config, verbose)
|
print_processing_header(name, config, verbose)
|
||||||
|
|
||||||
ep = EnvironmentProcessor(
|
targets = targets or config.get(f"env:{name}", "targets", [])
|
||||||
ctx,
|
only_monitor = targets == ["monitor"]
|
||||||
name,
|
result = {"env": name, "duration": time(), "succeeded": True}
|
||||||
config,
|
|
||||||
targets,
|
if not only_monitor:
|
||||||
upload_port,
|
result["succeeded"] = EnvironmentProcessor(
|
||||||
jobs,
|
ctx,
|
||||||
program_args,
|
name,
|
||||||
silent,
|
config,
|
||||||
verbose,
|
[t for t in targets if t != "monitor"],
|
||||||
)
|
upload_port,
|
||||||
result = {"env": name, "duration": time(), "succeeded": ep.process()}
|
jobs,
|
||||||
|
program_args,
|
||||||
|
silent,
|
||||||
|
verbose,
|
||||||
|
).process()
|
||||||
|
|
||||||
|
if "monitor" in targets and "nobuild" not in targets:
|
||||||
|
ctx.invoke(
|
||||||
|
device_monitor_cmd,
|
||||||
|
port=monitor_port,
|
||||||
|
environment=name,
|
||||||
|
)
|
||||||
|
|
||||||
result["duration"] = time() - result["duration"]
|
result["duration"] = time() - result["duration"]
|
||||||
|
|
||||||
# print footer on error or when is not unit testing
|
# print footer on error or when is not unit testing
|
||||||
if not is_test_running and (not silent or not result["succeeded"]):
|
if (
|
||||||
|
not is_test_running
|
||||||
|
and not only_monitor
|
||||||
|
and (not silent or not result["succeeded"])
|
||||||
|
):
|
||||||
print_processing_footer(result)
|
print_processing_footer(result)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -18,6 +18,10 @@ from os.path import isdir, isfile, join
|
|||||||
from platformio import fs
|
from platformio import fs
|
||||||
from platformio.project.helpers import compute_project_checksum, get_project_dir
|
from platformio.project.helpers import compute_project_checksum, get_project_dir
|
||||||
|
|
||||||
|
KNOWN_CLEAN_TARGETS = ("clean",)
|
||||||
|
KNOWN_FULLCLEAN_TARGETS = ("cleanall", "fullclean")
|
||||||
|
KNOWN_ALLCLEAN_TARGETS = KNOWN_CLEAN_TARGETS + KNOWN_FULLCLEAN_TARGETS
|
||||||
|
|
||||||
|
|
||||||
def clean_build_dir(build_dir, config):
|
def clean_build_dir(build_dir, config):
|
||||||
# remove legacy ".pioenvs" folder
|
# remove legacy ".pioenvs" folder
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
from platformio.package.commands.install import install_project_env_dependencies
|
from platformio.package.commands.install import install_project_env_dependencies
|
||||||
from platformio.platform.factory import PlatformFactory
|
from platformio.platform.factory import PlatformFactory
|
||||||
from platformio.project.exception import UndefinedEnvPlatformError
|
from platformio.project.exception import UndefinedEnvPlatformError
|
||||||
|
from platformio.run.helpers import KNOWN_ALLCLEAN_TARGETS
|
||||||
from platformio.test.runners.base import CTX_META_TEST_RUNNING_NAME
|
from platformio.test.runners.base import CTX_META_TEST_RUNNING_NAME
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
@ -36,7 +37,7 @@ class EnvironmentProcessor:
|
|||||||
self.cmd_ctx = cmd_ctx
|
self.cmd_ctx = cmd_ctx
|
||||||
self.name = name
|
self.name = name
|
||||||
self.config = config
|
self.config = config
|
||||||
self.targets = [str(t) for t in targets]
|
self.targets = targets
|
||||||
self.upload_port = upload_port
|
self.upload_port = upload_port
|
||||||
self.jobs = jobs
|
self.jobs = jobs
|
||||||
self.program_args = program_args
|
self.program_args = program_args
|
||||||
@ -61,33 +62,29 @@ class EnvironmentProcessor:
|
|||||||
variables["upload_port"] = self.upload_port
|
variables["upload_port"] = self.upload_port
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
def get_build_targets(self):
|
|
||||||
return (
|
|
||||||
self.targets
|
|
||||||
if self.targets
|
|
||||||
else self.config.get("env:" + self.name, "targets", [])
|
|
||||||
)
|
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
if "platform" not in self.options:
|
if "platform" not in self.options:
|
||||||
raise UndefinedEnvPlatformError(self.name)
|
raise UndefinedEnvPlatformError(self.name)
|
||||||
|
|
||||||
build_vars = self.get_build_variables()
|
build_vars = self.get_build_variables()
|
||||||
build_targets = list(self.get_build_targets())
|
is_clean = set(KNOWN_ALLCLEAN_TARGETS) & set(self.targets)
|
||||||
|
build_targets = list(set(self.targets) - set(KNOWN_ALLCLEAN_TARGETS))
|
||||||
|
|
||||||
# skip monitor target, we call it above
|
# pre-clean
|
||||||
if "monitor" in build_targets:
|
if is_clean:
|
||||||
build_targets.remove("monitor")
|
result = PlatformFactory.new(
|
||||||
|
self.options["platform"], autoinstall=True
|
||||||
if not set(["clean", "cleanall"]) & set(build_targets):
|
).run(build_vars, self.targets, self.silent, self.verbose, self.jobs)
|
||||||
install_project_env_dependencies(
|
if not build_targets:
|
||||||
self.name,
|
return result["returncode"] == 0
|
||||||
{
|
|
||||||
"project_targets": build_targets,
|
|
||||||
"piotest_running_name": build_vars.get("piotest_running_name"),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
install_project_env_dependencies(
|
||||||
|
self.name,
|
||||||
|
{
|
||||||
|
"project_targets": self.targets,
|
||||||
|
"piotest_running_name": build_vars.get("piotest_running_name"),
|
||||||
|
},
|
||||||
|
)
|
||||||
result = PlatformFactory.new(self.options["platform"], autoinstall=True).run(
|
result = PlatformFactory.new(self.options["platform"], autoinstall=True).run(
|
||||||
build_vars, build_targets, self.silent, self.verbose, self.jobs
|
build_vars, build_targets, self.silent, self.verbose, self.jobs
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user