fix(idf_tools): Validate input features

This commit is contained in:
Radim Karniš
2025-03-18 16:09:37 +01:00
parent 8bb65e6d85
commit 3c8d99d8ef
2 changed files with 22 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
#
# SPDX-License-Identifier: Apache-2.0
# This script is used from the $IDF_PATH/install.* scripts. This way the argument parsing can be done at one place and
@@ -13,19 +13,22 @@ from itertools import chain
def action_extract_features(args: str) -> None:
"""
Command line arguments starting with "--enable-" or "--disable" are features. This function selects those, add them signs '+' or '-' and prints them.
Command line arguments starting with "--enable-" or "--disable-" are features.
This function selects those, adds them a '+' or '-' sign and prints them.
"""
features = ['+core'] # "core" features should be always installed
if args:
arg_enable_prefix = '--enable-'
arg_disable_prefix = '--disable-'
# features to be enabled has prefix '+', disabled has prefix '-'
# features to be enabled have prefix '+', disabled have prefix '-'
for arg in args.split():
if arg.startswith(arg_enable_prefix):
features.append('+' + arg[len(arg_enable_prefix):])
elif arg.startswith(arg_disable_prefix):
features.append('-' + arg[len(arg_disable_prefix):])
elif arg.startswith('-'):
raise SystemExit(f'ERROR: Invalid feature specifier: {arg}')
features = list(set(features))
print(','.join(features))
@@ -75,7 +78,7 @@ optional arguments:
{help_opts} show this help message and exit
For more information, please see https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/tools/idf-tools.html#install-scripts
""")
""") # noqa: E222
def main() -> None: