#!/usr/bin/env bash # 清理 p4a 的构建缓存,迫使重编或重新组装 dist。 # # 两种模式: # --python (默认)删除 dists **以及** python3 / hostpython3 的编译产物。 # 换 Python 版本(wheel 的 cp311 ↔ p4a 默认版本)时必须用这个, # 否则旧 dist 里的 libpythonX.Y.so 不会被替换。 # --dist-only 只删除 dists,保留 other_builds 里的编译产物。 # 改的是 bootstrap 配置(例如 libs.xml 里 Qt 库的加载顺序)时用, # p4a 会重新组装 dist 但复用已编译好的 CPython,快得多。 # # 用法(WSL 内,root 或 builder 均可): # bash scripts/wsl_purge_python_build.sh [--python|--dist-only] set -euo pipefail MODE="python" case "${1:-}" in --dist-only) MODE="dist" ;; --python|"") MODE="python" ;; *) echo "未知参数:$1(可用:--python / --dist-only)" >&2; exit 2 ;; esac WORK="${WORK:-/opt/lnxgit-android}" SRC="${SRC:-$WORK/src}" PLATFORM="${PLATFORM:-$SRC/.buildozer/android/platform}" GLOBAL="${GLOBAL:-/home/builder/.buildozer/android/platform}" removed=0 purge() { local target="$1" if [ -e "$target" ]; then echo " 删除 $target" rm -rf "$target" removed=$((removed + 1)) fi } if [ "$MODE" = "dist" ]; then echo "==> 清理 p4a 的 dist(保留已编译的 other_builds)" else echo "==> 清理 p4a 的 Python 构建缓存与 dist" fi for platform_dir in "$PLATFORM" "$GLOBAL"; do [ -d "$platform_dir" ] || continue for arch_dir in "$platform_dir"/build-*; do [ -d "$arch_dir" ] || continue # ARCH_FILTER 只清理指定架构,例如 ARCH_FILTER=x86_64 if [ -n "${ARCH_FILTER:-}" ] && [ "$(basename "$arch_dir")" != "build-$ARCH_FILTER" ]; then continue fi purge "$arch_dir/dists" if [ "$MODE" = "python" ]; then purge "$arch_dir/build/other_builds/python3" purge "$arch_dir/build/other_builds/hostpython3" # 下载标记留着会让 p4a 以为源码包已就绪;版本变了必须重新校验 rm -f "$arch_dir"/packages/python3/.mark-* "$arch_dir"/packages/hostpython3/.mark-* fi done done echo "==> 完成(清理 $removed 项)"