blob: 0580509409e9c42df8a48a7f99ba7738bd63760f [file] [log] [blame]
Louis Dionne227371d2019-01-09 19:40:20 +00001#!/usr/bin/env bash
2
3set -ue
4
5function usage() {
6 cat <<EOM
Louis Dionne53e9c2d2019-08-06 20:01:28 +00007$(basename ${0}) [-h|--help] --monorepo-root <MONOREPO-ROOT> --std <STD> --arch <ARCHITECTURE> --deployment-target <TARGET> --sdk-version <SDK-VERSION> [--lit-args <ARGS...>]
Louis Dionne227371d2019-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 Dionne53e9c2d2019-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 Dionne227371d2019-01-09 19:40:20 +000012 --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 Dionne4fcdf212019-02-27 23:36:22 +000014 --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 Dionne227371d2019-01-09 19:40:20 +000015 --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.
19EOM
20}
21
22while [[ $# -gt 0 ]]; do
23 case "$1" in
Louis Dionne53e9c2d2019-08-06 20:01:28 +000024 --monorepo-root)
25 MONOREPO_ROOT="${2}"
26 if [[ ! -d "${MONOREPO_ROOT}" ]]; then
27 echo "--monorepo-root '${MONOREPO_ROOT}' is not a valid directory"
Louis Dionne227371d2019-01-09 19:40:20 +000028 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
67done
68
Louis Dionne53e9c2d2019-08-06 20:01:28 +000069if [[ -z ${MONOREPO_ROOT+x} ]]; then echo "--monorepo-root is a required parameter"; usage; exit 1; fi
Louis Dionne227371d2019-01-09 19:40:20 +000070if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi
71if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi
72if [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi
73if [[ -z ${MACOS_SDK_VERSION+x} ]]; then echo "--sdk-version is a required parameter"; usage; exit 1; fi
74if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi
75
76
77TEMP_DIR="$(mktemp -d)"
78echo "Created temporary directory ${TEMP_DIR}"
79function 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}
87trap cleanup EXIT
88
89
Louis Dionne53e9c2d2019-08-06 20:01:28 +000090LLVM_BUILD_DIR="${TEMP_DIR}/llvm-build"
91LLVM_INSTALL_DIR="${TEMP_DIR}/llvm-install"
Louis Dionne227371d2019-01-09 19:40:20 +000092
93PREVIOUS_DYLIBS_URL="http://lab.llvm.org:8080/roots/libcxx-roots.tar.gz"
94LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz"
Louis Dionne227371d2019-01-09 19:40:20 +000095
96
Louis Dionne227371d2019-01-09 19:40:20 +000097echo "@@@ Configuring architecture-related stuff @@@"
98if [[ "${ARCH}" == "64" ]]; then CMAKE_ARCH_STRING="x86_64"; else CMAKE_ARCH_STRING="i386"; fi
99if [[ "${ARCH}" == "64" ]]; then LIT_ARCH_STRING=""; else LIT_ARCH_STRING="--param=enable_32bit=true"; fi
100echo "@@@@@@"
101
102
Louis Dionne53e9c2d2019-08-06 20:01:28 +0000103echo "@@@ Configuring CMake @@@"
104mkdir -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 Dionne227371d2019-01-09 19:40:20 +0000109 -DCMAKE_OSX_ARCHITECTURES="${CMAKE_ARCH_STRING}"
110)
111echo "@@@@@@"
112
113
114echo "@@@ Installing the latest libc++ headers @@@"
Louis Dionne53e9c2d2019-08-06 20:01:28 +0000115ninja -C "${LLVM_BUILD_DIR}" install-cxx-headers
Louis Dionne227371d2019-01-09 19:40:20 +0000116echo "@@@@@@"
117
118
119echo "@@@ Downloading dylibs for older deployment targets @@@"
Louis Dionne227371d2019-01-09 19:40:20 +0000120# TODO: We should also link against the libc++abi.dylib that was shipped in the SDK
121PREVIOUS_DYLIBS_DIR="${TEMP_DIR}/libcxx-dylibs"
122mkdir "${PREVIOUS_DYLIBS_DIR}"
123curl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${PREVIOUS_DYLIBS_DIR}"
124LIBCXX_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/${DEPLOYMENT_TARGET}/libc++.dylib"
Louis Dionnee4d6ac52019-04-12 16:58:25 +0000125LIBCXXABI_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/${DEPLOYMENT_TARGET}/libc++abi.dylib"
Louis Dionne227371d2019-01-09 19:40:20 +0000126LIBCXX_IN_SDK="${PREVIOUS_DYLIBS_DIR}/macOS/${MACOS_SDK_VERSION}/libc++.dylib"
127echo "@@@@@@"
128
129
130# TODO: We need to also run the tests for libc++abi.
Louis Dionne227371d2019-01-09 19:40:20 +0000131echo "@@@ Running tests for libc++ @@@"
Louis Dionne53e9c2d2019-08-06 20:01:28 +0000132"${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 Dionne227371d2019-01-09 19:40:20 +0000142echo "@@@@@@"