Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -ue |
| 4 | |
| 5 | function usage() { |
| 6 | cat <<EOM |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 7 | $(basename ${0}) [-h|--help] --monorepo-root <MONOREPO-ROOT> --std <STD> --arch <ARCHITECTURE> --deployment-target <TARGET> --sdk-version <SDK-VERSION> [--lit-args <ARGS...>] |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 8 | |
| 9 | This script is used to continually test the back-deployment use case of libc++ and libc++abi on MacOS. |
| 10 | |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 11 | --monorepo-root Full path to the root of the LLVM monorepo. Both libc++ and libc++abi headers from the monorepo are used. |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 12 | --std Version of the C++ Standard to run the tests under (c++03, c++11, etc..). |
| 13 | --arch Architecture to build the tests for (32, 64). |
Louis Dionne | 4fcdf21 | 2019-02-27 23:36:22 +0000 | [diff] [blame] | 14 | --deployment-target The deployment target to run the tests for. This should be a version number of MacOS (e.g. 10.12). All MacOS versions until and including 10.9 are supported. |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 15 | --sdk-version The version of the SDK to test with. This should be a version number of MacOS (e.g. 10.12). We'll link against the libc++ dylib in that SDK, but we'll run against the one on the given deployment target. |
| 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. |
| 19 | EOM |
| 20 | } |
| 21 | |
| 22 | while [[ $# -gt 0 ]]; do |
| 23 | case "$1" in |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 24 | --monorepo-root) |
| 25 | MONOREPO_ROOT="${2}" |
| 26 | if [[ ! -d "${MONOREPO_ROOT}" ]]; then |
| 27 | echo "--monorepo-root '${MONOREPO_ROOT}' is not a valid directory" |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 28 | usage |
| 29 | exit 1 |
| 30 | fi |
| 31 | shift; shift |
| 32 | ;; |
| 33 | --std) |
| 34 | STD="${2}" |
| 35 | shift; shift |
| 36 | ;; |
| 37 | --arch) |
| 38 | ARCH="${2}" |
| 39 | shift; shift |
| 40 | ;; |
| 41 | --deployment-target) |
| 42 | DEPLOYMENT_TARGET="${2}" |
| 43 | shift; shift |
| 44 | ;; |
| 45 | --sdk-version) |
| 46 | MACOS_SDK_VERSION="${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 | |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 69 | if [[ -z ${MONOREPO_ROOT+x} ]]; then echo "--monorepo-root is a required parameter"; usage; exit 1; fi |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 70 | if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi |
| 71 | if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi |
| 72 | if [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi |
| 73 | if [[ -z ${MACOS_SDK_VERSION+x} ]]; then echo "--sdk-version is a required parameter"; usage; exit 1; fi |
| 74 | if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi |
| 75 | |
| 76 | |
| 77 | TEMP_DIR="$(mktemp -d)" |
| 78 | echo "Created temporary directory ${TEMP_DIR}" |
| 79 | function cleanup { |
| 80 | if [[ -z ${NO_CLEANUP+x} ]]; then |
| 81 | echo "Removing temporary directory ${TEMP_DIR}" |
| 82 | rm -rf "${TEMP_DIR}" |
| 83 | else |
| 84 | echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself" |
| 85 | fi |
| 86 | } |
| 87 | trap cleanup EXIT |
| 88 | |
| 89 | |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 90 | LLVM_BUILD_DIR="${TEMP_DIR}/llvm-build" |
| 91 | LLVM_INSTALL_DIR="${TEMP_DIR}/llvm-install" |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 92 | |
| 93 | PREVIOUS_DYLIBS_URL="http://lab.llvm.org:8080/roots/libcxx-roots.tar.gz" |
| 94 | LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz" |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 95 | |
| 96 | |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 97 | echo "@@@ Configuring architecture-related stuff @@@" |
| 98 | if [[ "${ARCH}" == "64" ]]; then CMAKE_ARCH_STRING="x86_64"; else CMAKE_ARCH_STRING="i386"; fi |
| 99 | if [[ "${ARCH}" == "64" ]]; then LIT_ARCH_STRING=""; else LIT_ARCH_STRING="--param=enable_32bit=true"; fi |
| 100 | echo "@@@@@@" |
| 101 | |
| 102 | |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 103 | echo "@@@ Configuring CMake @@@" |
| 104 | mkdir -p "${LLVM_BUILD_DIR}" |
| 105 | (cd "${LLVM_BUILD_DIR}" && |
| 106 | xcrun cmake "${MONOREPO_ROOT}/llvm" -GNinja \ |
| 107 | -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}" \ |
| 108 | -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \ |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 109 | -DCMAKE_OSX_ARCHITECTURES="${CMAKE_ARCH_STRING}" |
| 110 | ) |
| 111 | echo "@@@@@@" |
| 112 | |
| 113 | |
| 114 | echo "@@@ Installing the latest libc++ headers @@@" |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 115 | ninja -C "${LLVM_BUILD_DIR}" install-cxx-headers |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 116 | echo "@@@@@@" |
| 117 | |
| 118 | |
| 119 | echo "@@@ Downloading dylibs for older deployment targets @@@" |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 120 | # TODO: We should also link against the libc++abi.dylib that was shipped in the SDK |
| 121 | PREVIOUS_DYLIBS_DIR="${TEMP_DIR}/libcxx-dylibs" |
| 122 | mkdir "${PREVIOUS_DYLIBS_DIR}" |
| 123 | curl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${PREVIOUS_DYLIBS_DIR}" |
| 124 | LIBCXX_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/${DEPLOYMENT_TARGET}/libc++.dylib" |
Louis Dionne | e4d6ac5 | 2019-04-12 16:58:25 +0000 | [diff] [blame] | 125 | LIBCXXABI_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/${DEPLOYMENT_TARGET}/libc++abi.dylib" |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 126 | LIBCXX_IN_SDK="${PREVIOUS_DYLIBS_DIR}/macOS/${MACOS_SDK_VERSION}/libc++.dylib" |
| 127 | echo "@@@@@@" |
| 128 | |
| 129 | |
| 130 | # TODO: We need to also run the tests for libc++abi. |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 131 | echo "@@@ Running tests for libc++ @@@" |
Louis Dionne | 53e9c2d | 2019-08-06 20:01:28 +0000 | [diff] [blame^] | 132 | "${LLVM_BUILD_DIR}/bin/llvm-lit" -sv "${MONOREPO_ROOT}/libcxx/test" \ |
| 133 | --param=enable_experimental=false \ |
| 134 | ${LIT_ARCH_STRING} \ |
| 135 | --param=cxx_headers="${LLVM_INSTALL_DIR}/include/c++/v1" \ |
| 136 | --param=std="${STD}" \ |
| 137 | --param=platform="macosx${DEPLOYMENT_TARGET}" \ |
| 138 | --param=cxx_runtime_root="$(dirname "${LIBCXX_ON_DEPLOYMENT_TARGET}")" \ |
| 139 | --param=abi_library_path="$(dirname "${LIBCXXABI_ON_DEPLOYMENT_TARGET}")" \ |
| 140 | --param=use_system_cxx_lib="$(dirname "${LIBCXX_IN_SDK}")" \ |
| 141 | ${ADDITIONAL_LIT_ARGS} |
Louis Dionne | 227371d | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 142 | echo "@@@@@@" |