blob: 7fb19439e70c52ed20a0e8b82c7b9256ef8839ff [file] [log] [blame]
Louis Dionne62248ac2019-01-09 16:35:55 +00001#!/usr/bin/env bash
2
3set -ue
4
5function usage() {
6 cat <<EOM
7$(basename ${0}) [-h|--help] --libcxx-root <LIBCXX-ROOT> --libcxxabi-root <LIBCXXABI-ROOT> --std <STD> --arch <ARCHITECTURE> [--lit-args <ARGS...>]
8
9This script is used to continually test libc++ and libc++abi trunk on MacOS.
10
Louis Dionned8a646c2019-02-05 16:42:37 +000011 --libcxx-root Full path to the root of the libc++ repository to test.
12 --libcxxabi-root Full path to the root of the libc++abi repository to test.
13 --std Version of the C++ Standard to run the tests under (c++03, c++11, etc..).
14 --arch Architecture to build the tests for (32, 64).
15 --libcxx-exceptions Whether to enable exceptions when building libc++ and running the libc++ tests. libc++abi is always built with support for exceptions because other libraries in the runtime depend on it (like libobjc). This must be ON or OFF.
16 [--lit-args] Additional arguments to pass to lit (optional). If there are multiple arguments, quote them to pass them as a single argument to this script.
17 [--no-cleanup] Do not cleanup the temporary directory that was used for testing at the end. This can be useful to debug failures. Make sure to clean up manually after.
18 [-h, --help] Print this help.
Louis Dionne62248ac2019-01-09 16:35:55 +000019EOM
20}
21
22while [[ $# -gt 0 ]]; do
23 case "$1" in
24 --libcxx-root)
25 LIBCXX_ROOT="${2}"
26 if [[ ! -e "${LIBCXX_ROOT}" ]]; then
27 echo "--libcxx-root '${LIBCXX_ROOT}' is not a valid directory"
28 usage
29 exit 1
30 fi
31 shift; shift
32 ;;
33 --libcxxabi-root)
34 LIBCXXABI_ROOT="${2}"
35 if [[ ! -e "${LIBCXXABI_ROOT}" ]]; then
36 echo "--libcxxabi-root '${LIBCXXABI_ROOT}' is not a valid directory"
37 usage
38 exit 1
39 fi
40 shift; shift
41 ;;
42 --std)
43 STD="${2}"
44 shift; shift
45 ;;
46 --arch)
47 ARCH="${2}"
48 shift; shift
49 ;;
Louis Dionned8a646c2019-02-05 16:42:37 +000050 --libcxx-exceptions)
51 LIBCXX_EXCEPTIONS="${2}"
52 shift; shift
53 ;;
Louis Dionne62248ac2019-01-09 16:35:55 +000054 --lit-args)
55 ADDITIONAL_LIT_ARGS="${2}"
56 shift; shift
57 ;;
58 --no-cleanup)
59 NO_CLEANUP=""
60 shift
61 ;;
62 -h|--help)
63 usage
64 exit 0
65 ;;
66 *)
67 echo "${1} is not a supported argument"
68 usage
69 exit 1
70 ;;
71 esac
72done
73
74if [[ -z ${LIBCXX_ROOT+x} ]]; then echo "--libcxx-root is a required parameter"; usage; exit 1; fi
75if [[ -z ${LIBCXXABI_ROOT+x} ]]; then echo "--libcxxabi-root is a required parameter"; usage; exit 1; fi
76if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi
77if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi
Louis Dionned8a646c2019-02-05 16:42:37 +000078if [[ "${LIBCXX_EXCEPTIONS}" != "ON" && "${LIBCXX_EXCEPTIONS}" != "OFF" ]]; then echo "--libcxx-exceptions is a required parameter and must be either ON or OFF"; usage; exit 1; fi
Louis Dionne62248ac2019-01-09 16:35:55 +000079if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi
80
81
82TEMP_DIR="$(mktemp -d)"
83echo "Created temporary directory ${TEMP_DIR}"
84function cleanup {
85 if [[ -z ${NO_CLEANUP+x} ]]; then
86 echo "Removing temporary directory ${TEMP_DIR}"
87 rm -rf "${TEMP_DIR}"
88 else
89 echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself"
90 fi
91}
92trap cleanup EXIT
93
94
95LLVM_ROOT="${TEMP_DIR}/llvm"
96LIBCXX_BUILD_DIR="${TEMP_DIR}/libcxx-build"
97LIBCXX_INSTALL_DIR="${TEMP_DIR}/libcxx-install"
98LIBCXXABI_BUILD_DIR="${TEMP_DIR}/libcxxabi-build"
99LIBCXXABI_INSTALL_DIR="${TEMP_DIR}/libcxxabi-install"
100
Louis Dionne62248ac2019-01-09 16:35:55 +0000101
102echo "@@@ Downloading LLVM tarball of master (only used for CMake configuration) @@@"
103mkdir "${LLVM_ROOT}"
Louis Dionnea56a2152019-03-20 15:40:56 +0000104LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz"
Louis Dionne62248ac2019-01-09 16:35:55 +0000105curl -L "${LLVM_TARBALL_URL}" | tar -xz --strip-components=1 -C "${LLVM_ROOT}"
106echo "@@@@@@"
107
108
109echo "@@@ Setting up LIT flags @@@"
110LIT_FLAGS="-sv --param=std=${STD} ${ADDITIONAL_LIT_ARGS}"
111if [[ "${ARCH}" == "32" ]]; then
112 LIT_FLAGS+=" --param=enable_32bit=true"
113fi
114echo "@@@@@@"
115
116
117echo "@@@ Configuring CMake for libc++ @@@"
118mkdir -p "${LIBCXX_BUILD_DIR}"
119(cd "${LIBCXX_BUILD_DIR}" &&
120 xcrun cmake "${LIBCXX_ROOT}" -GNinja \
121 -DLLVM_PATH="${LLVM_ROOT}" \
122 -DCMAKE_INSTALL_PREFIX="${LIBCXX_INSTALL_DIR}" \
Louis Dionned8a646c2019-02-05 16:42:37 +0000123 -DLIBCXX_ENABLE_EXCEPTIONS="${LIBCXX_EXCEPTIONS}" \
Louis Dionne68e3d0a2019-04-16 20:46:03 +0000124 -DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=OFF \
Louis Dionne62248ac2019-01-09 16:35:55 +0000125 -DLLVM_LIT_ARGS="${LIT_FLAGS}" \
126 -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib
127)
128echo "@@@@@@"
129
130
131echo "@@@ Configuring CMake for libc++abi @@@"
132mkdir -p "${LIBCXXABI_BUILD_DIR}"
133(cd "${LIBCXXABI_BUILD_DIR}" &&
134 xcrun cmake "${LIBCXXABI_ROOT}" -GNinja \
135 -DLIBCXXABI_LIBCXX_PATH="${LIBCXX_ROOT}" \
136 -DLLVM_PATH="${LLVM_ROOT}" \
137 -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_INSTALL_DIR}" \
Louis Dionned8a646c2019-02-05 16:42:37 +0000138 -DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
Louis Dionne68e3d0a2019-04-16 20:46:03 +0000139 -DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=ON \
Louis Dionne62248ac2019-01-09 16:35:55 +0000140 -DLLVM_LIT_ARGS="${LIT_FLAGS}" \
141 -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib
142)
143echo "@@@@@@"
144
145
146echo "@@@ Building libc++.dylib and libc++abi.dylib from sources (just to make sure it works) @@@"
Louis Dionne8baf80e2019-04-16 21:16:58 +0000147ninja -C "${LIBCXX_BUILD_DIR}" install-cxx -v
148ninja -C "${LIBCXXABI_BUILD_DIR}" install-cxxabi -v
Louis Dionne62248ac2019-01-09 16:35:55 +0000149echo "@@@@@@"
150
151
152echo "@@@ Running tests for libc++ @@@"
153# TODO: We should run check-cxx-abilist too
154ninja -C "${LIBCXX_BUILD_DIR}" check-cxx
155echo "@@@@@@"
156
157
158echo "@@@ Running tests for libc++abi @@@"
159ninja -C "${LIBCXXABI_BUILD_DIR}" check-cxxabi
160echo "@@@@@@"