diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index ad7e8e49ba..37cbc79027 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -353,6 +353,13 @@ function run_tests() grep "CONFIG_IDF_TARGET=\"${other_target}\"" sdkconfig || failure "Project not configured correctly using idf.py set-target" grep "IDF_TARGET:STRING=${other_target}" build/CMakeCache.txt || failure "IDF_TARGET not set in CMakeCache.txt using idf.py set-target" + print_status "idf.py understands alternative target names" + clean_build_dir + rm sdkconfig + idf.py set-target ESP32-S2 + grep "CONFIG_IDF_TARGET=\"${other_target}\"" sdkconfig || failure "Project not configured correctly using idf.py set-target" + grep "IDF_TARGET:STRING=${other_target}" build/CMakeCache.txt || failure "IDF_TARGET not set in CMakeCache.txt using idf.py set-target" + print_status "Can guess target from sdkconfig, if CMakeCache does not exist" idf.py fullclean || failure "Failed to clean the build directory" idf.py reconfigure || failure "Failed to reconfigure after fullclean" diff --git a/tools/idf_py_actions/core_ext.py b/tools/idf_py_actions/core_ext.py index 09b47f8367..b03d5c3a3c 100644 --- a/tools/idf_py_actions/core_ext.py +++ b/tools/idf_py_actions/core_ext.py @@ -8,7 +8,7 @@ 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_target +from idf_py_actions.tools import ensure_build_directory, idf_version, merge_action_lists, realpath, run_target, TargetChoice def action_extensions(base_actions, project_path): @@ -379,7 +379,7 @@ def action_extensions(base_actions, project_path): { "names": ["idf-target"], "nargs": 1, - "type": click.Choice(SUPPORTED_TARGETS), + "type": TargetChoice(SUPPORTED_TARGETS), }, ], "dependencies": ["fullclean"], diff --git a/tools/idf_py_actions/tools.py b/tools/idf_py_actions/tools.py index 663522b82c..13cf712116 100644 --- a/tools/idf_py_actions/tools.py +++ b/tools/idf_py_actions/tools.py @@ -1,3 +1,4 @@ +import click import os import re import subprocess @@ -314,3 +315,25 @@ def _guess_or_check_idf_target(args, prog_name, cache): "To keep the setting in sdkconfig ({t_conf}) and re-generate CMakeCache.txt, run '{prog} fullclean'. " "To re-generate sdkconfig for '{t_cache}' target, run '{prog} set-target {t_cache}'." .format(t_conf=idf_target_from_sdkconfig, t_cache=idf_target_from_cache, prog=prog_name)) + + +class TargetChoice(click.Choice): + """ + A version of click.Choice with two special features: + - ignores hyphens + - not case sensitive + """ + def __init__(self, choices): + super(TargetChoice, self).__init__(choices, case_sensitive=False) + + def convert(self, value, param, ctx): + def normalize(str): + return str.lower().replace("-", "") + + saved_token_normalize_func = ctx.token_normalize_func + ctx.token_normalize_func = normalize + + try: + return super(TargetChoice, self).convert(value, param, ctx) + finally: + ctx.token_normalize_func = saved_token_normalize_func