Skip to content

Commit 26766cd

Browse files
committed
Refactor before_install script
Remove needless pushd that was causing trouble with `set -e` Remove old osx workaround for rvm Add shebang line Fix target descriptor Support LLVM versions 9.0.1+
1 parent 94bce16 commit 26766cd

File tree

1 file changed

+61
-39
lines changed

1 file changed

+61
-39
lines changed

ci/before_install.sh

+61-39
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,85 @@
1-
set -ex
2-
pushd ~
3-
4-
# Workaround for Travis CI macOS bug (https://github.com/travis-ci/travis-ci/issues/6307)
5-
if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
6-
rvm get head || true
7-
fi
1+
#!/usr/bin/env bash
2+
# Bail on first error
3+
set -e
4+
# Bail if an unset variable is encountered
5+
set -u
6+
# Enable debugging output
7+
set -x
8+
# Give a pipeline a non-zero exit code if one of its constituents fails
9+
set -o pipefail
810

911
function llvm_linux_target_triple() {
10-
if [ "$1" == "5.0" ]; then
11-
echo "linux-x86_64-ubuntu14.04"
12-
else
13-
echo "x86_64-linux-gnu-ubuntu-14.04"
14-
fi
12+
case "$1" in
13+
5.*) echo "linux-x86_64-ubuntu14.04" ;;
14+
*) echo "x86_64-linux-gnu-ubuntu-14.04" ;;
15+
esac
16+
}
17+
18+
function llvm_macos_target_triple() {
19+
case "$1" in
20+
[0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;;
21+
# Starting with 9.0.1, triple swapped ordering
22+
*) echo "x86_64-apple-darwin" ;;
23+
esac
1524
}
1625

1726
function llvm_version_triple() {
18-
if [ "$1" == "3.5" ]; then
19-
echo "3.5.2"
20-
elif [ "$1" == "3.6" ]; then
21-
echo "3.6.2"
22-
elif [ "$1" == "3.7" ]; then
23-
echo "3.7.1"
24-
elif [ "$1" == "3.8" ]; then
25-
echo "3.8.1"
26-
elif [ "$1" == "3.9" ]; then
27-
echo "3.9.0"
28-
elif [ "$1" == "4.0" ]; then
29-
echo "4.0.0"
30-
elif [ "$1" == "5.0" ]; then
31-
echo "5.0.0"
32-
elif [ "$1" == "9.0" ]; then
33-
echo "9.0.0"
34-
fi
27+
case "$1" in
28+
3.5) echo "3.5.2" ;;
29+
3.6) echo "3.6.2" ;;
30+
3.7) echo "3.7.1" ;;
31+
3.8) echo "3.8.1" ;;
32+
# By default, take the .0 patch release
33+
*) echo "$1.0" ;;
34+
esac
35+
}
36+
37+
function llvm_base_url() {
38+
local llvm_version_triple=$1
39+
40+
case "$llvm_version_triple" in
41+
[0-8].* | 9.0.0)
42+
echo "http://releases.llvm.org/$llvm_version_triple"
43+
;;
44+
# Starting with 9.0.1, releases are hosted on github
45+
*)
46+
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple"
47+
;;
48+
esac
3549
}
3650

3751
function llvm_download() {
38-
export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}`
39-
export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$1
52+
local base_url=$1
53+
local arch=$2
54+
55+
export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch
4056
export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}"
4157

58+
local base_url
59+
4260
if [ -d "${LLVM_DIRECTORY}" ]; then
4361
echo "Using cached LLVM download for ${LLVM}..."
4462
else
45-
wget http://releases.llvm.org/${LLVM_VERSION_TRIPLE}/${LLVM}.tar.xz
63+
wget $base_url/${LLVM}.tar.xz
4664
mkdir -p "${LLVM_DIRECTORY}"
4765
tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1
4866
fi
4967

68+
export LIBCLANG_PATH="${LLVM_DIRECTORY}/lib"
5069
export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config"
5170
}
5271

72+
export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}`
73+
74+
base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}`
75+
5376
if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
54-
llvm_download `llvm_linux_target_triple ${LLVM_VERSION}`
55-
export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":$LD_LIBRARY_PATH
77+
llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}`
78+
export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-}
5679
else
57-
llvm_download x86_64-apple-darwin
58-
cp "${LLVM_DIRECTORY}/lib/libclang.dylib" /usr/local/lib/libclang.dylib
59-
export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":$DYLD_LIBRARY_PATH
80+
llvm_download $base_url `llvm_macos_target_triple ${LLVM_VERSION_TRIPLE}`
81+
export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${DYLD_LIBRARY_PATH:-}
6082
fi
6183

62-
popd
63-
set +e
84+
# Subsequent scripts can see the state of `set -eu`, so unset it again.
85+
set +eu

0 commit comments

Comments
 (0)