2017-06-05 16:02:39 +03:00
|
|
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
2015-11-18 17:16:17 +02:00
|
|
|
#
|
|
|
|
# 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.
|
2014-06-03 21:27:36 +03:00
|
|
|
|
2015-02-15 00:27:28 +02:00
|
|
|
from datetime import datetime
|
2015-06-04 22:50:13 +03:00
|
|
|
from hashlib import sha1
|
|
|
|
from os import getcwd, makedirs, walk
|
2018-01-26 22:24:49 +02:00
|
|
|
from os.path import getmtime, isdir, isfile, join
|
2015-02-15 00:27:28 +02:00
|
|
|
from time import time
|
2015-02-14 00:12:16 +02:00
|
|
|
|
2014-12-03 20:16:50 +02:00
|
|
|
import click
|
2014-06-03 21:27:36 +03:00
|
|
|
|
2016-08-02 19:10:29 +03:00
|
|
|
from platformio import __version__, exception, telemetry, util
|
2017-06-26 17:14:38 +03:00
|
|
|
from platformio.commands.device import device_monitor as cmd_device_monitor
|
2015-05-01 13:49:18 +01:00
|
|
|
from platformio.commands.lib import lib_install as cmd_lib_install
|
2016-05-28 22:51:33 +03:00
|
|
|
from platformio.commands.platform import \
|
|
|
|
platform_install as cmd_platform_install
|
2018-01-13 19:44:05 +02:00
|
|
|
from platformio.managers.lib import LibraryManager, is_builtin_lib
|
2016-05-26 19:43:36 +03:00
|
|
|
from platformio.managers.platform import PlatformFactory
|
2014-06-03 21:27:36 +03:00
|
|
|
|
2016-08-28 00:03:54 +03:00
|
|
|
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches
|
|
|
|
|
2014-06-03 21:27:36 +03:00
|
|
|
|
2014-12-03 20:16:50 +02:00
|
|
|
@click.command("run", short_help="Process project environments")
|
2016-07-22 18:02:04 +03:00
|
|
|
@click.option("-e", "--environment", multiple=True)
|
|
|
|
@click.option("-t", "--target", multiple=True)
|
|
|
|
@click.option("--upload-port")
|
2016-08-03 23:38:20 +03:00
|
|
|
@click.option(
|
|
|
|
"-d",
|
|
|
|
"--project-dir",
|
|
|
|
default=getcwd,
|
|
|
|
type=click.Path(
|
|
|
|
exists=True,
|
2016-08-27 20:32:21 +03:00
|
|
|
file_okay=True,
|
2016-08-03 23:38:20 +03:00
|
|
|
dir_okay=True,
|
|
|
|
writable=True,
|
|
|
|
resolve_path=True))
|
2016-08-21 19:27:38 +03:00
|
|
|
@click.option("-s", "--silent", is_flag=True)
|
2016-07-22 18:02:04 +03:00
|
|
|
@click.option("-v", "--verbose", is_flag=True)
|
2015-07-21 14:53:38 +03:00
|
|
|
@click.option("--disable-auto-clean", is_flag=True)
|
2014-12-03 20:16:50 +02:00
|
|
|
@click.pass_context
|
2016-08-28 00:03:54 +03:00
|
|
|
def cli(ctx, environment, target, upload_port, project_dir, silent, verbose,
|
2016-08-03 23:38:20 +03:00
|
|
|
disable_auto_clean):
|
2016-08-27 20:32:21 +03:00
|
|
|
# find project directory on upper level
|
|
|
|
if isfile(project_dir):
|
|
|
|
project_dir = util.find_project_dir_above(project_dir)
|
|
|
|
|
|
|
|
if not util.is_platformio_project(project_dir):
|
|
|
|
raise exception.NotPlatformIOProject(project_dir)
|
|
|
|
|
2015-05-25 23:26:35 +03:00
|
|
|
with util.cd(project_dir):
|
2018-01-03 15:47:02 +02:00
|
|
|
# clean obsolete build dir
|
2015-07-21 14:53:38 +03:00
|
|
|
if not disable_auto_clean:
|
2015-10-06 17:06:47 +01:00
|
|
|
try:
|
2018-01-03 15:47:02 +02:00
|
|
|
_clean_build_dir(util.get_projectbuild_dir())
|
2016-01-28 00:56:25 +02:00
|
|
|
except: # pylint: disable=bare-except
|
2016-01-28 00:37:16 +02:00
|
|
|
click.secho(
|
|
|
|
"Can not remove temporary directory `%s`. Please remove "
|
2018-01-03 15:47:02 +02:00
|
|
|
"it manually to avoid build issues" %
|
|
|
|
util.get_projectbuild_dir(force=True),
|
2016-08-01 00:19:43 +03:00
|
|
|
fg="yellow")
|
2015-05-06 17:29:58 +01:00
|
|
|
|
2016-07-18 15:36:08 +03:00
|
|
|
config = util.load_project_config()
|
2016-08-08 14:00:01 +03:00
|
|
|
check_project_defopts(config)
|
|
|
|
assert check_project_envs(config, environment)
|
|
|
|
|
2016-04-27 14:10:18 +03:00
|
|
|
env_default = None
|
|
|
|
if config.has_option("platformio", "env_default"):
|
2017-06-30 00:15:49 +03:00
|
|
|
env_default = util.parse_conf_multi_values(
|
|
|
|
config.get("platformio", "env_default"))
|
2016-04-27 14:10:18 +03:00
|
|
|
|
2016-11-16 17:31:56 +02:00
|
|
|
results = []
|
2016-09-18 01:11:55 +03:00
|
|
|
start_time = time()
|
2015-05-06 17:29:58 +01:00
|
|
|
for section in config.sections():
|
2015-05-15 22:40:29 +02:00
|
|
|
if not section.startswith("env:"):
|
2016-09-17 23:46:53 +03:00
|
|
|
continue
|
2015-05-06 18:07:17 +01:00
|
|
|
|
2015-05-15 22:40:29 +02:00
|
|
|
envname = section[4:]
|
2016-10-31 20:05:34 +02:00
|
|
|
skipenv = any([
|
2017-07-24 17:35:41 +03:00
|
|
|
environment and envname not in environment, not environment
|
|
|
|
and env_default and envname not in env_default
|
2016-10-31 20:05:34 +02:00
|
|
|
])
|
2016-08-03 23:38:20 +03:00
|
|
|
if skipenv:
|
2016-11-16 17:31:56 +02:00
|
|
|
results.append((envname, None))
|
2015-05-15 22:40:29 +02:00
|
|
|
continue
|
2015-02-15 00:27:28 +02:00
|
|
|
|
2016-12-08 14:15:13 +02:00
|
|
|
if not silent and results:
|
2015-05-15 22:40:29 +02:00
|
|
|
click.echo()
|
2014-12-04 23:17:45 +02:00
|
|
|
|
2015-05-15 22:40:29 +02:00
|
|
|
options = {}
|
|
|
|
for k, v in config.items(section):
|
|
|
|
options[k] = v
|
2016-06-15 14:10:42 +03:00
|
|
|
if "piotest" not in options and "piotest" in ctx.meta:
|
|
|
|
options['piotest'] = ctx.meta['piotest']
|
2014-12-04 23:17:45 +02:00
|
|
|
|
2016-08-03 23:38:20 +03:00
|
|
|
ep = EnvironmentProcessor(ctx, envname, options, target,
|
2016-08-21 19:27:38 +03:00
|
|
|
upload_port, silent, verbose)
|
2017-06-26 17:14:38 +03:00
|
|
|
result = (envname, ep.process())
|
|
|
|
results.append(result)
|
|
|
|
if result[1] and "monitor" in ep.get_build_targets() and \
|
|
|
|
"nobuild" not in ep.get_build_targets():
|
|
|
|
ctx.invoke(cmd_device_monitor)
|
2016-09-18 01:11:55 +03:00
|
|
|
|
2018-01-18 22:04:43 +02:00
|
|
|
found_error = any(status is False for (_, status) in results)
|
2016-12-08 14:15:13 +02:00
|
|
|
|
|
|
|
if (found_error or not silent) and len(results) > 1:
|
2016-09-18 01:11:55 +03:00
|
|
|
click.echo()
|
2016-10-03 16:47:23 +03:00
|
|
|
print_summary(results, start_time)
|
2016-09-18 01:11:55 +03:00
|
|
|
|
2016-12-08 14:15:13 +02:00
|
|
|
if found_error:
|
2016-11-12 00:28:49 +02:00
|
|
|
raise exception.ReturnErrorCode(1)
|
2016-08-21 19:27:38 +03:00
|
|
|
return True
|
2015-05-01 13:49:18 +01:00
|
|
|
|
|
|
|
|
2015-05-15 22:40:29 +02:00
|
|
|
class EnvironmentProcessor(object):
|
|
|
|
|
2017-06-24 16:07:40 +03:00
|
|
|
KNOWN_OPTIONS = ("platform", "framework", "board", "board_mcu",
|
|
|
|
"board_f_cpu", "board_f_flash", "board_flash_mode",
|
|
|
|
"build_flags", "src_build_flags", "build_unflags",
|
2017-06-30 00:15:49 +03:00
|
|
|
"src_filter", "extra_scripts", "targets", "upload_port",
|
2017-06-24 16:07:40 +03:00
|
|
|
"upload_protocol", "upload_speed", "upload_flags",
|
|
|
|
"upload_resetmethod", "lib_deps", "lib_ignore",
|
|
|
|
"lib_extra_dirs", "lib_ldf_mode", "lib_compat_mode",
|
2017-08-17 17:18:23 +03:00
|
|
|
"lib_archive", "piotest", "test_transport", "test_filter",
|
2018-01-04 16:14:56 +02:00
|
|
|
"test_ignore", "test_port", "test_speed", "debug_tool",
|
|
|
|
"debug_port", "debug_init_cmds", "debug_extra_cmds",
|
|
|
|
"debug_server", "debug_init_break", "debug_load_cmd",
|
|
|
|
"monitor_port", "monitor_baud", "monitor_rts",
|
|
|
|
"monitor_dtr")
|
2017-06-20 18:48:52 +03:00
|
|
|
|
2017-06-24 18:40:30 +03:00
|
|
|
IGNORE_BUILD_OPTIONS = ("test_transport", "test_filter", "test_ignore",
|
2018-01-04 16:14:56 +02:00
|
|
|
"test_port", "test_speed", "debug_tool",
|
|
|
|
"debug_port", "debug_init_cmds",
|
|
|
|
"debug_extra_cmds", "debug_server",
|
|
|
|
"debug_init_break", "debug_load_cmd",
|
|
|
|
"monitor_port", "monitor_baud", "monitor_rts",
|
|
|
|
"monitor_dtr")
|
2016-08-08 14:00:01 +03:00
|
|
|
|
|
|
|
REMAPED_OPTIONS = {"framework": "pioframework", "platform": "pioplatform"}
|
2016-07-17 16:05:28 +03:00
|
|
|
|
2017-06-30 00:15:49 +03:00
|
|
|
RENAMED_OPTIONS = {
|
|
|
|
"lib_use": "lib_deps",
|
|
|
|
"lib_force": "lib_deps",
|
|
|
|
"extra_script": "extra_scripts"
|
|
|
|
}
|
2015-06-28 19:20:31 +03:00
|
|
|
|
2016-09-03 19:35:40 +03:00
|
|
|
RENAMED_PLATFORMS = {"espressif": "espressif8266"}
|
|
|
|
|
2016-10-31 20:05:34 +02:00
|
|
|
def __init__(
|
|
|
|
self, # pylint: disable=R0913
|
|
|
|
cmd_ctx,
|
|
|
|
name,
|
|
|
|
options,
|
|
|
|
targets,
|
|
|
|
upload_port,
|
|
|
|
silent,
|
|
|
|
verbose):
|
2015-05-15 22:40:29 +02:00
|
|
|
self.cmd_ctx = cmd_ctx
|
|
|
|
self.name = name
|
2016-08-08 14:00:01 +03:00
|
|
|
self.options = options
|
2015-05-15 22:40:29 +02:00
|
|
|
self.targets = targets
|
|
|
|
self.upload_port = upload_port
|
2016-08-21 19:27:38 +03:00
|
|
|
self.silent = silent
|
2016-07-17 00:48:59 +03:00
|
|
|
self.verbose = verbose
|
2015-05-15 22:40:29 +02:00
|
|
|
|
|
|
|
def process(self):
|
|
|
|
terminal_width, _ = click.get_terminal_size()
|
|
|
|
start_time = time()
|
|
|
|
|
2016-08-08 16:03:17 +03:00
|
|
|
for k, v in self.options.items():
|
2017-04-02 21:58:38 +03:00
|
|
|
self.options[k] = self.options[k].strip()
|
2016-09-17 16:32:16 +03:00
|
|
|
|
2016-12-08 14:15:13 +02:00
|
|
|
if not self.silent:
|
2017-11-22 21:09:16 +02:00
|
|
|
click.echo("[%s] Processing %s (%s)" %
|
|
|
|
(datetime.now().strftime("%c"),
|
|
|
|
click.style(self.name, fg="cyan", bold=True),
|
|
|
|
"; ".join([
|
|
|
|
"%s: %s" %
|
|
|
|
(k, ", ".join(util.parse_conf_multi_values(v)))
|
|
|
|
for k, v in self.options.items()
|
|
|
|
])))
|
2016-12-08 14:15:13 +02:00
|
|
|
click.secho("-" * terminal_width, bold=True)
|
2015-05-15 22:40:29 +02:00
|
|
|
|
2016-08-08 14:00:01 +03:00
|
|
|
self.options = self._validate_options(self.options)
|
2015-05-15 22:40:29 +02:00
|
|
|
result = self._run()
|
|
|
|
is_error = result['returncode'] != 0
|
2016-12-08 14:15:13 +02:00
|
|
|
|
|
|
|
if self.silent and not is_error:
|
|
|
|
return True
|
|
|
|
|
2016-06-15 14:10:42 +03:00
|
|
|
if is_error or "piotest_processor" not in self.cmd_ctx.meta:
|
2016-08-03 23:38:20 +03:00
|
|
|
print_header(
|
2017-06-05 16:05:05 +03:00
|
|
|
"[%s] Took %.2f seconds" %
|
|
|
|
((click.style("ERROR", fg="red", bold=True)
|
|
|
|
if is_error else click.style(
|
|
|
|
"SUCCESS", fg="green", bold=True)), time() - start_time),
|
2016-08-03 23:38:20 +03:00
|
|
|
is_error=is_error)
|
2015-05-15 22:40:29 +02:00
|
|
|
|
|
|
|
return not is_error
|
|
|
|
|
2015-06-28 20:16:43 +03:00
|
|
|
def _validate_options(self, options):
|
|
|
|
result = {}
|
|
|
|
for k, v in options.items():
|
2015-06-28 19:20:31 +03:00
|
|
|
# process obsolete options
|
2016-08-08 14:00:01 +03:00
|
|
|
if k in self.RENAMED_OPTIONS:
|
2015-06-28 19:20:31 +03:00
|
|
|
click.secho(
|
2015-06-28 20:16:43 +03:00
|
|
|
"Warning! `%s` option is deprecated and will be "
|
2015-06-28 19:20:31 +03:00
|
|
|
"removed in the next release! Please use "
|
2016-08-08 14:00:01 +03:00
|
|
|
"`%s` instead." % (k, self.RENAMED_OPTIONS[k]),
|
|
|
|
fg="yellow")
|
|
|
|
k = self.RENAMED_OPTIONS[k]
|
2016-09-03 19:35:40 +03:00
|
|
|
# process renamed platforms
|
|
|
|
if k == "platform" and v in self.RENAMED_PLATFORMS:
|
|
|
|
click.secho(
|
|
|
|
"Warning! Platform `%s` is deprecated and will be "
|
|
|
|
"removed in the next release! Please use "
|
|
|
|
"`%s` instead." % (v, self.RENAMED_PLATFORMS[v]),
|
|
|
|
fg="yellow")
|
|
|
|
v = self.RENAMED_PLATFORMS[v]
|
|
|
|
|
2016-08-08 14:00:01 +03:00
|
|
|
# warn about unknown options
|
2017-09-13 17:38:42 +03:00
|
|
|
if k not in self.KNOWN_OPTIONS and not k.startswith("custom_"):
|
2016-08-08 14:00:01 +03:00
|
|
|
click.secho(
|
2017-06-20 18:48:52 +03:00
|
|
|
"Detected non-PlatformIO `%s` option in `[env:%s]` section"
|
|
|
|
% (k, self.name),
|
2016-08-03 23:38:20 +03:00
|
|
|
fg="yellow")
|
2015-06-28 20:16:43 +03:00
|
|
|
result[k] = v
|
|
|
|
return result
|
2015-06-28 19:20:31 +03:00
|
|
|
|
2017-06-26 17:14:38 +03:00
|
|
|
def get_build_variables(self):
|
2016-05-10 15:36:00 +03:00
|
|
|
variables = {"pioenv": self.name}
|
2015-06-28 20:16:43 +03:00
|
|
|
if self.upload_port:
|
2016-05-10 15:36:00 +03:00
|
|
|
variables['upload_port'] = self.upload_port
|
2015-06-28 20:16:43 +03:00
|
|
|
for k, v in self.options.items():
|
2016-08-08 14:00:01 +03:00
|
|
|
if k in self.REMAPED_OPTIONS:
|
|
|
|
k = self.REMAPED_OPTIONS[k]
|
2017-04-28 01:38:25 +03:00
|
|
|
if k in self.IGNORE_BUILD_OPTIONS:
|
|
|
|
continue
|
2016-05-10 15:36:00 +03:00
|
|
|
if k == "targets" or (k == "upload_port" and self.upload_port):
|
2015-05-15 22:40:29 +02:00
|
|
|
continue
|
2016-05-10 15:36:00 +03:00
|
|
|
variables[k] = v
|
2015-05-15 22:40:29 +02:00
|
|
|
return variables
|
|
|
|
|
2017-06-26 17:14:38 +03:00
|
|
|
def get_build_targets(self):
|
2015-05-15 22:40:29 +02:00
|
|
|
targets = []
|
|
|
|
if self.targets:
|
|
|
|
targets = [t for t in self.targets]
|
|
|
|
elif "targets" in self.options:
|
2017-04-02 21:58:38 +03:00
|
|
|
targets = self.options['targets'].split(", ")
|
2015-05-15 22:40:29 +02:00
|
|
|
return targets
|
|
|
|
|
|
|
|
def _run(self):
|
|
|
|
if "platform" not in self.options:
|
|
|
|
raise exception.UndefinedEnvPlatform(self.name)
|
|
|
|
|
2017-06-26 17:14:38 +03:00
|
|
|
build_vars = self.get_build_variables()
|
|
|
|
build_targets = self.get_build_targets()
|
2015-05-15 22:40:29 +02:00
|
|
|
|
|
|
|
telemetry.on_run_environment(self.options, build_targets)
|
|
|
|
|
2017-06-26 17:14:38 +03:00
|
|
|
# skip monitor target, we call it above
|
|
|
|
if "monitor" in build_targets:
|
|
|
|
build_targets.remove("monitor")
|
2016-10-09 00:23:33 +03:00
|
|
|
if "nobuild" not in build_targets:
|
|
|
|
# install dependent libraries
|
|
|
|
if "lib_install" in self.options:
|
|
|
|
_autoinstall_libdeps(self.cmd_ctx, [
|
|
|
|
int(d.strip())
|
|
|
|
for d in self.options['lib_install'].split(",")
|
|
|
|
if d.strip()
|
|
|
|
], self.verbose)
|
|
|
|
if "lib_deps" in self.options:
|
2017-11-01 14:10:32 +02:00
|
|
|
_autoinstall_libdeps(self.cmd_ctx,
|
|
|
|
util.parse_conf_multi_values(
|
|
|
|
self.options['lib_deps']),
|
|
|
|
self.verbose)
|
2016-05-28 22:51:33 +03:00
|
|
|
|
|
|
|
try:
|
2016-08-01 17:05:48 +03:00
|
|
|
p = PlatformFactory.newPlatform(self.options['platform'])
|
2016-05-28 22:51:33 +03:00
|
|
|
except exception.UnknownPlatform:
|
2016-05-31 00:22:25 +03:00
|
|
|
self.cmd_ctx.invoke(
|
2016-09-10 18:58:18 +03:00
|
|
|
cmd_platform_install,
|
|
|
|
platforms=[self.options['platform']],
|
|
|
|
skip_default_package=True)
|
2016-08-01 17:05:48 +03:00
|
|
|
p = PlatformFactory.newPlatform(self.options['platform'])
|
2016-05-28 22:51:33 +03:00
|
|
|
|
2016-08-21 19:27:38 +03:00
|
|
|
return p.run(build_vars, build_targets, self.silent, self.verbose)
|
2015-05-15 22:40:29 +02:00
|
|
|
|
|
|
|
|
2016-08-08 16:03:17 +03:00
|
|
|
def _autoinstall_libdeps(ctx, libraries, verbose=False):
|
2017-06-30 00:15:49 +03:00
|
|
|
if not libraries:
|
|
|
|
return
|
2016-08-02 19:10:29 +03:00
|
|
|
storage_dir = util.get_projectlibdeps_dir()
|
|
|
|
ctx.obj = LibraryManager(storage_dir)
|
|
|
|
if verbose:
|
|
|
|
click.echo("Library Storage: " + storage_dir)
|
2016-09-17 16:32:16 +03:00
|
|
|
for lib in libraries:
|
|
|
|
try:
|
|
|
|
ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
|
|
|
|
except exception.LibNotFound as e:
|
2018-01-13 19:44:05 +02:00
|
|
|
if verbose or not is_builtin_lib(lib):
|
2017-01-28 15:48:36 +02:00
|
|
|
click.secho("Warning! %s" % e, fg="yellow")
|
2018-01-13 19:44:05 +02:00
|
|
|
except exception.InternetIsOffline as e:
|
|
|
|
click.secho(str(e), fg="yellow")
|
2015-06-04 22:50:13 +03:00
|
|
|
|
|
|
|
|
2018-01-03 15:47:02 +02:00
|
|
|
def _clean_build_dir(build_dir):
|
|
|
|
structhash_file = join(build_dir, "structure.hash")
|
2015-06-04 23:15:28 +03:00
|
|
|
proj_hash = calculate_project_hash()
|
|
|
|
|
|
|
|
# if project's config is modified
|
2018-01-03 15:47:02 +02:00
|
|
|
if (isdir(build_dir)
|
2017-11-01 14:10:32 +02:00
|
|
|
and getmtime(join(util.get_project_dir(),
|
2018-01-03 15:47:02 +02:00
|
|
|
"platformio.ini")) > getmtime(build_dir)):
|
|
|
|
util.rmtree_(build_dir)
|
2015-06-04 23:15:28 +03:00
|
|
|
|
|
|
|
# check project structure
|
2018-01-03 15:47:02 +02:00
|
|
|
if isdir(build_dir) and isfile(structhash_file):
|
2015-06-05 19:12:57 +03:00
|
|
|
with open(structhash_file) as f:
|
|
|
|
if f.read() == proj_hash:
|
|
|
|
return
|
2018-01-03 15:47:02 +02:00
|
|
|
util.rmtree_(build_dir)
|
2015-06-04 23:15:28 +03:00
|
|
|
|
2018-01-03 15:47:02 +02:00
|
|
|
if not isdir(build_dir):
|
|
|
|
makedirs(build_dir)
|
2015-06-04 23:15:28 +03:00
|
|
|
|
|
|
|
with open(structhash_file, "w") as f:
|
|
|
|
f.write(proj_hash)
|
2015-06-04 22:50:13 +03:00
|
|
|
|
|
|
|
|
2016-06-15 14:10:42 +03:00
|
|
|
def print_header(label, is_error=False):
|
|
|
|
terminal_width, _ = click.get_terminal_size()
|
|
|
|
width = len(click.unstyle(label))
|
|
|
|
half_line = "=" * ((terminal_width - width - 2) / 2)
|
|
|
|
click.echo("%s %s %s" % (half_line, label, half_line), err=is_error)
|
|
|
|
|
|
|
|
|
2016-10-03 16:47:23 +03:00
|
|
|
def print_summary(results, start_time):
|
|
|
|
print_header("[%s]" % click.style("SUMMARY"))
|
|
|
|
|
|
|
|
envname_max_len = 0
|
2016-11-16 17:31:56 +02:00
|
|
|
for (envname, _) in results:
|
2016-10-03 16:47:23 +03:00
|
|
|
if len(envname) > envname_max_len:
|
|
|
|
envname_max_len = len(envname)
|
|
|
|
|
|
|
|
successed = True
|
2016-11-16 17:31:56 +02:00
|
|
|
for (envname, status) in results:
|
2016-10-03 16:47:23 +03:00
|
|
|
status_str = click.style("SUCCESS", fg="green")
|
|
|
|
if status is False:
|
|
|
|
successed = False
|
|
|
|
status_str = click.style("ERROR", fg="red")
|
|
|
|
elif status is None:
|
|
|
|
status_str = click.style("SKIP", fg="yellow")
|
|
|
|
|
|
|
|
format_str = (
|
|
|
|
"Environment {0:<" + str(envname_max_len + 9) + "}\t[{1}]")
|
|
|
|
click.echo(
|
2017-03-02 17:09:22 +02:00
|
|
|
format_str.format(click.style(envname, fg="cyan"), status_str),
|
2016-10-03 16:47:23 +03:00
|
|
|
err=status is False)
|
|
|
|
|
|
|
|
print_header(
|
2017-06-24 16:07:40 +03:00
|
|
|
"[%s] Took %.2f seconds" %
|
|
|
|
((click.style("SUCCESS", fg="green", bold=True)
|
|
|
|
if successed else click.style("ERROR", fg="red", bold=True)),
|
|
|
|
time() - start_time),
|
2016-10-03 16:47:23 +03:00
|
|
|
is_error=not successed)
|
|
|
|
|
|
|
|
|
2016-08-08 14:00:01 +03:00
|
|
|
def check_project_defopts(config):
|
|
|
|
if not config.has_section("platformio"):
|
|
|
|
return True
|
2017-04-27 18:30:40 +03:00
|
|
|
known = ("env_default", "home_dir", "lib_dir", "libdeps_dir", "src_dir",
|
2018-01-03 15:47:02 +02:00
|
|
|
"build_dir", "data_dir", "test_dir", "boards_dir",
|
2017-04-27 18:30:40 +03:00
|
|
|
"lib_extra_dirs")
|
2016-08-08 14:00:01 +03:00
|
|
|
unknown = set([k for k, _ in config.items("platformio")]) - set(known)
|
|
|
|
if not unknown:
|
|
|
|
return True
|
|
|
|
click.secho(
|
2018-01-03 15:47:02 +02:00
|
|
|
"Warning! Ignore unknown `%s` option in `[platformio]` section" %
|
2016-08-08 14:00:01 +03:00
|
|
|
", ".join(unknown),
|
|
|
|
fg="yellow")
|
|
|
|
return False
|
|
|
|
|
2016-06-15 14:10:42 +03:00
|
|
|
|
2016-08-08 14:00:01 +03:00
|
|
|
def check_project_envs(config, environments):
|
2016-07-18 15:36:08 +03:00
|
|
|
if not config.sections():
|
|
|
|
raise exception.ProjectEnvsNotAvailable()
|
2016-06-15 14:10:42 +03:00
|
|
|
|
2016-08-03 23:38:20 +03:00
|
|
|
known = set([s[4:] for s in config.sections() if s.startswith("env:")])
|
2016-07-18 15:36:08 +03:00
|
|
|
unknown = set(environments) - known
|
|
|
|
if unknown:
|
2016-08-03 23:38:20 +03:00
|
|
|
raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known))
|
2016-06-15 14:10:42 +03:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2015-06-04 22:50:13 +03:00
|
|
|
def calculate_project_hash():
|
2018-01-26 22:24:49 +02:00
|
|
|
check_suffixes = (".c", ".cc", ".cpp", ".h", ".hpp", ".s", ".S")
|
2016-06-29 13:17:06 +03:00
|
|
|
structure = [__version__]
|
2015-06-04 22:50:13 +03:00
|
|
|
for d in (util.get_projectsrc_dir(), util.get_projectlib_dir()):
|
|
|
|
if not isdir(d):
|
|
|
|
continue
|
|
|
|
for root, _, files in walk(d):
|
|
|
|
for f in files:
|
|
|
|
path = join(root, f)
|
2018-01-26 22:24:49 +02:00
|
|
|
if path.endswith(check_suffixes):
|
2015-06-04 22:50:13 +03:00
|
|
|
structure.append(path)
|
2018-01-26 22:24:49 +02:00
|
|
|
return sha1(",".join(sorted(structure))).hexdigest()
|