From 435c5564f4e7a7d58d3657add2a94e40d82d6739 Mon Sep 17 00:00:00 2001 From: Sergei Silnov Date: Tue, 14 Jul 2020 17:07:32 +0200 Subject: [PATCH 1/2] idf.py: Add help subcommand --- tools/idf.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/idf.py b/tools/idf.py index 0c295feff4..456a6c8df0 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -144,7 +144,6 @@ def init_cli(verbose_output=None): class Deprecation(object): """Construct deprecation notice for help messages""" - def __init__(self, deprecated=False): self.deprecated = deprecated self.since = None @@ -292,7 +291,6 @@ def init_cli(verbose_output=None): names - alias of 'param_decls' """ - def __init__(self, **kwargs): names = kwargs.pop("names") super(Argument, self).__init__(names, **kwargs) @@ -331,7 +329,6 @@ def init_cli(verbose_output=None): class Option(click.Option): """Option that knows whether it should be global""" - def __init__(self, scope=None, deprecated=False, hidden=False, **kwargs): """ Keyword arguments additional to Click's Option class: @@ -367,7 +364,6 @@ def init_cli(verbose_output=None): class CLI(click.MultiCommand): """Action list contains all actions with options available for CLI""" - def __init__(self, all_actions=None, verbose_output=None, help=None): super(CLI, self).__init__( chain=True, @@ -518,6 +514,10 @@ def init_cli(verbose_output=None): ctx = click.get_current_context() global_args = PropertyDict(kwargs) + def _help_and_exit(): + print(ctx.get_help()) + ctx.exit() + # Show warning if some tasks are present several times in the list dupplicated_tasks = sorted( [item for item, count in Counter(task.name for task in tasks).items() if count > 1]) @@ -528,9 +528,13 @@ def init_cli(verbose_output=None): ("s %s are" % dupes if len(dupplicated_tasks) > 1 else " %s is" % dupes) + "Only first occurence will be executed.") - # Set propagated global options. - # These options may be set on one subcommand, but available in the list of global arguments for task in tasks: + # Show help and exit if help is in the list of commands + if task.name == 'help': + _help_and_exit() + + # Set propagated global options. + # These options may be set on one subcommand, but available in the list of global arguments for key in list(task.action_args): option = next((o for o in ctx.command.params if o.name == key), None) @@ -558,8 +562,7 @@ def init_cli(verbose_output=None): # Always show help when command is not provided if not tasks: - print(ctx.get_help()) - ctx.exit() + _help_and_exit() # Build full list of tasks to and deal with dependencies and order dependencies tasks_to_run = OrderedDict() From 140c5800dd8cb83759b3df3c69919045593ce6f6 Mon Sep 17 00:00:00 2001 From: Sergei Silnov Date: Wed, 15 Jul 2020 16:43:17 +0200 Subject: [PATCH 2/2] idf.py: Add command to list build system targets --- tools/idf_py_actions/core_ext.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/idf_py_actions/core_ext.py b/tools/idf_py_actions/core_ext.py index bb2a76280e..e38879d2e8 100644 --- a/tools/idf_py_actions/core_ext.py +++ b/tools/idf_py_actions/core_ext.py @@ -13,7 +13,6 @@ from idf_py_actions.tools import ensure_build_directory, idf_version, merge_acti def action_extensions(base_actions, project_path): - def build_target(target_name, ctx, args): """ Execute the target build system to build target 'target_name' @@ -24,6 +23,10 @@ def action_extensions(base_actions, project_path): ensure_build_directory(args, ctx.info_name) run_target(target_name, args) + def list_build_system_targets(target_name, ctx, args): + """Shows list of targets known to build sytem (make/ninja)""" + build_target('help', ctx, args) + def menuconfig(target_name, ctx, args, style): """ Menuconfig target is build_target extended with the style argument for setting the value for the environment @@ -137,8 +140,10 @@ def action_extensions(base_actions, project_path): os.remove(file_to_delete) def set_target(action, ctx, args, idf_target): - if(not args["preview"] and idf_target in PREVIEW_TARGETS): - raise FatalError("%s is still in preview. You have to append '--preview' option after idf.py to use any preview feature." % idf_target) + if (not args["preview"] and idf_target in PREVIEW_TARGETS): + raise FatalError( + "%s is still in preview. You have to append '--preview' option after idf.py to use any preview feature." + % idf_target) args.define_cache_entry.append("IDF_TARGET=" + idf_target) sdkconfig_path = os.path.join(args.project_dir, 'sdkconfig') sdkconfig_old = sdkconfig_path + ".old" @@ -370,10 +375,14 @@ def action_extensions(base_actions, project_path): "help": "Read otadata partition.", "options": global_options, }, + "build-system-targets": { + "callback": list_build_system_targets, + "help": "Print list of build system targets.", + }, "fallback": { "callback": fallback_target, "help": "Handle for targets not known for idf.py.", - "hidden": True + "hidden": True, } } }