Skip to content

Commit cdb87e8

Browse files
committed
ci: the function-size gate runs after the LLVM self-build; clang-tidy is resolved at the version that wrote the compile database
1 parent 7ba4157 commit cdb87e8

2 files changed

Lines changed: 40 additions & 36 deletions

File tree

‎.github/tools/check_function_sizes.sh‎

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#
3030
# A compile database that names BMIs explicitly (-fmodule-file=...), which
3131
# 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.
3636
#
3737
# clang-tidy itself is not part of the plain xim:llvm payload mcpp resolves
3838
# for `--toolchain llvm@...` (measured: xim-x-llvm/22.1.8/bin has clang,
@@ -70,43 +70,37 @@ EOF
7070
fi
7171

7272
# 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; }
9887
done
9988
return 1
10089
}
10190

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>}
107100
EOF
108-
exit 1
109-
}
101+
exit 1
102+
}
103+
fi
110104

111105
# The files this database actually has entries for, restricted to the
112106
# decomposition's own directory (plus the primary interface, if it is ever

‎.github/workflows/ci-linux.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ jobs:
253253
# Restore
254254
sed -i 's/^default = "llvm@20.1.7"/default = "gcc@16.1.0"/' mcpp.toml
255255
256+
# The function-size gate (mcpp#722) reads clang-tidy's own function
257+
# boundaries over the compile database the LLVM build above wrote, so it
258+
# runs here, where mcpp itself was just built with clang. clang-tidy is
259+
# the sibling payload xim:llvm-tools at that clang's version, because it
260+
# reads the BMIs that clang wrote.
261+
- name: "Function-size gate (src/build/prepare, clang-tidy)"
262+
run: |
263+
XLINGS_HOME="$MCPP_HOME/registry" "$XLINGS_BIN" install xim:llvm-tools@20.1.7 -y
264+
bash .github/tools/check_function_sizes.sh
265+
256266
# Integration: the mcpp built from THIS PR's source builds & runs a real
257267
# external C++ project — xlings (openxlings/xlings ships its own mcpp.toml).
258268
# MCPP_VENDORED_XLINGS only supplies the xlings package backend that mcpp

0 commit comments

Comments
 (0)