Skip to content

Commit 833a219

Browse files
authored
Make run-clang-tidy.sh pick a default LLVM installation (halide#8904)
1 parent 5742605 commit 833a219

File tree

2 files changed

+61
-35
lines changed

2 files changed

+61
-35
lines changed

run-clang-format.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,33 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
66

77
##
88

9+
# We standardize a common LLVM/Clang version for this script.
10+
# Note that this is totally independent of the version of LLVM that you
11+
# are using to build Halide itself. If you don't have the right version
12+
# installed, you can usually install what you need easily via:
13+
#
14+
# sudo apt-get install llvm-X clang-X libclang-X-dev clang-tidy-X
15+
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-X
16+
#
17+
# On macOS:
18+
#
19+
# brew install llvm@X
20+
# export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@X
21+
#
22+
# Where X matches the EXPECTED_VERSION below.
23+
924
EXPECTED_VERSION=21
1025

1126
##
1227

1328
usage() { echo -e "Usage: $0 [-c]" 1>&2; exit 1; }
1429

30+
if [ "$(uname)" == "Darwin" ]; then
31+
_DEFAULT_LLVM_LOCATION="/opt/homebrew/opt/llvm@$EXPECTED_VERSION"
32+
else
33+
_DEFAULT_LLVM_LOCATION="/usr/lib/llvm-$EXPECTED_VERSION"
34+
fi
35+
1536
# Fix the formatting in-place
1637
MODE_FLAGS=(-i --sort-includes)
1738

@@ -43,22 +64,13 @@ if [[ "${MODE_FLAGS[*]}" =~ "-i" ]]; then
4364
fi
4465
fi
4566

46-
# We are currently standardized on using LLVM/Clang19 for this script.
47-
# Note that this is totally independent of the version of LLVM that you
48-
# are using to build Halide itself. If you don't have LLVM19 installed,
49-
# you can usually install what you need easily via:
50-
#
51-
# sudo apt-get install llvm-19 clang-19 libclang-19-dev clang-tidy-19
52-
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/usr/lib/llvm-19
53-
#
54-
# On macOS:
55-
#
56-
# brew install llvm@19
57-
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@19
58-
5967
if [ -z "$CLANG_FORMAT_LLVM_INSTALL_DIR" ]; then
60-
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
61-
exit 1
68+
if [ -d "${_DEFAULT_LLVM_LOCATION}" ]; then
69+
CLANG_FORMAT_LLVM_INSTALL_DIR="${_DEFAULT_LLVM_LOCATION}"
70+
else
71+
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
72+
exit 1
73+
fi
6274
fi
6375

6476
echo "CLANG_FORMAT_LLVM_INSTALL_DIR=${CLANG_FORMAT_LLVM_INSTALL_DIR}"

run-clang-tidy.sh

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ set -e
44

55
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
66

7+
##
8+
9+
# We standardize a common LLVM/Clang version for this script.
10+
# Note that this is totally independent of the version of LLVM that you
11+
# are using to build Halide itself. If you don't have the right version
12+
# installed, you can usually install what you need easily via:
13+
#
14+
# sudo apt-get install llvm-X clang-X libclang-X-dev clang-tidy-X
15+
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-X
16+
#
17+
# On macOS:
18+
#
19+
# brew install llvm@X
20+
# export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@X
21+
#
22+
# Where X matches the EXPECTED_VERSION below.
23+
24+
EXPECTED_VERSION=21
25+
26+
##
27+
728
usage() { echo "Usage: $0 [-j MAX_PROCESS_COUNT] [-f]" 1>&2; exit 1; }
829

930
get_thread_count () {
@@ -13,8 +34,10 @@ get_thread_count () {
1334

1435
if [ "$(uname)" == "Darwin" ]; then
1536
patch_file () { sed -i '' -E "$@"; }
37+
_DEFAULT_LLVM_LOCATION="/opt/homebrew/opt/llvm@$EXPECTED_VERSION"
1638
else
1739
patch_file () { sed -i -E "$@"; }
40+
_DEFAULT_LLVM_LOCATION="/usr/lib/llvm-$EXPECTED_VERSION"
1841
fi
1942

2043
J=$(get_thread_count)
@@ -41,32 +64,22 @@ if [ -n "${FIX}" ]; then
4164
echo "Operating in -fix mode!"
4265
fi
4366

44-
# We are currently standardized on using LLVM/Clang 21 for this script.
45-
# Note that this is totally independent of the version of LLVM that you
46-
# are using to build Halide itself. If you don't have LLVM21 installed,
47-
# you can usually install what you need easily via:
48-
#
49-
# sudo apt-get install llvm-21 clang-21 libclang-21-dev clang-tidy-21
50-
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-21
51-
#
52-
# On macOS:
53-
#
54-
# brew install llvm@21
55-
# export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@21
56-
5767
if [ -z "$CLANG_TIDY_LLVM_INSTALL_DIR" ]; then
58-
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
59-
exit
68+
if [ -d "${_DEFAULT_LLVM_LOCATION}" ]; then
69+
CLANG_TIDY_LLVM_INSTALL_DIR="${_DEFAULT_LLVM_LOCATION}"
70+
else
71+
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
72+
exit
73+
fi
6074
fi
6175

6276
echo "CLANG_TIDY_LLVM_INSTALL_DIR = ${CLANG_TIDY_LLVM_INSTALL_DIR}"
6377

6478
VERSION=$("${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/clang-tidy" --version)
65-
if [[ ${VERSION} =~ .*version\ 21.* ]]
66-
then
67-
echo "clang-tidy version 21 found."
79+
if [[ ${VERSION} =~ .*version\ $EXPECTED_VERSION.* ]]; then
80+
echo "clang-tidy version $EXPECTED_VERSION found."
6881
else
69-
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM 21 install!"
82+
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM $EXPECTED_VERSION install!"
7083
exit 1
7184
fi
7285

@@ -94,10 +107,11 @@ if [[ $(${CC} --version) =~ .*Homebrew.* ]]; then
94107
SDKROOT="$(xcrun --show-sdk-path)"
95108
# TOOLCHAINROOT="$(xcrun --show-toolchain-path)"
96109
TOOLCHAINROOT="$(cd "$(dirname "$(xcrun --find clang)")"/../.. && pwd)"
110+
RCDIR="$(xcrun clang -print-resource-dir)"
97111
cat > "${CLANG_TIDY_BUILD_DIR}/toolchain.cmake" << EOF
98112
set(CMAKE_SYSROOT "${SDKROOT}")
99113
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES
100-
"${TOOLCHAINROOT}/usr/lib/clang/17/include"
114+
"${RCDIR}/include"
101115
"${SDKROOT}/usr/include"
102116
"${TOOLCHAINROOT}/usr/include"
103117
"${SDKROOT}/System/Library/Frameworks"

0 commit comments

Comments
 (0)