1*58b9f456SAndroid Build Coastguard Worker#!/usr/bin/env bash 2*58b9f456SAndroid Build Coastguard Worker 3*58b9f456SAndroid Build Coastguard Workerset -ue 4*58b9f456SAndroid Build Coastguard Worker 5*58b9f456SAndroid Build Coastguard Workerfunction usage() { 6*58b9f456SAndroid Build Coastguard Worker cat <<EOM 7*58b9f456SAndroid Build Coastguard Worker$(basename ${0}) [-h|--help] --libcxx-root <LIBCXX-ROOT> --libcxxabi-root <LIBCXXABI-ROOT> --std <STD> --arch <ARCHITECTURE> --deployment-target <TARGET> --sdk-version <SDK-VERSION> [--lit-args <ARGS...>] 8*58b9f456SAndroid Build Coastguard Worker 9*58b9f456SAndroid Build Coastguard WorkerThis script is used to continually test the back-deployment use case of libc++ and libc++abi on MacOS. 10*58b9f456SAndroid Build Coastguard Worker 11*58b9f456SAndroid Build Coastguard Worker --libcxx-root Full path to the root of the libc++ repository to test. 12*58b9f456SAndroid Build Coastguard Worker --libcxxabi-root Full path to the root of the libc++abi repository to test. 13*58b9f456SAndroid Build Coastguard Worker --std Version of the C++ Standard to run the tests under (c++03, c++11, etc..). 14*58b9f456SAndroid Build Coastguard Worker --arch Architecture to build the tests for (32, 64). 15*58b9f456SAndroid Build Coastguard Worker --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.7 are supported. 16*58b9f456SAndroid Build Coastguard Worker --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. 17*58b9f456SAndroid Build Coastguard Worker [--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*58b9f456SAndroid Build Coastguard Worker [--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*58b9f456SAndroid Build Coastguard Worker [-h, --help] Print this help. 20*58b9f456SAndroid Build Coastguard WorkerEOM 21*58b9f456SAndroid Build Coastguard Worker} 22*58b9f456SAndroid Build Coastguard Worker 23*58b9f456SAndroid Build Coastguard Workerwhile [[ $# -gt 0 ]]; do 24*58b9f456SAndroid Build Coastguard Worker case "$1" in 25*58b9f456SAndroid Build Coastguard Worker --libcxx-root) 26*58b9f456SAndroid Build Coastguard Worker LIBCXX_ROOT="${2}" 27*58b9f456SAndroid Build Coastguard Worker if [[ ! -d "${LIBCXX_ROOT}" ]]; then 28*58b9f456SAndroid Build Coastguard Worker echo "--libcxx-root '${LIBCXX_ROOT}' is not a valid directory" 29*58b9f456SAndroid Build Coastguard Worker usage 30*58b9f456SAndroid Build Coastguard Worker exit 1 31*58b9f456SAndroid Build Coastguard Worker fi 32*58b9f456SAndroid Build Coastguard Worker shift; shift 33*58b9f456SAndroid Build Coastguard Worker ;; 34*58b9f456SAndroid Build Coastguard Worker --libcxxabi-root) 35*58b9f456SAndroid Build Coastguard Worker LIBCXXABI_ROOT="${2}" 36*58b9f456SAndroid Build Coastguard Worker if [[ ! -d "${LIBCXXABI_ROOT}" ]]; then 37*58b9f456SAndroid Build Coastguard Worker echo "--libcxxabi-root '${LIBCXXABI_ROOT}' is not a valid directory" 38*58b9f456SAndroid Build Coastguard Worker usage 39*58b9f456SAndroid Build Coastguard Worker exit 1 40*58b9f456SAndroid Build Coastguard Worker fi 41*58b9f456SAndroid Build Coastguard Worker shift; shift 42*58b9f456SAndroid Build Coastguard Worker ;; 43*58b9f456SAndroid Build Coastguard Worker --std) 44*58b9f456SAndroid Build Coastguard Worker STD="${2}" 45*58b9f456SAndroid Build Coastguard Worker shift; shift 46*58b9f456SAndroid Build Coastguard Worker ;; 47*58b9f456SAndroid Build Coastguard Worker --arch) 48*58b9f456SAndroid Build Coastguard Worker ARCH="${2}" 49*58b9f456SAndroid Build Coastguard Worker shift; shift 50*58b9f456SAndroid Build Coastguard Worker ;; 51*58b9f456SAndroid Build Coastguard Worker --deployment-target) 52*58b9f456SAndroid Build Coastguard Worker DEPLOYMENT_TARGET="${2}" 53*58b9f456SAndroid Build Coastguard Worker shift; shift 54*58b9f456SAndroid Build Coastguard Worker ;; 55*58b9f456SAndroid Build Coastguard Worker --sdk-version) 56*58b9f456SAndroid Build Coastguard Worker MACOS_SDK_VERSION="${2}" 57*58b9f456SAndroid Build Coastguard Worker shift; shift 58*58b9f456SAndroid Build Coastguard Worker ;; 59*58b9f456SAndroid Build Coastguard Worker --lit-args) 60*58b9f456SAndroid Build Coastguard Worker ADDITIONAL_LIT_ARGS="${2}" 61*58b9f456SAndroid Build Coastguard Worker shift; shift 62*58b9f456SAndroid Build Coastguard Worker ;; 63*58b9f456SAndroid Build Coastguard Worker --no-cleanup) 64*58b9f456SAndroid Build Coastguard Worker NO_CLEANUP="" 65*58b9f456SAndroid Build Coastguard Worker shift 66*58b9f456SAndroid Build Coastguard Worker ;; 67*58b9f456SAndroid Build Coastguard Worker -h|--help) 68*58b9f456SAndroid Build Coastguard Worker usage 69*58b9f456SAndroid Build Coastguard Worker exit 0 70*58b9f456SAndroid Build Coastguard Worker ;; 71*58b9f456SAndroid Build Coastguard Worker *) 72*58b9f456SAndroid Build Coastguard Worker echo "${1} is not a supported argument" 73*58b9f456SAndroid Build Coastguard Worker usage 74*58b9f456SAndroid Build Coastguard Worker exit 1 75*58b9f456SAndroid Build Coastguard Worker ;; 76*58b9f456SAndroid Build Coastguard Worker esac 77*58b9f456SAndroid Build Coastguard Workerdone 78*58b9f456SAndroid Build Coastguard Worker 79*58b9f456SAndroid Build Coastguard Workerif [[ -z ${LIBCXX_ROOT+x} ]]; then echo "--libcxx-root is a required parameter"; usage; exit 1; fi 80*58b9f456SAndroid Build Coastguard Workerif [[ -z ${LIBCXXABI_ROOT+x} ]]; then echo "--libcxxabi-root is a required parameter"; usage; exit 1; fi 81*58b9f456SAndroid Build Coastguard Workerif [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi 82*58b9f456SAndroid Build Coastguard Workerif [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi 83*58b9f456SAndroid Build Coastguard Workerif [[ -z ${DEPLOYMENT_TARGET+x} ]]; then echo "--deployment-target is a required parameter"; usage; exit 1; fi 84*58b9f456SAndroid Build Coastguard Workerif [[ -z ${MACOS_SDK_VERSION+x} ]]; then echo "--sdk-version is a required parameter"; usage; exit 1; fi 85*58b9f456SAndroid Build Coastguard Workerif [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi 86*58b9f456SAndroid Build Coastguard Worker 87*58b9f456SAndroid Build Coastguard Worker 88*58b9f456SAndroid Build Coastguard WorkerTEMP_DIR="$(mktemp -d)" 89*58b9f456SAndroid Build Coastguard Workerecho "Created temporary directory ${TEMP_DIR}" 90*58b9f456SAndroid Build Coastguard Workerfunction cleanup { 91*58b9f456SAndroid Build Coastguard Worker if [[ -z ${NO_CLEANUP+x} ]]; then 92*58b9f456SAndroid Build Coastguard Worker echo "Removing temporary directory ${TEMP_DIR}" 93*58b9f456SAndroid Build Coastguard Worker rm -rf "${TEMP_DIR}" 94*58b9f456SAndroid Build Coastguard Worker else 95*58b9f456SAndroid Build Coastguard Worker echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself" 96*58b9f456SAndroid Build Coastguard Worker fi 97*58b9f456SAndroid Build Coastguard Worker} 98*58b9f456SAndroid Build Coastguard Workertrap cleanup EXIT 99*58b9f456SAndroid Build Coastguard Worker 100*58b9f456SAndroid Build Coastguard Worker 101*58b9f456SAndroid Build Coastguard WorkerLLVM_ROOT="${TEMP_DIR}/llvm" 102*58b9f456SAndroid Build Coastguard WorkerLIBCXX_BUILD_DIR="${TEMP_DIR}/libcxx-build" 103*58b9f456SAndroid Build Coastguard WorkerLIBCXX_INSTALL_DIR="${TEMP_DIR}/libcxx-install" 104*58b9f456SAndroid Build Coastguard WorkerLIBCXXABI_BUILD_DIR="${TEMP_DIR}/libcxxabi-build" 105*58b9f456SAndroid Build Coastguard WorkerLIBCXXABI_INSTALL_DIR="${TEMP_DIR}/libcxxabi-install" 106*58b9f456SAndroid Build Coastguard Worker 107*58b9f456SAndroid Build Coastguard WorkerPREVIOUS_DYLIBS_URL="http://lab.llvm.org:8080/roots/libcxx-roots.tar.gz" 108*58b9f456SAndroid Build Coastguard WorkerLLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz" 109*58b9f456SAndroid Build Coastguard Workerexport CC="$(xcrun --find clang)" 110*58b9f456SAndroid Build Coastguard Workerexport CXX="$(xcrun --find clang++)" 111*58b9f456SAndroid Build Coastguard Worker 112*58b9f456SAndroid Build Coastguard Worker 113*58b9f456SAndroid Build Coastguard Workerecho "@@@ Downloading LLVM tarball of master (only used for CMake configuration) @@@" 114*58b9f456SAndroid Build Coastguard Workermkdir "${LLVM_ROOT}" 115*58b9f456SAndroid Build Coastguard Workercurl -L "${LLVM_TARBALL_URL}" | tar -xz --strip-components=1 -C "${LLVM_ROOT}" 116*58b9f456SAndroid Build Coastguard Workerecho "@@@@@@" 117*58b9f456SAndroid Build Coastguard Worker 118*58b9f456SAndroid Build Coastguard Worker 119*58b9f456SAndroid Build Coastguard Workerecho "@@@ Configuring architecture-related stuff @@@" 120*58b9f456SAndroid Build Coastguard Workerif [[ "${ARCH}" == "64" ]]; then CMAKE_ARCH_STRING="x86_64"; else CMAKE_ARCH_STRING="i386"; fi 121*58b9f456SAndroid Build Coastguard Workerif [[ "${ARCH}" == "64" ]]; then LIT_ARCH_STRING=""; else LIT_ARCH_STRING="--param=enable_32bit=true"; fi 122*58b9f456SAndroid Build Coastguard Workerecho "@@@@@@" 123*58b9f456SAndroid Build Coastguard Worker 124*58b9f456SAndroid Build Coastguard Worker 125*58b9f456SAndroid Build Coastguard Workerecho "@@@ Configuring CMake for libc++ @@@" 126*58b9f456SAndroid Build Coastguard Workermkdir -p "${LIBCXX_BUILD_DIR}" 127*58b9f456SAndroid Build Coastguard Worker(cd "${LIBCXX_BUILD_DIR}" && 128*58b9f456SAndroid Build Coastguard Worker xcrun cmake "${LIBCXX_ROOT}" -GNinja \ 129*58b9f456SAndroid Build Coastguard Worker -DLLVM_PATH="${LLVM_ROOT}" \ 130*58b9f456SAndroid Build Coastguard Worker -DCMAKE_INSTALL_PREFIX="${LIBCXX_INSTALL_DIR}" \ 131*58b9f456SAndroid Build Coastguard Worker -DCMAKE_OSX_ARCHITECTURES="${CMAKE_ARCH_STRING}" 132*58b9f456SAndroid Build Coastguard Worker) 133*58b9f456SAndroid Build Coastguard Workerecho "@@@@@@" 134*58b9f456SAndroid Build Coastguard Worker 135*58b9f456SAndroid Build Coastguard Worker 136*58b9f456SAndroid Build Coastguard Workerecho "@@@ Configuring CMake for libc++abi @@@" 137*58b9f456SAndroid Build Coastguard Workermkdir -p "${LIBCXXABI_BUILD_DIR}" 138*58b9f456SAndroid Build Coastguard Worker(cd "${LIBCXXABI_BUILD_DIR}" && 139*58b9f456SAndroid Build Coastguard Worker xcrun cmake "${LIBCXXABI_ROOT}" -GNinja \ 140*58b9f456SAndroid Build Coastguard Worker -DLIBCXXABI_LIBCXX_PATH="${LIBCXX_ROOT}" \ 141*58b9f456SAndroid Build Coastguard Worker -DLLVM_PATH="${LLVM_ROOT}" \ 142*58b9f456SAndroid Build Coastguard Worker -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_INSTALL_DIR}" \ 143*58b9f456SAndroid Build Coastguard Worker -DCMAKE_OSX_ARCHITECTURES="${CMAKE_ARCH_STRING}" 144*58b9f456SAndroid Build Coastguard Worker) 145*58b9f456SAndroid Build Coastguard Workerecho "@@@@@@" 146*58b9f456SAndroid Build Coastguard Worker 147*58b9f456SAndroid Build Coastguard Worker 148*58b9f456SAndroid Build Coastguard Workerecho "@@@ Installing the latest libc++ headers @@@" 149*58b9f456SAndroid Build Coastguard Workerninja -C "${LIBCXX_BUILD_DIR}" install-cxx-headers 150*58b9f456SAndroid Build Coastguard Workerecho "@@@@@@" 151*58b9f456SAndroid Build Coastguard Worker 152*58b9f456SAndroid Build Coastguard Worker 153*58b9f456SAndroid Build Coastguard Workerecho "@@@ Downloading dylibs for older deployment targets @@@" 154*58b9f456SAndroid Build Coastguard Worker# TODO: The tarball should contain libc++abi.dylib too, we shouldn't be relying on the system's 155*58b9f456SAndroid Build Coastguard Worker# TODO: We should also link against the libc++abi.dylib that was shipped in the SDK 156*58b9f456SAndroid Build Coastguard WorkerPREVIOUS_DYLIBS_DIR="${TEMP_DIR}/libcxx-dylibs" 157*58b9f456SAndroid Build Coastguard Workermkdir "${PREVIOUS_DYLIBS_DIR}" 158*58b9f456SAndroid Build Coastguard Workercurl "${PREVIOUS_DYLIBS_URL}" | tar -xz --strip-components=1 -C "${PREVIOUS_DYLIBS_DIR}" 159*58b9f456SAndroid Build Coastguard WorkerLIBCXX_ON_DEPLOYMENT_TARGET="${PREVIOUS_DYLIBS_DIR}/macOS/${DEPLOYMENT_TARGET}/libc++.dylib" 160*58b9f456SAndroid Build Coastguard WorkerLIBCXXABI_ON_DEPLOYMENT_TARGET="/usr/lib/libc++abi.dylib" 161*58b9f456SAndroid Build Coastguard WorkerLIBCXX_IN_SDK="${PREVIOUS_DYLIBS_DIR}/macOS/${MACOS_SDK_VERSION}/libc++.dylib" 162*58b9f456SAndroid Build Coastguard Workerecho "@@@@@@" 163*58b9f456SAndroid Build Coastguard Worker 164*58b9f456SAndroid Build Coastguard Worker 165*58b9f456SAndroid Build Coastguard Worker# TODO: We need to also run the tests for libc++abi. 166*58b9f456SAndroid Build Coastguard Worker# TODO: Make sure lit will actually run against the libc++abi we specified 167*58b9f456SAndroid Build Coastguard Workerecho "@@@ Running tests for libc++ @@@" 168*58b9f456SAndroid Build Coastguard Worker"${LIBCXX_BUILD_DIR}/bin/llvm-lit" -sv "${LIBCXX_ROOT}/test" \ 169*58b9f456SAndroid Build Coastguard Worker --param=enable_experimental=false \ 170*58b9f456SAndroid Build Coastguard Worker --param=enable_filesystem=false \ 171*58b9f456SAndroid Build Coastguard Worker ${LIT_ARCH_STRING} \ 172*58b9f456SAndroid Build Coastguard Worker --param=cxx_under_test="${CXX}" \ 173*58b9f456SAndroid Build Coastguard Worker --param=cxx_headers="${LIBCXX_INSTALL_DIR}/include/c++/v1" \ 174*58b9f456SAndroid Build Coastguard Worker --param=std="${STD}" \ 175*58b9f456SAndroid Build Coastguard Worker --param=platform="macosx${DEPLOYMENT_TARGET}" \ 176*58b9f456SAndroid Build Coastguard Worker --param=cxx_runtime_root="$(dirname "${LIBCXX_ON_DEPLOYMENT_TARGET}")" \ 177*58b9f456SAndroid Build Coastguard Worker --param=abi_library_path="$(dirname "${LIBCXXABI_ON_DEPLOYMENT_TARGET}")" \ 178*58b9f456SAndroid Build Coastguard Worker --param=use_system_cxx_lib="$(dirname "${LIBCXX_IN_SDK}")" \ 179*58b9f456SAndroid Build Coastguard Worker ${ADDITIONAL_LIT_ARGS} 180*58b9f456SAndroid Build Coastguard Workerecho "@@@@@@" 181