Louis Dionne | 504008e | 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 | |
| 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 | [--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. |
| 16 | [--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. |
| 17 | [-h, --help] Print this help. |
| 18 | EOM |
| 19 | } |
| 20 | |
| 21 | while [[ $# -gt 0 ]]; do |
| 22 | case "$1" in |
| 23 | --libcxx-root) |
| 24 | LIBCXX_ROOT="${2}" |
| 25 | if [[ ! -e "${LIBCXX_ROOT}" ]]; then |
| 26 | echo "--libcxx-root '${LIBCXX_ROOT}' is not a valid directory" |
| 27 | usage |
| 28 | exit 1 |
| 29 | fi |
| 30 | shift; shift |
| 31 | ;; |
| 32 | --libcxxabi-root) |
| 33 | LIBCXXABI_ROOT="${2}" |
| 34 | if [[ ! -e "${LIBCXXABI_ROOT}" ]]; then |
| 35 | echo "--libcxxabi-root '${LIBCXXABI_ROOT}' is not a valid directory" |
| 36 | usage |
| 37 | exit 1 |
| 38 | fi |
| 39 | shift; shift |
| 40 | ;; |
| 41 | --std) |
| 42 | STD="${2}" |
| 43 | shift; shift |
| 44 | ;; |
| 45 | --arch) |
| 46 | ARCH="${2}" |
| 47 | shift; shift |
| 48 | ;; |
| 49 | --lit-args) |
| 50 | ADDITIONAL_LIT_ARGS="${2}" |
| 51 | shift; shift |
| 52 | ;; |
| 53 | --no-cleanup) |
| 54 | NO_CLEANUP="" |
| 55 | shift |
| 56 | ;; |
| 57 | -h|--help) |
| 58 | usage |
| 59 | exit 0 |
| 60 | ;; |
| 61 | *) |
| 62 | echo "${1} is not a supported argument" |
| 63 | usage |
| 64 | exit 1 |
| 65 | ;; |
| 66 | esac |
| 67 | done |
| 68 | |
| 69 | if [[ -z ${LIBCXX_ROOT+x} ]]; then echo "--libcxx-root is a required parameter"; usage; exit 1; fi |
| 70 | if [[ -z ${LIBCXXABI_ROOT+x} ]]; then echo "--libcxxabi-root is a required parameter"; usage; exit 1; fi |
| 71 | if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi |
| 72 | if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi |
| 73 | if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi |
| 74 | |
| 75 | |
| 76 | TEMP_DIR="$(mktemp -d)" |
| 77 | echo "Created temporary directory ${TEMP_DIR}" |
| 78 | function cleanup { |
| 79 | if [[ -z ${NO_CLEANUP+x} ]]; then |
| 80 | echo "Removing temporary directory ${TEMP_DIR}" |
| 81 | rm -rf "${TEMP_DIR}" |
| 82 | else |
| 83 | echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself" |
| 84 | fi |
| 85 | } |
| 86 | trap cleanup EXIT |
| 87 | |
| 88 | |
| 89 | LLVM_ROOT="${TEMP_DIR}/llvm" |
| 90 | LIBCXX_BUILD_DIR="${TEMP_DIR}/libcxx-build" |
| 91 | LIBCXX_INSTALL_DIR="${TEMP_DIR}/libcxx-install" |
| 92 | LIBCXXABI_BUILD_DIR="${TEMP_DIR}/libcxxabi-build" |
| 93 | LIBCXXABI_INSTALL_DIR="${TEMP_DIR}/libcxxabi-install" |
| 94 | |
| 95 | LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz" |
| 96 | export CC="$(xcrun --find clang)" |
| 97 | export CXX="$(xcrun --find clang++)" |
| 98 | |
| 99 | |
| 100 | echo "@@@ Downloading LLVM tarball of master (only used for CMake configuration) @@@" |
| 101 | mkdir "${LLVM_ROOT}" |
| 102 | curl -L "${LLVM_TARBALL_URL}" | tar -xz --strip-components=1 -C "${LLVM_ROOT}" |
| 103 | echo "@@@@@@" |
| 104 | |
| 105 | |
| 106 | echo "@@@ Setting up LIT flags @@@" |
| 107 | LIT_FLAGS="-sv --param=std=${STD} ${ADDITIONAL_LIT_ARGS}" |
| 108 | if [[ "${ARCH}" == "32" ]]; then |
| 109 | LIT_FLAGS+=" --param=enable_32bit=true" |
| 110 | fi |
| 111 | echo "@@@@@@" |
| 112 | |
| 113 | |
| 114 | echo "@@@ Configuring CMake for libc++ @@@" |
| 115 | mkdir -p "${LIBCXX_BUILD_DIR}" |
| 116 | (cd "${LIBCXX_BUILD_DIR}" && |
| 117 | xcrun cmake "${LIBCXX_ROOT}" -GNinja \ |
| 118 | -DLLVM_PATH="${LLVM_ROOT}" \ |
| 119 | -DCMAKE_INSTALL_PREFIX="${LIBCXX_INSTALL_DIR}" \ |
| 120 | -DLLVM_LIT_ARGS="${LIT_FLAGS}" \ |
| 121 | -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib |
| 122 | ) |
| 123 | echo "@@@@@@" |
| 124 | |
| 125 | |
| 126 | echo "@@@ Configuring CMake for libc++abi @@@" |
| 127 | mkdir -p "${LIBCXXABI_BUILD_DIR}" |
| 128 | (cd "${LIBCXXABI_BUILD_DIR}" && |
| 129 | xcrun cmake "${LIBCXXABI_ROOT}" -GNinja \ |
| 130 | -DLIBCXXABI_LIBCXX_PATH="${LIBCXX_ROOT}" \ |
| 131 | -DLLVM_PATH="${LLVM_ROOT}" \ |
| 132 | -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_INSTALL_DIR}" \ |
| 133 | -DLLVM_LIT_ARGS="${LIT_FLAGS}" \ |
| 134 | -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib |
| 135 | ) |
| 136 | echo "@@@@@@" |
| 137 | |
| 138 | |
| 139 | echo "@@@ Building libc++.dylib and libc++abi.dylib from sources (just to make sure it works) @@@" |
| 140 | ninja -C "${LIBCXX_BUILD_DIR}" install-cxx |
| 141 | ninja -C "${LIBCXXABI_BUILD_DIR}" install-cxxabi |
| 142 | echo "@@@@@@" |
| 143 | |
| 144 | |
| 145 | echo "@@@ Running tests for libc++ @@@" |
| 146 | # TODO: We should run check-cxx-abilist too |
| 147 | ninja -C "${LIBCXX_BUILD_DIR}" check-cxx |
| 148 | echo "@@@@@@" |
| 149 | |
| 150 | |
| 151 | echo "@@@ Running tests for libc++abi @@@" |
| 152 | ninja -C "${LIBCXXABI_BUILD_DIR}" check-cxxabi |
| 153 | echo "@@@@@@" |