mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 09:46:44 +00:00
feat: detect multiple NDK and Rust toolchain versions (#234)
Add report-only detection for multiple Android NDK and Rust toolchain installations. Users receive helpful guidance for manual cleanup via Android Studio SDK Manager or rustup commands. - Add check_android_ndk() and check_rust_toolchains() - Extract check_multiple_versions() helper (DRY) - Add 4 test cases, optimize test performance - Fix shellcheck warnings All 393 tests passing.
This commit is contained in:
@@ -75,6 +75,41 @@ clean_dev_rust() {
|
||||
safe_clean ~/.cargo/git/* "Cargo git cache"
|
||||
safe_clean ~/.rustup/downloads/* "Rust downloads cache"
|
||||
}
|
||||
|
||||
# Helper: Check for multiple versions in a directory.
|
||||
# Args: $1=directory, $2=tool_name, $3+=additional_lines
|
||||
check_multiple_versions() {
|
||||
local dir="$1"
|
||||
local tool_name="$2"
|
||||
shift 2
|
||||
local -a additional_lines=("$@")
|
||||
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local count
|
||||
count=$(find "$dir" -mindepth 1 -maxdepth 1 -type d 2> /dev/null | wc -l | tr -d ' ')
|
||||
|
||||
if [[ "$count" -gt 1 ]]; then
|
||||
note_activity
|
||||
echo -e " Found ${GREEN}${count}${NC} ${tool_name}"
|
||||
for line in "${additional_lines[@]}"; do
|
||||
echo -e " $line"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Check for multiple Rust toolchains.
|
||||
check_rust_toolchains() {
|
||||
command -v rustup > /dev/null 2>&1 || return 0
|
||||
|
||||
check_multiple_versions \
|
||||
"$HOME/.rustup/toolchains" \
|
||||
"Rust toolchains" \
|
||||
"You can list them with: ${GRAY}rustup toolchain list${NC}" \
|
||||
"Remove unused with: ${GRAY}rustup toolchain uninstall <name>${NC}"
|
||||
}
|
||||
# Docker caches (guarded by daemon check).
|
||||
clean_dev_docker() {
|
||||
if command -v docker > /dev/null 2>&1; then
|
||||
@@ -130,19 +165,13 @@ clean_dev_frontend() {
|
||||
safe_clean ~/.cache/eslint/* "ESLint cache"
|
||||
safe_clean ~/.cache/prettier/* "Prettier cache"
|
||||
}
|
||||
# Mobile dev caches (can be large).
|
||||
# Check for multiple Android NDK versions.
|
||||
check_android_ndk() {
|
||||
local ndk_dir="$HOME/Library/Android/sdk/ndk"
|
||||
if [[ -d "$ndk_dir" ]]; then
|
||||
local count
|
||||
count=$(find "$ndk_dir" -mindepth 1 -maxdepth 1 -type d 2> /dev/null | wc -l | tr -d ' ')
|
||||
if [[ "$count" -gt 1 ]]; then
|
||||
note_activity
|
||||
echo -e " Found ${GREEN}${count}${NC} Android NDK versions"
|
||||
echo -e " You can delete unused versions manually: ${ndk_dir}"
|
||||
fi
|
||||
fi
|
||||
check_multiple_versions \
|
||||
"$HOME/Library/Android/sdk/ndk" \
|
||||
"Android NDK versions" \
|
||||
"Manage in: ${GRAY}Android Studio → SDK Manager${NC}" \
|
||||
"Or manually at: ${GRAY}\$HOME/Library/Android/sdk/ndk${NC}"
|
||||
}
|
||||
|
||||
clean_dev_mobile() {
|
||||
@@ -284,6 +313,7 @@ clean_developer_tools() {
|
||||
clean_dev_python
|
||||
clean_dev_go
|
||||
clean_dev_rust
|
||||
check_rust_toolchains
|
||||
clean_dev_docker
|
||||
clean_dev_cloud
|
||||
clean_dev_nix
|
||||
|
||||
@@ -83,6 +83,8 @@ clean_project_caches() { :; }
|
||||
clean_dev_python() { :; }
|
||||
clean_dev_go() { :; }
|
||||
clean_dev_rust() { :; }
|
||||
check_rust_toolchains() { :; }
|
||||
check_android_ndk() { :; }
|
||||
clean_dev_docker() { :; }
|
||||
clean_dev_cloud() { :; }
|
||||
clean_dev_nix() { :; }
|
||||
@@ -96,6 +98,10 @@ clean_dev_database() { :; }
|
||||
clean_dev_api_tools() { :; }
|
||||
clean_dev_network() { :; }
|
||||
clean_dev_misc() { :; }
|
||||
clean_dev_elixir() { :; }
|
||||
clean_dev_haskell() { :; }
|
||||
clean_dev_ocaml() { :; }
|
||||
clean_dev_editors() { :; }
|
||||
safe_clean() { :; }
|
||||
debug_log() { :; }
|
||||
clean_developer_tools
|
||||
|
||||
@@ -40,7 +40,9 @@ EOF
|
||||
|
||||
# Source and run the function
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/bin/clean.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
# shellcheck disable=SC2329
|
||||
safe_clean() { :; }
|
||||
clean_dev_elixir > /dev/null 2>&1 || true
|
||||
|
||||
# Verify the file still exists
|
||||
@@ -67,7 +69,9 @@ EOF
|
||||
|
||||
# Source and run the function
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/bin/clean.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
# shellcheck disable=SC2329
|
||||
safe_clean() { :; }
|
||||
clean_dev_haskell > /dev/null 2>&1 || true
|
||||
|
||||
# Verify the file still exists
|
||||
@@ -109,9 +113,39 @@ EOF
|
||||
|
||||
# Source and run the function
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/bin/clean.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
# shellcheck disable=SC2329
|
||||
safe_clean() { :; }
|
||||
clean_dev_editors > /dev/null 2>&1 || true
|
||||
|
||||
# Verify the file still exists
|
||||
[ -f "$HOME/Library/Application Support/Code/User/workspaceStorage/abc123/workspace.json" ]
|
||||
}
|
||||
|
||||
@test "check_android_ndk reports multiple NDK versions" {
|
||||
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk"/{21.0.1,22.0.0,20.0.0} && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Found 3 Android NDK versions"* ]]
|
||||
}
|
||||
|
||||
@test "check_android_ndk silent when only one NDK" {
|
||||
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk/22.0.0" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" != *"Found"*"NDK"* ]]
|
||||
}
|
||||
|
||||
@test "check_rust_toolchains reports multiple toolchains" {
|
||||
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains"/{stable,nightly,1.75.0}-aarch64-apple-darwin && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Found 3 Rust toolchains"* ]]
|
||||
}
|
||||
|
||||
@test "check_rust_toolchains silent when only one toolchain" {
|
||||
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" != *"Found"*"Rust"* ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user