| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -ue |
| 4 | |
| 5 | function 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 | |
| 9 | This script is used to continually test libc++ and libc++abi trunk on MacOS. |
| 10 | |
| Louis Dionne | a3ec627 | 2019-02-05 16:42:37 +0000 | [diff] [blame] | 11 | --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 Dionne | 3b1ef58 | 2019-07-19 18:47:00 +0000 | [diff] [blame^] | 16 | [--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 Dionne | a3ec627 | 2019-02-05 16:42:37 +0000 | [diff] [blame] | 18 | [--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 Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 20 | EOM |
| 21 | } |
| 22 | |
| 23 | while [[ $# -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 Dionne | a3ec627 | 2019-02-05 16:42:37 +0000 | [diff] [blame] | 51 | --libcxx-exceptions) |
| 52 | LIBCXX_EXCEPTIONS="${2}" |
| 53 | shift; shift |
| 54 | ;; |
| Louis Dionne | 3b1ef58 | 2019-07-19 18:47:00 +0000 | [diff] [blame^] | 55 | --cmake-args) |
| 56 | ADDITIONAL_CMAKE_ARGS="${2}" |
| 57 | shift; shift |
| 58 | ;; |
| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 59 | --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 |
| 77 | done |
| 78 | |
| 79 | if [[ -z ${LIBCXX_ROOT+x} ]]; then echo "--libcxx-root is a required parameter"; usage; exit 1; fi |
| 80 | if [[ -z ${LIBCXXABI_ROOT+x} ]]; then echo "--libcxxabi-root is a required parameter"; usage; exit 1; fi |
| 81 | if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi |
| 82 | if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi |
| Louis Dionne | a3ec627 | 2019-02-05 16:42:37 +0000 | [diff] [blame] | 83 | if [[ "${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 Dionne | 3b1ef58 | 2019-07-19 18:47:00 +0000 | [diff] [blame^] | 84 | if [[ -z ${ADDITIONAL_CMAKE_ARGS+x} ]]; then ADDITIONAL_CMAKE_ARGS=""; fi |
| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 85 | if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi |
| 86 | |
| 87 | |
| 88 | TEMP_DIR="$(mktemp -d)" |
| 89 | echo "Created temporary directory ${TEMP_DIR}" |
| 90 | function 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 | } |
| 98 | trap cleanup EXIT |
| 99 | |
| 100 | |
| 101 | LLVM_ROOT="${TEMP_DIR}/llvm" |
| 102 | LIBCXX_BUILD_DIR="${TEMP_DIR}/libcxx-build" |
| 103 | LIBCXX_INSTALL_DIR="${TEMP_DIR}/libcxx-install" |
| 104 | LIBCXXABI_BUILD_DIR="${TEMP_DIR}/libcxxabi-build" |
| 105 | LIBCXXABI_INSTALL_DIR="${TEMP_DIR}/libcxxabi-install" |
| 106 | |
| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 107 | |
| 108 | echo "@@@ Downloading LLVM tarball of master (only used for CMake configuration) @@@" |
| 109 | mkdir "${LLVM_ROOT}" |
| Louis Dionne | e526a6b | 2019-03-20 15:40:56 +0000 | [diff] [blame] | 110 | LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz" |
| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 111 | curl -L "${LLVM_TARBALL_URL}" | tar -xz --strip-components=1 -C "${LLVM_ROOT}" |
| 112 | echo "@@@@@@" |
| 113 | |
| 114 | |
| 115 | echo "@@@ Setting up LIT flags @@@" |
| 116 | LIT_FLAGS="-sv --param=std=${STD} ${ADDITIONAL_LIT_ARGS}" |
| 117 | if [[ "${ARCH}" == "32" ]]; then |
| 118 | LIT_FLAGS+=" --param=enable_32bit=true" |
| 119 | fi |
| 120 | echo "@@@@@@" |
| 121 | |
| 122 | |
| 123 | echo "@@@ Configuring CMake for libc++ @@@" |
| 124 | mkdir -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 Dionne | a3ec627 | 2019-02-05 16:42:37 +0000 | [diff] [blame] | 129 | -DLIBCXX_ENABLE_EXCEPTIONS="${LIBCXX_EXCEPTIONS}" \ |
| Louis Dionne | 4b9c19e | 2019-04-16 20:46:03 +0000 | [diff] [blame] | 130 | -DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=OFF \ |
| Louis Dionne | 3b1ef58 | 2019-07-19 18:47:00 +0000 | [diff] [blame^] | 131 | ${ADDITIONAL_CMAKE_ARGS} \ |
| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 132 | -DLLVM_LIT_ARGS="${LIT_FLAGS}" \ |
| 133 | -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib |
| 134 | ) |
| 135 | echo "@@@@@@" |
| 136 | |
| 137 | |
| 138 | echo "@@@ Configuring CMake for libc++abi @@@" |
| 139 | mkdir -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 Dionne | a3ec627 | 2019-02-05 16:42:37 +0000 | [diff] [blame] | 145 | -DLIBCXXABI_ENABLE_EXCEPTIONS=ON \ |
| Louis Dionne | 4b9c19e | 2019-04-16 20:46:03 +0000 | [diff] [blame] | 146 | -DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=ON \ |
| Louis Dionne | 3b1ef58 | 2019-07-19 18:47:00 +0000 | [diff] [blame^] | 147 | ${ADDITIONAL_CMAKE_ARGS} \ |
| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 148 | -DLLVM_LIT_ARGS="${LIT_FLAGS}" \ |
| 149 | -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib |
| 150 | ) |
| 151 | echo "@@@@@@" |
| 152 | |
| 153 | |
| 154 | echo "@@@ Building libc++.dylib and libc++abi.dylib from sources (just to make sure it works) @@@" |
| Louis Dionne | 4eff3de | 2019-04-16 21:16:58 +0000 | [diff] [blame] | 155 | ninja -C "${LIBCXX_BUILD_DIR}" install-cxx -v |
| 156 | ninja -C "${LIBCXXABI_BUILD_DIR}" install-cxxabi -v |
| Louis Dionne | cb4e59e | 2019-01-09 16:35:55 +0000 | [diff] [blame] | 157 | echo "@@@@@@" |
| 158 | |
| 159 | |
| 160 | echo "@@@ Running tests for libc++ @@@" |
| 161 | # TODO: We should run check-cxx-abilist too |
| 162 | ninja -C "${LIBCXX_BUILD_DIR}" check-cxx |
| 163 | echo "@@@@@@" |
| 164 | |
| 165 | |
| 166 | echo "@@@ Running tests for libc++abi @@@" |
| 167 | ninja -C "${LIBCXXABI_BUILD_DIR}" check-cxxabi |
| 168 | echo "@@@@@@" |