blob: 4ed3bda2e3af27c95f4318184e3be61257dba342 [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 Dionne2fff24e2020-05-21 14:33:32 -04007$(basename ${0}) [-h|--help] --monorepo-root <MONOREPO-ROOT> --std <STD> --deployment-target <TARGET> [--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 Dionne2fff24e2020-05-21 14:33:32 -040011Specifically, this script runs the libc++ test suite against the just-built headers and linking against the just-built dylib, but it runs the tests against the dylibs for the given deployment target.
12
Louis Dionne293573d2019-08-06 20:01:28 +000013 --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 +000014 --std Version of the C++ Standard to run the tests under (c++03, c++11, etc..).
Louis Dionne9b557842019-02-27 23:36:22 +000015 --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 Dionne3e2f88d2020-04-14 15:07:38 -040016 [--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 +000017 [--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.
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.
20EOM
21}
22
23while [[ $# -gt 0 ]]; do
24 case "$1" in
Louis Dionne293573d2019-08-06 20:01:28 +000025 --monorepo-root)
26 MONOREPO_ROOT="${2}"
27 if [[ ! -d "${MONOREPO_ROOT}" ]]; then
28 echo "--monorepo-root '${MONOREPO_ROOT}' is not a valid directory"
Louis Dionnecbc66672019-01-09 19:40:20 +000029 usage
30 exit 1
31 fi
32 shift; shift
33 ;;
34 --std)
35 STD="${2}"
36 shift; shift
37 ;;
Louis Dionnecbc66672019-01-09 19:40:20 +000038 --deployment-target)
39 DEPLOYMENT_TARGET="${2}"
40 shift; shift
41 ;;
Louis Dionnecbc66672019-01-09 19:40:20 +000042 --lit-args)
43 ADDITIONAL_LIT_ARGS="${2}"
44 shift; shift
45 ;;
Louis Dionne3e2f88d2020-04-14 15:07:38 -040046 --libcxx-roots)
47 PREVIOUS_DYLIBS_DIR="${2}"
48 shift; shift
49 ;;
Louis Dionnecbc66672019-01-09 19:40:20 +000050 --no-cleanup)
51 NO_CLEANUP=""
52 shift
53 ;;
54 -h|--help)
55 usage
56 exit 0
57 ;;
58 *)
59 echo "${1} is not a supported argument"
60 usage
61 exit 1
62 ;;
63 esac
64done
65
Louis Dionne293573d2019-08-06 20:01:28 +000066if [[ -z ${MONOREPO_ROOT+x} ]]; then echo "--monorepo-root is a required parameter"; usage; exit 1; fi
Louis Dionnecbc66672019-01-09 19:40:20 +000067if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi
Louis Dionnecbc66672019-01-09 19:40:20 +000068if [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi
Louis Dionnecbc66672019-01-09 19:40:20 +000069if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi
Louis Dionne3e2f88d2020-04-14 15:07:38 -040070if [[ -z ${PREVIOUS_DYLIBS_DIR+x} ]]; then PREVIOUS_DYLIBS_DIR=""; fi
Louis Dionnecbc66672019-01-09 19:40:20 +000071
Louis Dionnecbc66672019-01-09 19:40:20 +000072TEMP_DIR="$(mktemp -d)"
73echo "Created temporary directory ${TEMP_DIR}"
74function cleanup {
75 if [[ -z ${NO_CLEANUP+x} ]]; then
76 echo "Removing temporary directory ${TEMP_DIR}"
77 rm -rf "${TEMP_DIR}"
78 else
79 echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself"
80 fi
81}
82trap cleanup EXIT
83
84
Louis Dionne293573d2019-08-06 20:01:28 +000085LLVM_BUILD_DIR="${TEMP_DIR}/llvm-build"
86LLVM_INSTALL_DIR="${TEMP_DIR}/llvm-install"
Louis Dionnecbc66672019-01-09 19:40:20 +000087
88PREVIOUS_DYLIBS_URL="http://lab.llvm.org:8080/roots/libcxx-roots.tar.gz"
89LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz"
Louis Dionnecbc66672019-01-09 19:40:20 +000090
91
Louis Dionne293573d2019-08-06 20:01:28 +000092echo "@@@ Configuring CMake @@@"
93mkdir -p "${LLVM_BUILD_DIR}"
94(cd "${LLVM_BUILD_DIR}" &&
Louis Dionne747d3112019-09-11 16:57:19 +000095 xcrun cmake \
96 -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Apple.cmake" \
97 -GNinja \
Louis Dionne293573d2019-08-06 20:01:28 +000098 -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}" \
99 -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
Louis Dionne74953e12020-04-30 12:55:01 -0400100 -DCMAKE_OSX_ARCHITECTURES="x86_64" \
Louis Dionne747d3112019-09-11 16:57:19 +0000101 "${MONOREPO_ROOT}/llvm"
Louis Dionnecbc66672019-01-09 19:40:20 +0000102)
103echo "@@@@@@"
104
105
Louis Dionne2fff24e2020-05-21 14:33:32 -0400106echo "@@@ Building and installing libc++ and libc++abi @@@"
107ninja -C "${LLVM_BUILD_DIR}" install-cxx install-cxxabi
Louis Dionnecbc66672019-01-09 19:40:20 +0000108echo "@@@@@@"
109
110
Louis Dionne3e2f88d2020-04-14 15:07:38 -0400111if [[ ${PREVIOUS_DYLIBS_DIR} == "" ]]; then
112 echo "@@@ Downloading dylibs for older deployment targets @@@"
113 PREVIOUS_DYLIBS_DIR="${TEMP_DIR}/libcxx-dylibs"
114 mkdir "${PREVIOUS_DYLIBS_DIR}"
115 curl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${PREVIOUS_DYLIBS_DIR}"
116 echo "@@@@@@"
117fi
118
Louis Dionne83c20b32020-05-15 12:13:48 -0400119LIBCXX_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++/${DEPLOYMENT_TARGET}"
120LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/libc++abi/${DEPLOYMENT_TARGET}"
Louis Dionnecbc66672019-01-09 19:40:20 +0000121
122# TODO: We need to also run the tests for libc++abi.
Louis Dionnecbc66672019-01-09 19:40:20 +0000123echo "@@@ Running tests for libc++ @@@"
Louis Dionne293573d2019-08-06 20:01:28 +0000124"${LLVM_BUILD_DIR}/bin/llvm-lit" -sv "${MONOREPO_ROOT}/libcxx/test" \
125 --param=enable_experimental=false \
Louis Dionne293573d2019-08-06 20:01:28 +0000126 --param=cxx_headers="${LLVM_INSTALL_DIR}/include/c++/v1" \
127 --param=std="${STD}" \
128 --param=platform="macosx${DEPLOYMENT_TARGET}" \
Louis Dionne2fff24e2020-05-21 14:33:32 -0400129 --param=cxx_library_root="${LLVM_INSTALL_DIR}/lib" \
Louis Dionne83c20b32020-05-15 12:13:48 -0400130 --param=cxx_runtime_root="${LIBCXX_ROOT_ON_DEPLOYMENT_TARGET}" \
131 --param=abi_library_path="${LIBCXXABI_ROOT_ON_DEPLOYMENT_TARGET}" \
Louis Dionne4cc5e0d2020-05-15 11:33:59 -0400132 --param=use_system_cxx_lib="True" \
Louis Dionne293573d2019-08-06 20:01:28 +0000133 ${ADDITIONAL_LIT_ARGS}
Louis Dionnecbc66672019-01-09 19:40:20 +0000134echo "@@@@@@"