|
29 | 29 | # |
30 | 30 | # A compile database that names BMIs explicitly (-fmodule-file=...), which |
31 | 31 | # only a build actually produces: `mcpp build --toolchain llvm@22.1.8` writes |
32 | | -# compile_commands.json at the project root. This script does not build it -- |
33 | | -# the caller (a developer, or the CI step beside this one) runs that build |
34 | | -# first, the same division check_file_lengths.sh has none of because it reads |
35 | | -# the tree directly. |
| 32 | +# compile_commands.json at the project root. This script does not build it: |
| 33 | +# the caller runs that build first (a developer, or ci-linux.yml's LLVM |
| 34 | +# toolchain job, which builds mcpp with llvm@20.1.7 before this step). |
| 35 | +# check_file_lengths.sh needs no such division because it reads the tree. |
36 | 36 | # |
37 | 37 | # clang-tidy itself is not part of the plain xim:llvm payload mcpp resolves |
38 | 38 | # for `--toolchain llvm@...` (measured: xim-x-llvm/22.1.8/bin has clang, |
|
70 | 70 | fi |
71 | 71 |
|
72 | 72 | # Locate clang-tidy. It is not in the plain xim:llvm payload (see the header |
73 | | -# comment); look for the sibling xim:llvm-tools payload under either xlings |
74 | | -# store layout this machine may use, preferring a version that matches an |
75 | | -# xim:llvm payload actually installed (compile_commands.json was built with |
76 | | -# one of those), and falling back to any clang-tidy the store has. |
77 | | -find_clang_tidy() { |
78 | | - local roots=( |
79 | | - "$HOME/.mcpp/registry/data/xpkgs" |
80 | | - "$HOME/.xlings/data/xpkgs" |
81 | | - ) |
82 | | - local llvm_versions=() |
83 | | - for root in "${roots[@]}"; do |
84 | | - [ -d "$root/xim-x-llvm" ] || continue |
85 | | - while IFS= read -r v; do llvm_versions+=("$v"); done \ |
86 | | - < <(find "$root/xim-x-llvm" -maxdepth 1 -mindepth 1 -type d -printf '%f\n' 2>/dev/null) |
87 | | - done |
88 | | - for root in "${roots[@]}"; do |
89 | | - for v in "${llvm_versions[@]}"; do |
90 | | - local cand="$root/xim-x-llvm-tools/$v/bin/clang-tidy" |
91 | | - [ -x "$cand" ] && { echo "$cand"; return 0; } |
92 | | - done |
93 | | - done |
94 | | - for root in "${roots[@]}"; do |
95 | | - local cand |
96 | | - cand=$(find "$root/xim-x-llvm-tools" -maxdepth 3 -type f -name clang-tidy 2>/dev/null | sort -V | tail -1) |
97 | | - [ -n "$cand" ] && [ -x "$cand" ] && { echo "$cand"; return 0; } |
| 73 | +# comment); it is the sibling xim:llvm-tools payload, and it must be the |
| 74 | +# version of the clang that wrote compile_commands.json, because it reads the |
| 75 | +# BMIs that clang wrote. `CLANG_TIDY` may name it explicitly; otherwise |
| 76 | +# the version is read from the compiler path the database names |
| 77 | +# (`.../xim-x-llvm/<version>/bin/clang++`) and looked up in either xlings store. |
| 78 | +cdb_llvm_version() { |
| 79 | + grep -o 'xim-x-llvm/[0-9][0-9.]*/bin/clang' "$CDB" 2>/dev/null | head -1 \ |
| 80 | + | sed 's|xim-x-llvm/\([0-9.]*\)/bin/clang|\1|' |
| 81 | +} |
| 82 | +find_clang_tidy() { # $1 = the llvm version |
| 83 | + local root |
| 84 | + for root in "${MCPP_HOME:-$HOME/.mcpp}/registry/data/xpkgs" "$HOME/.xlings/data/xpkgs"; do |
| 85 | + [ -x "$root/xim-x-llvm-tools/$1/bin/clang-tidy" ] \ |
| 86 | + && { echo "$root/xim-x-llvm-tools/$1/bin/clang-tidy"; return 0; } |
98 | 87 | done |
99 | 88 | return 1 |
100 | 89 | } |
101 | 90 |
|
102 | | -CLANG_TIDY="$(find_clang_tidy)" || { |
103 | | - cat >&2 <<EOF |
104 | | -FAIL: no clang-tidy found under an xlings package store. |
105 | | - Install the sibling of your llvm toolchain, e.g.: |
106 | | - xlings install xim:llvm-tools@22.1.8 |
| 91 | +if [ -n "${CLANG_TIDY:-}" ]; then |
| 92 | + [ -x "$CLANG_TIDY" ] || { echo "FAIL: CLANG_TIDY=$CLANG_TIDY is not executable" >&2; exit 1; } |
| 93 | +else |
| 94 | + LLVM_VERSION="$(cdb_llvm_version)" |
| 95 | + CLANG_TIDY="$( [ -n "$LLVM_VERSION" ] && find_clang_tidy "$LLVM_VERSION" )" || { |
| 96 | + cat >&2 <<EOF |
| 97 | +FAIL: no clang-tidy of the llvm version that wrote $CDB (${LLVM_VERSION:-unknown}) |
| 98 | + was found under an xlings package store. Install that toolchain's sibling: |
| 99 | + xlings install xim:llvm-tools@${LLVM_VERSION:-<version>} |
107 | 100 | EOF |
108 | | - exit 1 |
109 | | -} |
| 101 | + exit 1 |
| 102 | + } |
| 103 | +fi |
110 | 104 |
|
111 | 105 | # The files this database actually has entries for, restricted to the |
112 | 106 | # decomposition's own directory (plus the primary interface, if it is ever |
|
0 commit comments