mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(tools): Add 'check' field to idf.py actions
This commit is contained in:
@@ -1,24 +1,29 @@
|
||||
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import os
|
||||
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.errors import FatalError
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
from idf_py_actions.tools import ensure_build_directory
|
||||
from idf_py_actions.tools import get_sdkconfig_filename
|
||||
from idf_py_actions.tools import get_sdkconfig_value
|
||||
from idf_py_actions.tools import red_print
|
||||
from idf_py_actions.tools import run_target
|
||||
|
||||
SOC_USB_DFU_SUPPORTED = 'CONFIG_SOC_USB_DFU_SUPPORTED'
|
||||
|
||||
|
||||
def _soc_usb_dfu_supported(project_path: str) -> bool:
|
||||
return bool(get_sdkconfig_value(os.path.join(project_path, 'sdkconfig'), SOC_USB_DFU_SUPPORTED) == 'y')
|
||||
|
||||
|
||||
def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
def check_dfu_supported(target_name: str, ctx: Context, args: PropertyDict, **kwargs: str) -> bool:
|
||||
sdkconfig_path = get_sdkconfig_filename(args)
|
||||
if get_sdkconfig_value(sdkconfig_path, SOC_USB_DFU_SUPPORTED) == 'y':
|
||||
return True
|
||||
|
||||
target = get_sdkconfig_value(sdkconfig_path, 'CONFIG_IDF_TARGET') or 'unknown'
|
||||
red_print(f'DFU is not supported for this target: {target}')
|
||||
return False
|
||||
|
||||
def dfu_target(target_name: str, ctx: Context, args: PropertyDict, part_size: str) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
run_target(target_name, args, {'ESP_DFU_PART_SIZE': part_size} if part_size else {})
|
||||
@@ -44,6 +49,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
'actions': {
|
||||
'dfu': {
|
||||
'callback': dfu_target,
|
||||
'check': check_dfu_supported,
|
||||
'short_help': 'Build the DFU binary',
|
||||
'dependencies': ['all'],
|
||||
'options': [
|
||||
@@ -57,11 +63,13 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
},
|
||||
'dfu-list': {
|
||||
'callback': dfu_list_target,
|
||||
'check': check_dfu_supported,
|
||||
'short_help': 'List DFU capable devices',
|
||||
'dependencies': [],
|
||||
},
|
||||
'dfu-flash': {
|
||||
'callback': dfu_flash_target,
|
||||
'check': check_dfu_supported,
|
||||
'short_help': 'Flash the DFU binary',
|
||||
'order_dependencies': ['dfu'],
|
||||
'options': [
|
||||
@@ -77,4 +85,4 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
}
|
||||
}
|
||||
|
||||
return dfu_actions if _soc_usb_dfu_supported(project_path) else {}
|
||||
return dfu_actions
|
||||
|
||||
@@ -988,19 +988,12 @@ def get_sdkconfig_value(sdkconfig_file: str, key: str) -> str | None:
|
||||
pattern = re.compile(rf'^{key}=\"?([^\"]*)\"?$')
|
||||
with open(sdkconfig_file, encoding='utf-8') as f:
|
||||
for line in f:
|
||||
match = re.match(pattern, line)
|
||||
match = re.match(pattern, line.strip())
|
||||
if match:
|
||||
value = match.group(1)
|
||||
return value
|
||||
|
||||
|
||||
def is_target_supported(project_path: str, supported_targets: list) -> bool:
|
||||
"""
|
||||
Returns True if the active target is supported, or False otherwise.
|
||||
"""
|
||||
return get_target(project_path) in supported_targets
|
||||
|
||||
|
||||
def _check_idf_target(
|
||||
args: 'PropertyDict', prog_name: str, cache: dict, cache_cmdl: dict, env: dict | None = None
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user