Make RustRover work with Rust from Nixpkgs
1#!/usr/bin/env bash
2
3INSTALLED_ONLY=false
4if [[ "$2" == "--installed" ]] || [[ "$1" == "--installed" ]]; then
5 INSTALLED_ONLY=true
6 if [[ "$1" == "--installed" ]]; then
7 SYSROOT="$2"
8 else
9 SYSROOT="$1"
10 fi
11else
12 SYSROOT="$1"
13fi
14
15if [[ -z "$SYSROOT" ]] || [[ ! -d "$SYSROOT" ]]; then
16 echo "Error: Invalid sysroot directory" >&2
17 exit 1
18fi
19
20declare -A COMPONENTS
21COMPONENTS=(
22 ["rustc"]="bin/rustc"
23 ["cargo"]="bin/cargo"
24 ["clippy"]="bin/clippy-driver"
25 ["rustfmt"]="bin/rustfmt"
26 ["rust-docs"]="share/doc/rust/html/index.html"
27 ["rust-std"]="lib/rustlib"
28 ["rust-analyzer"]="bin/rust-analyzer"
29 ["llvm-tools"]="lib/rustlib/*/bin/llvm-*"
30)
31
32declare -A INSTALLED
33for component in "${!COMPONENTS[@]}"; do
34 path="${COMPONENTS[$component]}"
35 if [[ "$path" == *"*"* ]]; then
36 if compgen -G "$SYSROOT/$path" > /dev/null 2>&1; then
37 INSTALLED[$component]=true
38 else
39 INSTALLED[$component]=false
40 fi
41 else
42 if [[ -e "$SYSROOT/$path" ]]; then
43 INSTALLED[$component]=true
44 else
45 INSTALLED[$component]=false
46 fi
47 fi
48done
49
50if $INSTALLED_ONLY; then
51 for component in rustc cargo rust-std clippy rustfmt rust-docs rust-analyzer llvm-tools; do
52 if [[ "${INSTALLED[$component]}" == "true" ]]; then
53 echo "$component"
54 fi
55 done
56else
57 for component in rustc cargo rust-std clippy rustfmt rust-docs rust-analyzer llvm-tools; do
58 if [[ "${INSTALLED[$component]}" == "true" ]]; then
59 echo "$component (installed)"
60 else
61 echo "$component"
62 fi
63 done
64fi