blob: 8767f4b8fe9c11a2d099db8c444837a936d3ff04 [file] [log] [blame]
Louis Dionnecbc66672019-01-09 19:40:20 +00001#!/usr/bin/env bash
2
3set -ue
4
5function usage() {
6 cat <<EOM
Louis Dionne74953e12020-04-30 12:55:01 -04007$(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 Dionnecbc66672019-01-09 19:40:20 +00008
9This script is used to continually test the back-deployment use case of libc++ and libc++abi on MacOS.
10
Louis Dionne293573d2019-08-06 20:01:28 +000011 --monorepo-root Full path to the root of the LLVM monorepo. Both libc++ and libc++abi headers from the monorepo are used.
Louis Dionnecbc66672019-01-09 19:40:20 +000012 --std Version of the C++ Standard to run the tests under (c++03, c++11, etc..).
Louis Dionne9b557842019-02-27 23:36:22 +000013 --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 Dionnebc3500d2020-02-11 13:50:38 +010014 --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 Dionne3e2f88d2020-04-14 15:07:38 -040015 [--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 Dionnecbc66672019-01-09 19:40:20 +000016 [--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.
19EOM
20}
21
Louis Dionnebc3500d2020-02-11 13:50:38 +010022function version-less-equal() {
23 [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
24}
25
26function version-less() {
27 [ "$1" = "$2" ] && return 1 || version-less-equal $1 $2
28}
29
Louis Dionnecbc66672019-01-09 19:40:20 +000030while [[ $# -gt 0 ]]; do
31 case "$1" in
Louis Dionne293573d2019-08-06 20:01:28 +000032 --monorepo-root)
33 MONOREPO_ROOT="${2}"
34 if [[ ! -d "${MONOREPO_ROOT}" ]]; then
35 echo "--monorepo-root '${MONOREPO_ROOT}' is not a valid directory"
Louis Dionnecbc66672019-01-09 19:40:20 +000036 usage
37 exit 1
38 fi
39 shift; shift
40 ;;
41 --std)
42 STD="${2}"
43 shift; shift
44 ;;
Louis Dionnecbc66672019-01-09 19:40:20 +000045 --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 Dionne3e2f88d2020-04-14 15:07:38 -040057 --libcxx-roots)
58 PREVIOUS_DYLIBS_DIR="${2}"
59 shift; shift
60 ;;
Louis Dionnecbc66672019-01-09 19:40:20 +000061 --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
75done
76
Louis Dionne293573d2019-08-06 20:01:28 +000077if [[ -z ${MONOREPO_ROOT+x} ]]; then echo "--monorepo-root is a required parameter"; usage; exit 1; fi
Louis Dionnecbc66672019-01-09 19:40:20 +000078if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi
Louis Dionnecbc66672019-01-09 19:40:20 +000079if [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi
80if [[ -z ${MACOS_SDK_VERSION+x} ]]; then echo "--sdk-version is a required parameter"; usage; exit 1; fi
81if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi
Louis Dionne3e2f88d2020-04-14 15:07:38 -040082if [[ -z ${PREVIOUS_DYLIBS_DIR+x} ]]; then PREVIOUS_DYLIBS_DIR=""; fi
Louis Dionnecbc66672019-01-09 19:40:20 +000083
Louis Dionnebc3500d2020-02-11 13:50:38 +010084if 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
88fi
Louis Dionnecbc66672019-01-09 19:40:20 +000089
90TEMP_DIR="$(mktemp -d)"
91echo "Created temporary directory ${TEMP_DIR}"
92function 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}
100trap cleanup EXIT
101
102
Louis Dionne293573d2019-08-06 20:01:28 +0000103LLVM_BUILD_DIR="${TEMP_DIR}/llvm-build"
104LLVM_INSTALL_DIR="${TEMP_DIR}/llvm-install"
Louis Dionnecbc66672019-01-09 19:40:20 +0000105
106PREVIOUS_DYLIBS_URL="http://lab.llvm.org:8080/roots/libcxx-roots.tar.gz"
107LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz"
Louis Dionnecbc66672019-01-09 19:40:20 +0000108
109
Louis Dionne293573d2019-08-06 20:01:28 +0000110echo "@@@ Configuring CMake @@@"
111mkdir -p "${LLVM_BUILD_DIR}"
112(cd "${LLVM_BUILD_DIR}" &&
Louis Dionne747d3112019-09-11 16:57:19 +0000113 xcrun cmake \
114 -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Apple.cmake" \
115 -GNinja \
Louis Dionne293573d2019-08-06 20:01:28 +0000116 -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}" \
117 -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
Louis Dionne74953e12020-04-30 12:55:01 -0400118 -DCMAKE_OSX_ARCHITECTURES="x86_64" \
Louis Dionne747d3112019-09-11 16:57:19 +0000119 "${MONOREPO_ROOT}/llvm"
Louis Dionnecbc66672019-01-09 19:40:20 +0000120)
121echo "@@@@@@"
122
123
124echo "@@@ Installing the latest libc++ headers @@@"
Louis Dionne293573d2019-08-06 20:01:28 +0000125ninja -C "${LLVM_BUILD_DIR}" install-cxx-headers
Louis Dionnecbc66672019-01-09 19:40:20 +0000126echo "@@@@@@"
127
128
Louis Dionnecbc66672019-01-09 19:40:20 +0000129# TODO: We should also link against the libc++abi.dylib that was shipped in the SDK
Louis Dionne3e2f88d2020-04-14 15:07:38 -0400130if [[ ${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 "@@@@@@"
136fi
137
Louis Dionne83c20b32020-05-15 12:13:48 -0400138LIBCXX_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${DEPLOYMENT_TARGET}"
139LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++abi/${DEPLOYMENT_TARGET}"
140LIBCXX_ROOT_IN_SDK="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${MACOS_SDK_VERSION}"
Louis Dionnecbc66672019-01-09 19:40:20 +0000141
142# TODO: We need to also run the tests for libc++abi.
Louis Dionnecbc66672019-01-09 19:40:20 +0000143echo "@@@ Running tests for libc++ @@@"
Louis Dionne293573d2019-08-06 20:01:28 +0000144"${LLVM_BUILD_DIR}/bin/llvm-lit" -sv "${MONOREPO_ROOT}/libcxx/test" \
145 --param=enable_experimental=false \
Louis Dionne293573d2019-08-06 20:01:28 +0000146 --param=cxx_headers="${LLVM_INSTALL_DIR}/include/c++/v1" \
147 --param=std="${STD}" \
148 --param=platform="macosx${DEPLOYMENT_TARGET}" \
Louis Dionne83c20b32020-05-15 12:13:48 -0400149 --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 Dionne293573d2019-08-06 20:01:28 +0000152 ${ADDITIONAL_LIT_ARGS}
Louis Dionnecbc66672019-01-09 19:40:20 +0000153echo "@@@@@@"