Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit 473e1e4

Browse files
committed
driver: Improvements around binary locating
We've tailored driver.sh around our Docker image with regards to the binary versions that we check for. A user might not have the latest versions of Clang or llvm-ar installed. Check for all three versions offered by apt.llvm.org, falling back to the generic binary name if those are not found. Additionally, for llvm-ar, do a sanity check that the user has a version of llvm-ar that can actually build the kernel (has support for the P modifier). If they don't fall back to regular GNU ar and let them know. Presubmit: https://travis-ci.com/nathanchance/continuous-integration/builds/103470578 [skip ci] Signed-off-by: Nathan Chancellor <[email protected]>
1 parent 02d50bc commit 473e1e4

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

driver.sh

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,72 @@ setup_variables() {
139139
}
140140

141141
check_dependencies() {
142+
# Check for existence of needed binaries
142143
command -v nproc
143144
command -v "${CROSS_COMPILE:-}"as
144145
command -v ${qemu}
145146
command -v timeout
146147
command -v unbuffer
147-
command -v clang-9
148-
command -v llvm-ar-9
149-
command -v "${LD:="${CROSS_COMPILE:-}"ld}"
148+
149+
# Check for LD, CC, and AR environmental variables
150+
# and print the version string of each. If CC and AR
151+
# don't exist, try to find them.
152+
# lld isn't ready for all architectures so it's just
153+
# simpler to fall back to GNU ld when LD isn't specified
154+
# to avoid architecture specific selection logic.
155+
156+
"${LD:="${CROSS_COMPILE:-}"ld}" --version
157+
158+
if [[ -z "${CC:-}" ]]; then
159+
for CC in clang-9 clang-8 clang-7 clang; do
160+
command -v ${CC} &>/dev/null && break
161+
done
162+
fi
163+
${CC} --version 2>/dev/null || {
164+
set +x
165+
echo
166+
echo "Looks like ${CC} could not be found in PATH!"
167+
echo
168+
echo "Please install as recent a version of clang as you can from your distro or"
169+
echo "properly specify the CC variable to point to the correct clang binary."
170+
echo
171+
echo "If you don't want to install clang, you can either download AOSP's prebuilt"
172+
echo "clang [1] or build it from source [2] then add the bin folder to your PATH."
173+
echo
174+
echo "[1]: https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/"
175+
echo "[2]: https://github.com/ClangBuiltLinux/linux/wiki/Building-Clang-from-source"
176+
echo
177+
exit;
178+
}
179+
180+
if [[ -z "${AR:-}" ]]; then
181+
for AR in llvm-ar-9 llvm-ar-8 llvm-ar-7 llvm-ar "${CROSS_COMPILE:-}"ar; do
182+
command -v ${AR} 2>/dev/null && break
183+
done
184+
fi
185+
check_ar_version
186+
${AR} --version
187+
}
188+
189+
# Optimistically check to see that the user has a llvm-ar
190+
# with https://reviews.llvm.org/rL354044. If they don't,
191+
# fall back to GNU ar and let them know.
192+
check_ar_version() {
193+
if ${AR} --version | grep -q "LLVM" && \
194+
[[ $(${AR} --version | grep version | sed -e 's/.*LLVM version //g' -e 's/[[:blank:]]*$//' -e 's/\.//g') -lt 900 ]]; then
195+
set +x
196+
echo
197+
echo "${AR} found but appears to be too old to build the kernel (needs to be at least 9.0.0)."
198+
echo
199+
echo "Please either update llvm-ar from your distro or build it from source!"
200+
echo
201+
echo "See https://github.com/ClangBuiltLinux/linux/issues/33 for more info."
202+
echo
203+
echo "Falling back to GNU ar..."
204+
echo
205+
AR=${CROSS_COMPILE:-}ar
206+
set -x
207+
fi
150208
}
151209

152210
mako_reactor() {
@@ -155,11 +213,12 @@ mako_reactor() {
155213
KBUILD_BUILD_TIMESTAMP="Thu Jan 1 00:00:00 UTC 1970" \
156214
KBUILD_BUILD_USER=driver \
157215
KBUILD_BUILD_HOST=clangbuiltlinux \
158-
make -j"${jobs:-$(nproc)}" CC="${CC}" HOSTCC="${CC}" LD="${LD}" HOSTLD="${HOSTLD:-ld}" AR="llvm-ar-9" "${@}"
216+
make -j"${jobs:-$(nproc)}" CC="${CC}" HOSTCC="${CC}" LD="${LD}" HOSTLD="${HOSTLD:-ld}" AR="${AR}" "${@}"
159217
}
160218

161219
build_linux() {
162-
CC="$(command -v ccache) $(command -v clang-9)"
220+
# Wrap CC in ccache if it is available (it's not strictly required)
221+
CC="$(command -v ccache) ${CC}"
163222
[[ ${LD} =~ lld ]] && HOSTLD=${LD}
164223

165224
if [[ -d ${tree} ]]; then

0 commit comments

Comments
 (0)