Louis Dionne | cbc6667 | 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 | 74953e1 | 2020-04-30 12:55:01 -0400 | [diff] [blame] | 7 | $(basename ${0}) [-h|--help] --monorepo-root <MONOREPO-ROOT> --std <STD> --deployment-target <TARGET> --sdk-version <SDK-VERSION> [--libcxx-roots <DIR>] [--lit-args <ARGS...>] [--no-cleanup] |
Louis Dionne | cbc6667 | 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 | 293573d | 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 | cbc6667 | 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..). |
Louis Dionne | 9b55784 | 2019-02-27 23:36:22 +0000 | [diff] [blame] | 13 | --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 | bc3500d | 2020-02-11 13:50:38 +0100 | [diff] [blame] | 14 | --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. The SDK version must be no older than the deployment target. |
Louis Dionne | 3e2f88d | 2020-04-14 15:07:38 -0400 | [diff] [blame] | 15 | [--libcxx-roots] The path to previous libc++/libc++abi dylibs to use for back-deployment testing. Those are normally downloaded automatically, but if specified, this option will override the directory used. The directory should have the same layout as the roots downloaded automatically. |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 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 | |
Louis Dionne | bc3500d | 2020-02-11 13:50:38 +0100 | [diff] [blame] | 22 | function version-less-equal() { |
| 23 | [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] |
| 24 | } |
| 25 | |
| 26 | function version-less() { |
| 27 | [ "$1" = "$2" ] && return 1 || version-less-equal $1 $2 |
| 28 | } |
| 29 | |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 30 | while [[ $# -gt 0 ]]; do |
| 31 | case "$1" in |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 32 | --monorepo-root) |
| 33 | MONOREPO_ROOT="${2}" |
| 34 | if [[ ! -d "${MONOREPO_ROOT}" ]]; then |
| 35 | echo "--monorepo-root '${MONOREPO_ROOT}' is not a valid directory" |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 36 | usage |
| 37 | exit 1 |
| 38 | fi |
| 39 | shift; shift |
| 40 | ;; |
| 41 | --std) |
| 42 | STD="${2}" |
| 43 | shift; shift |
| 44 | ;; |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 45 | --deployment-target) |
| 46 | DEPLOYMENT_TARGET="${2}" |
| 47 | shift; shift |
| 48 | ;; |
| 49 | --sdk-version) |
| 50 | MACOS_SDK_VERSION="${2}" |
| 51 | shift; shift |
| 52 | ;; |
| 53 | --lit-args) |
| 54 | ADDITIONAL_LIT_ARGS="${2}" |
| 55 | shift; shift |
| 56 | ;; |
Louis Dionne | 3e2f88d | 2020-04-14 15:07:38 -0400 | [diff] [blame] | 57 | --libcxx-roots) |
| 58 | PREVIOUS_DYLIBS_DIR="${2}" |
| 59 | shift; shift |
| 60 | ;; |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 61 | --no-cleanup) |
| 62 | NO_CLEANUP="" |
| 63 | shift |
| 64 | ;; |
| 65 | -h|--help) |
| 66 | usage |
| 67 | exit 0 |
| 68 | ;; |
| 69 | *) |
| 70 | echo "${1} is not a supported argument" |
| 71 | usage |
| 72 | exit 1 |
| 73 | ;; |
| 74 | esac |
| 75 | done |
| 76 | |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 77 | if [[ -z ${MONOREPO_ROOT+x} ]]; then echo "--monorepo-root is a required parameter"; usage; exit 1; fi |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 78 | if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 79 | if [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi |
| 80 | if [[ -z ${MACOS_SDK_VERSION+x} ]]; then echo "--sdk-version is a required parameter"; usage; exit 1; fi |
| 81 | if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi |
Louis Dionne | 3e2f88d | 2020-04-14 15:07:38 -0400 | [diff] [blame] | 82 | if [[ -z ${PREVIOUS_DYLIBS_DIR+x} ]]; then PREVIOUS_DYLIBS_DIR=""; fi |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 83 | |
Louis Dionne | bc3500d | 2020-02-11 13:50:38 +0100 | [diff] [blame] | 84 | if version-less "${MACOS_SDK_VERSION}" "${DEPLOYMENT_TARGET}"; then |
| 85 | echo "SDK version ${MACOS_SDK_VERSION} shouldn't be older than the deployment target (${DEPLOYMENT_TARGET})" |
| 86 | usage |
| 87 | exit 1 |
| 88 | fi |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 89 | |
| 90 | TEMP_DIR="$(mktemp -d)" |
| 91 | echo "Created temporary directory ${TEMP_DIR}" |
| 92 | function cleanup { |
| 93 | if [[ -z ${NO_CLEANUP+x} ]]; then |
| 94 | echo "Removing temporary directory ${TEMP_DIR}" |
| 95 | rm -rf "${TEMP_DIR}" |
| 96 | else |
| 97 | echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself" |
| 98 | fi |
| 99 | } |
| 100 | trap cleanup EXIT |
| 101 | |
| 102 | |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 103 | LLVM_BUILD_DIR="${TEMP_DIR}/llvm-build" |
| 104 | LLVM_INSTALL_DIR="${TEMP_DIR}/llvm-install" |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 105 | |
| 106 | PREVIOUS_DYLIBS_URL="http://lab.llvm.org:8080/roots/libcxx-roots.tar.gz" |
| 107 | LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz" |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 108 | |
| 109 | |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 110 | echo "@@@ Configuring CMake @@@" |
| 111 | mkdir -p "${LLVM_BUILD_DIR}" |
| 112 | (cd "${LLVM_BUILD_DIR}" && |
Louis Dionne | 747d311 | 2019-09-11 16:57:19 +0000 | [diff] [blame] | 113 | xcrun cmake \ |
| 114 | -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Apple.cmake" \ |
| 115 | -GNinja \ |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 116 | -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}" \ |
| 117 | -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \ |
Louis Dionne | 74953e1 | 2020-04-30 12:55:01 -0400 | [diff] [blame] | 118 | -DCMAKE_OSX_ARCHITECTURES="x86_64" \ |
Louis Dionne | 747d311 | 2019-09-11 16:57:19 +0000 | [diff] [blame] | 119 | "${MONOREPO_ROOT}/llvm" |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 120 | ) |
| 121 | echo "@@@@@@" |
| 122 | |
| 123 | |
| 124 | echo "@@@ Installing the latest libc++ headers @@@" |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 125 | ninja -C "${LLVM_BUILD_DIR}" install-cxx-headers |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 126 | echo "@@@@@@" |
| 127 | |
| 128 | |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 129 | # TODO: We should also link against the libc++abi.dylib that was shipped in the SDK |
Louis Dionne | 3e2f88d | 2020-04-14 15:07:38 -0400 | [diff] [blame] | 130 | if [[ ${PREVIOUS_DYLIBS_DIR} == "" ]]; then |
| 131 | echo "@@@ Downloading dylibs for older deployment targets @@@" |
| 132 | PREVIOUS_DYLIBS_DIR="${TEMP_DIR}/libcxx-dylibs" |
| 133 | mkdir "${PREVIOUS_DYLIBS_DIR}" |
| 134 | curl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${PREVIOUS_DYLIBS_DIR}" |
| 135 | echo "@@@@@@" |
| 136 | fi |
| 137 | |
Louis Dionne | 83c20b3 | 2020-05-15 12:13:48 -0400 | [diff] [blame^] | 138 | LIBCXX_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${DEPLOYMENT_TARGET}" |
| 139 | LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++abi/${DEPLOYMENT_TARGET}" |
| 140 | LIBCXX_ROOT_IN_SDK="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${MACOS_SDK_VERSION}" |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 141 | |
| 142 | # TODO: We need to also run the tests for libc++abi. |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 143 | echo "@@@ Running tests for libc++ @@@" |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 144 | "${LLVM_BUILD_DIR}/bin/llvm-lit" -sv "${MONOREPO_ROOT}/libcxx/test" \ |
| 145 | --param=enable_experimental=false \ |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 146 | --param=cxx_headers="${LLVM_INSTALL_DIR}/include/c++/v1" \ |
| 147 | --param=std="${STD}" \ |
| 148 | --param=platform="macosx${DEPLOYMENT_TARGET}" \ |
Louis Dionne | 83c20b3 | 2020-05-15 12:13:48 -0400 | [diff] [blame^] | 149 | --param=cxx_runtime_root="${LIBCXX_ROOT_ON_DEPLOYMENT_TARGET}" \ |
| 150 | --param=abi_library_path="${LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET}" \ |
| 151 | --param=use_system_cxx_lib="${LIBCXX_ROOT_IN_SDK}" \ |
Louis Dionne | 293573d | 2019-08-06 20:01:28 +0000 | [diff] [blame] | 152 | ${ADDITIONAL_LIT_ARGS} |
Louis Dionne | cbc6667 | 2019-01-09 19:40:20 +0000 | [diff] [blame] | 153 | echo "@@@@@@" |