Files
esp-idf/tools/ci/check_executables.py
T
Jan Beran aab610c327 change(tools): apply ruff fixes (ci, test_apps, build system, ldgen)
Apply the ruff lint (including pyupgrade) and format fixes for the
Python 3.11 target in the following areas:

- tools (idf_py_actions, install_util, test_bsasm, test_idf_diag,
  test_idf_py, test_idf_size)
- tools/ci
- tools/test_apps
- tools/test_build_system
- tools/ldgen

Findings that are not auto-fixable (long lines, a shadowed builtin,
type comparisons) are fixed by hand. Also fix the typos reported by
codespell and the mypy error in tools/ci/idf_pytest/utils.py that
surfaced once the file was touched, and switch check_for_file_paths.py
to the SPDX header (removing it from the copyright ignore list).
2026-10-12 15:46:44 +08:00

79 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
import sys
from collections.abc import Iterable
try:
from idf_ci_utils import is_executable
except ImportError:
sys.path.append(os.path.join(os.path.dirname(__file__)))
from idf_ci_utils import is_executable
def _strip_each_item(iterable: Iterable) -> list:
res = []
for item in iterable:
if item:
res.append(item.strip())
return res
IDF_PATH = os.getenv('IDF_PATH', os.getcwd())
EXECUTABLE_LIST_FN = os.path.join(IDF_PATH, 'tools/ci/executable-list.txt')
known_executables = _strip_each_item(open(EXECUTABLE_LIST_FN).readlines())
def check_executable_list() -> int:
ret = 0
for index, fn in enumerate(known_executables):
if not os.path.exists(os.path.join(IDF_PATH, fn)):
print(f'{EXECUTABLE_LIST_FN}:{index + 1} {fn} not exists. Please remove it manually')
ret = 1
return ret
def check_executables(files: list) -> int:
ret = 0
for fn in files:
fn_executable = is_executable(fn)
fn_in_list = fn in known_executables
if fn_executable and not fn_in_list:
print(f'"{fn}" is not in {EXECUTABLE_LIST_FN}')
ret = 1
if not fn_executable and fn_in_list:
print(f'"{fn}" is not executable but is in {EXECUTABLE_LIST_FN}')
ret = 1
return ret
def check() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
'--action',
choices=['executables', 'list'],
required=True,
help='if "executables", pass all your executables to see if it\'s in the list.'
'if "list", check if all items on your list exist',
)
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
args = parser.parse_args()
if args.action == 'executables':
ret = check_executables(args.filenames)
elif args.action == 'list':
ret = check_executable_list()
else:
raise ValueError
return ret
if __name__ == '__main__':
sys.exit(check())