idf.py: use underlying flash targets
This commit is contained in:
parent
38b3fbfbfb
commit
7ddd39ec7d
3 changed files with 22 additions and 23 deletions
|
@ -8,17 +8,10 @@ import click
|
||||||
from idf_py_actions.constants import GENERATORS, SUPPORTED_TARGETS
|
from idf_py_actions.constants import GENERATORS, SUPPORTED_TARGETS
|
||||||
from idf_py_actions.errors import FatalError
|
from idf_py_actions.errors import FatalError
|
||||||
from idf_py_actions.global_options import global_options
|
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 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):
|
def build_target(target_name, ctx, args):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,7 +4,7 @@ import sys
|
||||||
|
|
||||||
from idf_py_actions.errors import FatalError
|
from idf_py_actions.errors import FatalError
|
||||||
from idf_py_actions.global_options import global_options
|
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
|
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
|
Run esptool to flash the entire project, from an argfile generated by the build system
|
||||||
"""
|
"""
|
||||||
flasher_args_path = {
|
if args.port is None:
|
||||||
# action -> name of flasher args file generated by build system
|
args.port = _get_default_serial_port()
|
||||||
"bootloader-flash": "flash_bootloader_args",
|
|
||||||
"partition_table-flash": "flash_partition_table_args",
|
run_target(action, args, {"ESPPORT": args.port,
|
||||||
"app-flash": "flash_app_args",
|
"ESPBAUD": str(args.baud)})
|
||||||
"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)
|
|
||||||
|
|
||||||
def erase_flash(action, ctx, args):
|
def erase_flash(action, ctx, args):
|
||||||
esptool_args = _get_esptool_args(args)
|
esptool_args = _get_esptool_args(args)
|
||||||
|
|
|
@ -63,7 +63,7 @@ def idf_version():
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
def run_tool(tool_name, args, cwd):
|
def run_tool(tool_name, args, cwd, env=dict()):
|
||||||
def quote_arg(arg):
|
def quote_arg(arg):
|
||||||
" Quote 'arg' if necessary "
|
" Quote 'arg' if necessary "
|
||||||
if " " in arg and not (arg.startswith('"') or arg.startswith("'")):
|
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)
|
display_args = " ".join(quote_arg(arg) for arg in args)
|
||||||
print("Running %s in directory %s" % (tool_name, quote_arg(cwd)))
|
print("Running %s in directory %s" % (tool_name, quote_arg(cwd)))
|
||||||
print('Executing "%s"...' % str(display_args))
|
print('Executing "%s"...' % str(display_args))
|
||||||
|
|
||||||
|
env_copy = dict(os.environ)
|
||||||
|
env_copy.update(env)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Note: we explicitly pass in os.environ here, as we may have set IDF_PATH there during startup
|
# 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:
|
except subprocess.CalledProcessError as e:
|
||||||
raise FatalError("%s failed with exit code %d" % (tool_name, e.returncode))
|
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"^\"(.*)\"$|^'(.*)'$|^(.*)$")):
|
def _strip_quotes(value, regexp=re.compile(r"^\"(.*)\"$|^'(.*)'$|^(.*)$")):
|
||||||
"""
|
"""
|
||||||
Strip quotes like CMake does during parsing cache entries
|
Strip quotes like CMake does during parsing cache entries
|
||||||
|
|
Loading…
Reference in a new issue