def process(self): terminal_width, _ = click.get_terminal_size() start_time = time() env_dump = [] for k, v in self.options.items(): self.options[k] = self.options[k].strip() if self.verbose or k in self.DEFAULT_DUMP_OPTIONS: env_dump.append( "%s: %s" % (k, ", ".join(util.parse_conf_multi_values(v)))) if not self.silent: click.echo("Processing %s (%s)" % (click.style( self.name, fg="cyan", bold=True), "; ".join(env_dump))) click.secho("-" * terminal_width, bold=True) self.options = self._validate_options(self.options) result = self._run() is_error = result['returncode'] != 0 if self.silent and not is_error: return True if is_error or "piotest_processor" not in self.cmd_ctx.meta: print_header( "[%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), is_error=is_error) return not is_error
def process(self): terminal_width, _ = click.get_terminal_size() start_time = time() env_dump = [] for k, v in self.options.items(): self.options[k] = self.options[k].strip() if self.verbose or k in self.DEFAULT_DUMP_OPTIONS: env_dump.append( "%s: %s" % (k, ", ".join(util.parse_conf_multi_values(v)))) if not self.silent: click.echo("Processing %s (%s)" % (click.style( self.name, fg="cyan", bold=True), "; ".join(env_dump))) click.secho("-" * terminal_width, bold=True) self.options = self._validate_options(self.options) result = self._run() is_error = result['returncode'] != 0 if self.silent and not is_error: return True if is_error or "piotest_processor" not in self.cmd_ctx.meta: print_header( "[%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), is_error=is_error) return not is_error
def _run(self): if "platform" not in self.options: raise exception.UndefinedEnvPlatform(self.name) build_vars = self.get_build_variables() build_targets = self.get_build_targets() telemetry.on_run_environment(self.options, build_targets) # skip monitor target, we call it above if "monitor" in build_targets: build_targets.remove("monitor") 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: _autoinstall_libdeps( self.cmd_ctx, util.parse_conf_multi_values(self.options['lib_deps']), self.verbose) try: p = PlatformFactory.newPlatform(self.options['platform']) except exception.UnknownPlatform: self.cmd_ctx.invoke(cmd_platform_install, platforms=[self.options['platform']], skip_default_package=True) p = PlatformFactory.newPlatform(self.options['platform']) return p.run(build_vars, build_targets, self.silent, self.verbose)
def get_best_envname(project_dir, boards=None): config = util.load_project_config(project_dir) env_default = None if config.has_option("platformio", "env_default"): env_default = util.parse_conf_multi_values( config.get("platformio", "env_default")) check_project_envs(config, env_default) if env_default: return env_default[0] section = None for section in config.sections(): if not section.startswith("env:"): continue elif config.has_option(section, "board") and (not boards or config.get( section, "board") in boards): break return section[4:] if section else None
def get_best_envname(project_dir, boards=None): config = util.load_project_config(project_dir) env_default = None if config.has_option("platformio", "env_default"): env_default = util.parse_conf_multi_values( config.get("platformio", "env_default")) check_project_envs(config, env_default) if env_default: return env_default[0] section = None for section in config.sections(): if not section.startswith("env:"): continue elif config.has_option(section, "board") and (not boards or config.get( section, "board") in boards): break return section[4:] if section else None
def _run(self): if "platform" not in self.options: raise exception.UndefinedEnvPlatform(self.name) build_vars = self.get_build_variables() build_targets = self.get_build_targets() telemetry.on_run_environment(self.options, build_targets) # skip monitor target, we call it above if "monitor" in build_targets: build_targets.remove("monitor") 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: _autoinstall_libdeps( self.cmd_ctx, util.parse_conf_multi_values(self.options['lib_deps']), self.verbose) try: p = PlatformFactory.newPlatform(self.options['platform']) except exception.UnknownPlatform: self.cmd_ctx.invoke( cmd_platform_install, platforms=[self.options['platform']], skip_default_package=True) p = PlatformFactory.newPlatform(self.options['platform']) return p.run(build_vars, build_targets, self.silent, self.verbose)
def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, disable_auto_clean): # 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) with util.cd(project_dir): # clean obsolete build dir if not disable_auto_clean: try: _clean_build_dir(util.get_projectbuild_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "it manually to avoid build issues" % util.get_projectbuild_dir(force=True), fg="yellow") config = util.load_project_config() check_project_defopts(config) assert check_project_envs(config, environment) env_default = None if config.has_option("platformio", "env_default"): env_default = util.parse_conf_multi_values( config.get("platformio", "env_default")) results = [] start_time = time() for section in config.sections(): if not section.startswith("env:"): continue envname = section[4:] skipenv = any([ environment and envname not in environment, not environment and env_default and envname not in env_default ]) if skipenv: results.append((envname, None)) continue if not silent and results: click.echo() options = {} for k, v in config.items(section): options[k] = v if "piotest" not in options and "piotest" in ctx.meta: options['piotest'] = ctx.meta['piotest'] ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, silent, verbose) 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) found_error = any([status is False for (_, status) in results]) if (found_error or not silent) and len(results) > 1: click.echo() print_summary(results, start_time) if found_error: raise exception.ReturnErrorCode(1) return True
def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, disable_auto_clean): # 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) with util.cd(project_dir): # clean obsolete build dir if not disable_auto_clean: try: _clean_build_dir(util.get_projectbuild_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "it manually to avoid build issues" % util.get_projectbuild_dir(force=True), fg="yellow") config = util.load_project_config() env_default = None if config.has_option("platformio", "env_default"): env_default = util.parse_conf_multi_values( config.get("platformio", "env_default")) check_project_defopts(config) check_project_envs(config, environment or env_default) results = [] start_time = time() for section in config.sections(): if not section.startswith("env:"): continue envname = section[4:] skipenv = any([ environment and envname not in environment, not environment and env_default and envname not in env_default ]) if skipenv: results.append((envname, None)) continue if not silent and results: click.echo() options = {} for k, v in config.items(section): options[k] = v if "piotest" not in options and "piotest" in ctx.meta: options['piotest'] = ctx.meta['piotest'] ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, silent, verbose) 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, environment=environment[0] if environment else None) found_error = any(status is False for (_, status) in results) if (found_error or not silent) and len(results) > 1: click.echo() print_summary(results, start_time) if found_error: raise exception.ReturnErrorCode(1) return True
if not int(ARGUMENTS.get("PIOVERBOSE", 0)): DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET" DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET" DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET" for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"): DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET" env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS) # decode common variables for k in commonvars.keys(): if k in env: env[k] = base64.b64decode(env[k]) if k in MULTILINE_VARS: env[k] = util.parse_conf_multi_values(env[k]) if env.GetOption('clean'): env.PioClean(env.subst("$BUILD_DIR")) env.Exit(0) elif not int(ARGUMENTS.get("PIOVERBOSE", 0)): print "Verbose mode can be enabled via `-v, --verbose` option" # Handle custom variables from system environment for var in ("BUILD_FLAGS", "SRC_BUILD_FLAGS", "SRC_FILTER", "EXTRA_SCRIPTS", "UPLOAD_PORT", "UPLOAD_FLAGS", "LIB_EXTRA_DIRS"): k = "PLATFORMIO_%s" % var if k not in environ: continue if var in ("UPLOAD_PORT", ): env[var] = environ.get(k)
if not int(ARGUMENTS.get("PIOVERBOSE", 0)): DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET" DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET" DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET" for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"): DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET" env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS) # decode common variables for k in commonvars.keys(): if k in env: env[k] = base64.b64decode(env[k]) if k in MULTILINE_VARS: env[k] = util.parse_conf_multi_values(env[k]) if env.GetOption('clean'): env.PioClean(env.subst("$BUILD_DIR")) env.Exit(0) elif not int(ARGUMENTS.get("PIOVERBOSE", 0)): print "Verbose mode can be enabled via `-v, --verbose` option" # Handle custom variables from system environment for var in ("BUILD_FLAGS", "SRC_BUILD_FLAGS", "SRC_FILTER", "EXTRA_SCRIPTS", "UPLOAD_PORT", "UPLOAD_FLAGS", "LIB_EXTRA_DIRS"): k = "PLATFORMIO_%s" % var if k not in environ: continue if var in ("UPLOAD_PORT", ): env[var] = environ.get(k)