blob: 7139a24c1160647e72c192a5ae7e4ba38ae53626 [file] [log] [blame]
Louis Dionnecb4e59e2019-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 Dionnea3ec6272019-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.
Louis Dionne3b1ef582019-07-19 18:47:00 +000016 [--cmake-args] Additional arguments to pass to CMake (both the libc++ and the libc++abi configuration). If there are multiple arguments, quote them to paass them as a single argument to this script.
17 [--lit-args] Additional arguments to pass to lit. If there are multiple arguments, quote them to pass them as a single argument to this script.
Louis Dionnea3ec6272019-02-05 16:42:37 +000018 [--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.
19 [-h, --help] Print this help.
Louis Dionnecb4e59e2019-01-09 16:35:55 +000020EOM
21}
22
23while [[ $# -gt 0 ]]; do
24 case "$1" in
25 --libcxx-root)
26 LIBCXX_ROOT="${2}"
27 if [[ ! -e "${LIBCXX_ROOT}" ]]; then
28 echo "--libcxx-root '${LIBCXX_ROOT}' is not a valid directory"
29 usage
30 exit 1
31 fi
32 shift; shift
33 ;;
34 --libcxxabi-root)
35 LIBCXXABI_ROOT="${2}"
36 if [[ ! -e "${LIBCXXABI_ROOT}" ]]; then
37 echo "--libcxxabi-root '${LIBCXXABI_ROOT}' is not a valid directory"
38 usage
39 exit 1
40 fi
41 shift; shift
42 ;;
43 --std)
44 STD="${2}"
45 shift; shift
46 ;;
47 --arch)
48 ARCH="${2}"
49 shift; shift
50 ;;
Louis Dionnea3ec6272019-02-05 16:42:37 +000051 --libcxx-exceptions)
52 LIBCXX_EXCEPTIONS="${2}"
53 shift; shift
54 ;;
Louis Dionne3b1ef582019-07-19 18:47:00 +000055 --cmake-args)
56 ADDITIONAL_CMAKE_ARGS="${2}"
57 shift; shift
58 ;;
Louis Dionnecb4e59e2019-01-09 16:35:55 +000059 --lit-args)
60 ADDITIONAL_LIT_ARGS="${2}"
61 shift; shift
62 ;;
63 --no-cleanup)
64 NO_CLEANUP=""
65 shift
66 ;;
67 -h|--help)
68 usage
69 exit 0
70 ;;
71 *)
72 echo "${1} is not a supported argument"
73 usage
74 exit 1
75 ;;
76 esac
77done
78
79if [[ -z ${LIBCXX_ROOT+x} ]]; then echo "--libcxx-root is a required parameter"; usage; exit 1; fi
80if [[ -z ${LIBCXXABI_ROOT+x} ]]; then echo "--libcxxabi-root is a required parameter"; usage; exit 1; fi
81if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi
82if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi
Louis Dionnea3ec6272019-02-05 16:42:37 +000083if [[ "${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 Dionne3b1ef582019-07-19 18:47:00 +000084if [[ -z ${ADDITIONAL_CMAKE_ARGS+x} ]]; then ADDITIONAL_CMAKE_ARGS=""; fi
Louis Dionnecb4e59e2019-01-09 16:35:55 +000085if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi
86
87
88TEMP_DIR="$(mktemp -d)"
89echo "Created temporary directory ${TEMP_DIR}"
90function cleanup {
91 if [[ -z ${NO_CLEANUP+x} ]]; then
92 echo "Removing temporary directory ${TEMP_DIR}"
93 rm -rf "${TEMP_DIR}"
94 else
95 echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself"
96 fi
97}
98trap cleanup EXIT
99
100
101LLVM_ROOT="${TEMP_DIR}/llvm"
102LIBCXX_BUILD_DIR="${TEMP_DIR}/libcxx-build"
103LIBCXX_INSTALL_DIR="${TEMP_DIR}/libcxx-install"
104LIBCXXABI_BUILD_DIR="${TEMP_DIR}/libcxxabi-build"
105LIBCXXABI_INSTALL_DIR="${TEMP_DIR}/libcxxabi-install"
106
Louis Dionnecb4e59e2019-01-09 16:35:55 +0000107
108echo "@@@ Downloading LLVM tarball of master (only used for CMake configuration) @@@"
109mkdir "${LLVM_ROOT}"
Louis Dionnee526a6b2019-03-20 15:40:56 +0000110LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz"
Louis Dionnecb4e59e2019-01-09 16:35:55 +0000111curl -L "${LLVM_TARBALL_URL}" | tar -xz --strip-components=1 -C "${LLVM_ROOT}"
112echo "@@@@@@"
113
114
115echo "@@@ Setting up LIT flags @@@"
116LIT_FLAGS="-sv --param=std=${STD} ${ADDITIONAL_LIT_ARGS}"
117if [[ "${ARCH}" == "32" ]]; then
118 LIT_FLAGS+=" --param=enable_32bit=true"
119fi
120echo "@@@@@@"
121
122
123echo "@@@ Configuring CMake for libc++ @@@"
124mkdir -p "${LIBCXX_BUILD_DIR}"
125(cd "${LIBCXX_BUILD_DIR}" &&
126 xcrun cmake "${LIBCXX_ROOT}" -GNinja \
127 -DLLVM_PATH="${LLVM_ROOT}" \
128 -DCMAKE_INSTALL_PREFIX="${LIBCXX_INSTALL_DIR}" \
Louis Dionnea3ec6272019-02-05 16:42:37 +0000129 -DLIBCXX_ENABLE_EXCEPTIONS="${LIBCXX_EXCEPTIONS}" \
Louis Dionne4b9c19e2019-04-16 20:46:03 +0000130 -DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=OFF \
Louis Dionne3b1ef582019-07-19 18:47:00 +0000131 ${ADDITIONAL_CMAKE_ARGS} \
Louis Dionnecb4e59e2019-01-09 16:35:55 +0000132 -DLLVM_LIT_ARGS="${LIT_FLAGS}" \
133 -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib
134)
135echo "@@@@@@"
136
137
138echo "@@@ Configuring CMake for libc++abi @@@"
139mkdir -p "${LIBCXXABI_BUILD_DIR}"
140(cd "${LIBCXXABI_BUILD_DIR}" &&
141 xcrun cmake "${LIBCXXABI_ROOT}" -GNinja \
142 -DLIBCXXABI_LIBCXX_PATH="${LIBCXX_ROOT}" \
143 -DLLVM_PATH="${LLVM_ROOT}" \
144 -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_INSTALL_DIR}" \
Louis Dionnea3ec6272019-02-05 16:42:37 +0000145 -DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
Louis Dionne4b9c19e2019-04-16 20:46:03 +0000146 -DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=ON \
Louis Dionne3b1ef582019-07-19 18:47:00 +0000147 ${ADDITIONAL_CMAKE_ARGS} \
Louis Dionnecb4e59e2019-01-09 16:35:55 +0000148 -DLLVM_LIT_ARGS="${LIT_FLAGS}" \
149 -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib
150)
151echo "@@@@@@"
152
153
154echo "@@@ Building libc++.dylib and libc++abi.dylib from sources (just to make sure it works) @@@"
Louis Dionne4eff3de2019-04-16 21:16:58 +0000155ninja -C "${LIBCXX_BUILD_DIR}" install-cxx -v
156ninja -C "${LIBCXXABI_BUILD_DIR}" install-cxxabi -v
Louis Dionnecb4e59e2019-01-09 16:35:55 +0000157echo "@@@@@@"
158
159
160echo "@@@ Running tests for libc++ @@@"
161# TODO: We should run check-cxx-abilist too
162ninja -C "${LIBCXX_BUILD_DIR}" check-cxx
163echo "@@@@@@"
164
165
166echo "@@@ Running tests for libc++abi @@@"
167ninja -C "${LIBCXXABI_BUILD_DIR}" check-cxxabi
168echo "@@@@@@"