diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index ea88b479a9..43f4d3270e 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -395,6 +395,17 @@ function run_tests() (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-issue) && failure "All commands in compile_commands.json should use PSRAM cache workaround" rm -r build + print_status "Cleaning Python bytecode" + idf.py clean > /dev/null + idf.py fullclean > /dev/null + if [ "$(find $IDF_PATH -name "*.py[co]" | wc -l)" -eq 0 ]; then + failure "No Python bytecode in IDF!" + fi + idf.py python-clean + if [ "$(find $IDF_PATH -name "*.py[co]" | wc -l)" -gt 0 ]; then + failure "Python bytecode isn't working!" + fi + print_status "Displays partition table when executing target partition_table" idf.py partition_table | grep -E "# Espressif .+ Partition Table" rm -r build diff --git a/tools/idf.py b/tools/idf.py index 8ccd1327ca..a09944fa09 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -27,6 +27,7 @@ # any external libraries here - put in external script, or import in # their specific function instead. import codecs +import fnmatch import json import locale import multiprocessing @@ -491,6 +492,21 @@ def fullclean(action, ctx, args): os.remove(f) +def python_clean(action, ctx, args): + for root, dirnames, filenames in os.walk(os.environ["IDF_PATH"]): + for d in dirnames: + if d == "__pycache__": + dir_to_delete = os.path.join(root, d) + if args.verbose: + print("Removing: %s" % dir_to_delete) + shutil.rmtree(dir_to_delete) + for filename in fnmatch.filter(filenames, '*.py[co]'): + file_to_delete = os.path.join(root, filename) + if args.verbose: + print("Removing: %s" % file_to_delete) + os.remove(file_to_delete) + + def _safe_relpath(path, start=None): """ Return a relative path, same as os.path.relpath, but only if this is possible. @@ -1124,6 +1140,13 @@ def init_cli(): + "Note that this option recursively deletes all files in the build directory, so use with care." + "Project configuration is not deleted.", }, + "python-clean": { + "callback": python_clean, + "short_help": "Delete generated Python byte code from the IDF directory", + "help": ("Delete generated Python byte code from the IDF directory " + "which may cause issues when switching between IDF and Python versions. " + "It is advised to run this target after switching versions.") + }, } }