From 7ddd39ec7d892d1b02bbe53bd63f6968903dcc8d Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 20 Dec 2019 09:55:39 +0800 Subject: [PATCH] idf.py: use underlying flash targets --- tools/idf_py_actions/core_ext.py | 9 +-------- tools/idf_py_actions/serial_ext.py | 19 ++++++------------- tools/idf_py_actions/tools.py | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/tools/idf_py_actions/core_ext.py b/tools/idf_py_actions/core_ext.py index 56c13540f..09b47f836 100644 --- a/tools/idf_py_actions/core_ext.py +++ b/tools/idf_py_actions/core_ext.py @@ -8,17 +8,10 @@ import click from idf_py_actions.constants import GENERATORS, SUPPORTED_TARGETS from idf_py_actions.errors import FatalError from idf_py_actions.global_options import global_options -from idf_py_actions.tools import ensure_build_directory, idf_version, merge_action_lists, realpath, run_tool +from idf_py_actions.tools import ensure_build_directory, idf_version, merge_action_lists, realpath, run_target def action_extensions(base_actions, project_path): - def run_target(target_name, args): - generator_cmd = GENERATORS[args.generator]["command"] - - if args.verbose: - generator_cmd += [GENERATORS[args.generator]["verbose_flag"]] - - run_tool(generator_cmd[0], generator_cmd + [target_name], args.build_dir) def build_target(target_name, ctx, args): """ diff --git a/tools/idf_py_actions/serial_ext.py b/tools/idf_py_actions/serial_ext.py index 4ea0e4a02..7c3ea9811 100644 --- a/tools/idf_py_actions/serial_ext.py +++ b/tools/idf_py_actions/serial_ext.py @@ -4,7 +4,7 @@ import sys from idf_py_actions.errors import FatalError from idf_py_actions.global_options import global_options -from idf_py_actions.tools import ensure_build_directory, run_tool +from idf_py_actions.tools import ensure_build_directory, run_tool, run_target PYTHON = sys.executable @@ -99,18 +99,11 @@ def action_extensions(base_actions, project_path): """ Run esptool to flash the entire project, from an argfile generated by the build system """ - flasher_args_path = { - # action -> name of flasher args file generated by build system - "bootloader-flash": "flash_bootloader_args", - "partition_table-flash": "flash_partition_table_args", - "app-flash": "flash_app_args", - "flash": "flash_project_args", - "encrypted-app-flash": "flash_encrypted_app_args", - "encrypted-flash": "flash_encrypted_project_args", - }[action] - esptool_args = _get_esptool_args(args) - esptool_args += ["write_flash", "@" + flasher_args_path] - run_tool("esptool.py", esptool_args, args.build_dir) + if args.port is None: + args.port = _get_default_serial_port() + + run_target(action, args, {"ESPPORT": args.port, + "ESPBAUD": str(args.baud)}) def erase_flash(action, ctx, args): esptool_args = _get_esptool_args(args) diff --git a/tools/idf_py_actions/tools.py b/tools/idf_py_actions/tools.py index bca13ecb0..cc35185aa 100644 --- a/tools/idf_py_actions/tools.py +++ b/tools/idf_py_actions/tools.py @@ -63,7 +63,7 @@ def idf_version(): return version -def run_tool(tool_name, args, cwd): +def run_tool(tool_name, args, cwd, env=dict()): def quote_arg(arg): " Quote 'arg' if necessary " if " " in arg and not (arg.startswith('"') or arg.startswith("'")): @@ -73,13 +73,26 @@ def run_tool(tool_name, args, cwd): display_args = " ".join(quote_arg(arg) for arg in args) print("Running %s in directory %s" % (tool_name, quote_arg(cwd))) print('Executing "%s"...' % str(display_args)) + + env_copy = dict(os.environ) + env_copy.update(env) + try: # Note: we explicitly pass in os.environ here, as we may have set IDF_PATH there during startup - subprocess.check_call(args, env=os.environ, cwd=cwd) + subprocess.check_call(args, env=env_copy, cwd=cwd) except subprocess.CalledProcessError as e: raise FatalError("%s failed with exit code %d" % (tool_name, e.returncode)) +def run_target(target_name, args, env=dict()): + generator_cmd = GENERATORS[args.generator]["command"] + + if args.verbose: + generator_cmd += [GENERATORS[args.generator]["verbose_flag"]] + + run_tool(generator_cmd[0], generator_cmd + [target_name], args.build_dir, env) + + def _strip_quotes(value, regexp=re.compile(r"^\"(.*)\"$|^'(.*)'$|^(.*)$")): """ Strip quotes like CMake does during parsing cache entries