xref: /openbmc/libpldm/scripts/apply-renames (revision 28b649bc)
16bfc65c1SAndrew Jeffery#!/usr/bin/bash
26bfc65c1SAndrew Jeffery
36bfc65c1SAndrew Jefferyset -eou pipefail
46bfc65c1SAndrew Jeffery
56bfc65c1SAndrew Jeffery# Path to the meson build directory
66bfc65c1SAndrew Jeffery: "${BUILD:=build}"
76bfc65c1SAndrew Jeffery
86bfc65c1SAndrew JefferyABSPATH="$(command -v "$0" | xargs realpath)"
96bfc65c1SAndrew Jeffery
106bfc65c1SAndrew Jeffery# Deal with relative paths
116bfc65c1SAndrew Jeffery: "${LIBPLDM_ROOT:="${ABSPATH%scripts/apply-renames}"}"
126bfc65c1SAndrew Jeffery
136bfc65c1SAndrew Jeffery# Deal with clang including its version in all the tool names
14*28b649bcSAndrew Jeffery: "${CLANG_VERSION:=18}"
156bfc65c1SAndrew Jeffery: "${CLANG_RENAME:="$(command -v clang-rename-"${CLANG_VERSION}")"}"
166bfc65c1SAndrew Jeffery: "${CLANG_APPLY_REPLACEMENTS:="$(command -v clang-apply-replacements-"${CLANG_VERSION}")"}"
176bfc65c1SAndrew Jeffery
186bfc65c1SAndrew Jeffery# Make it parallel
196bfc65c1SAndrew Jeffery: "${JOBS:="$(nproc)"}"
206bfc65c1SAndrew Jeffery
216bfc65c1SAndrew Jeffery# Allow clang-rename to pick up the per-file flags from the compile command
226bfc65c1SAndrew Jeffery# database
236bfc65c1SAndrew Jeffery: "${CRFLAGS:="-p=."}"
246bfc65c1SAndrew Jeffery
256bfc65c1SAndrew JefferyCRINPUT=$(realpath --relative-to "$BUILD" "$1")
266bfc65c1SAndrew Jeffery
276bfc65c1SAndrew Jeffery# Deal with clang-rename segfaulting when file paths from the compile command
286bfc65c1SAndrew Jeffery# database don't resolve properly
296bfc65c1SAndrew Jefferycd "$BUILD"
306bfc65c1SAndrew Jeffery
316bfc65c1SAndrew Jeffery# We export the fixes to yaml files so we can apply them all in one hit later
326bfc65c1SAndrew Jefferytrap "rm -f fixes.*.yaml" EXIT
336bfc65c1SAndrew Jeffery
346bfc65c1SAndrew Jeffery# See `man 7 gitglossary` for some explanation of the pathspec provided to `git
356bfc65c1SAndrew Jeffery# ls-files`, which, separately, is also subject to bash's brace expansion. See
366bfc65c1SAndrew Jeffery# "Brace Expansion" in `man bash`.
376bfc65c1SAndrew Jeffery# shellcheck disable=SC2016
386bfc65c1SAndrew Jefferygit ls-files -- ':/:*.[ch]'{,pp} |
396bfc65c1SAndrew Jefferyxargs -I '{}' -n 1 -P "$JOBS" -- \
406bfc65c1SAndrew Jeffery    bash -c '"$0" --force --input="$1" --export-fixes="$(mktemp fixes.XXXXX.yaml)" "$2" "$3"' \
416bfc65c1SAndrew Jeffery    "$CLANG_RENAME" "$CRINPUT" "$CRFLAGS" '{}'
426bfc65c1SAndrew Jeffery
436bfc65c1SAndrew Jeffery# Now apply the generated fixes
446bfc65c1SAndrew Jeffery"$CLANG_APPLY_REPLACEMENTS" ..
456bfc65c1SAndrew Jeffery
466bfc65c1SAndrew Jeffery# Deal with subsequent runs of clang-rename bailing out because it's modified
476bfc65c1SAndrew Jeffery# the symbol declaration in the headers, and then is surprised by the lack of a
486bfc65c1SAndrew Jeffery# declaration for the as-yet un-renamed symbol in the implementation
496bfc65c1SAndrew Jefferygit -C "$LIBPLDM_ROOT" restore -- include
50