• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2
3set -ue
4
5function usage() {
6  cat <<EOM
7$(basename ${0}) [-h|--help] --libcxx-root <LIBCXX-ROOT> --libcxxabi-root <LIBCXXABI-ROOT> --std <STD> --arch <ARCHITECTURE> [--lit-args <ARGS...>]
8
9This script is used to continually test libc++ and libc++abi trunk on MacOS.
10
11  --libcxx-root     Full path to the root of the libc++ repository to test.
12  --libcxxabi-root  Full path to the root of the libc++abi repository to test.
13  --std             Version of the C++ Standard to run the tests under (c++03, c++11, etc..).
14  --arch            Architecture to build the tests for (32, 64).
15  [--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.
16  [--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.
17  [-h, --help]      Print this help.
18EOM
19}
20
21while [[ $# -gt 0 ]]; do
22  case "$1" in
23    --libcxx-root)
24    LIBCXX_ROOT="${2}"
25    if [[ ! -e "${LIBCXX_ROOT}" ]]; then
26      echo "--libcxx-root '${LIBCXX_ROOT}' is not a valid directory"
27      usage
28      exit 1
29    fi
30    shift; shift
31    ;;
32    --libcxxabi-root)
33    LIBCXXABI_ROOT="${2}"
34    if [[ ! -e "${LIBCXXABI_ROOT}" ]]; then
35      echo "--libcxxabi-root '${LIBCXXABI_ROOT}' is not a valid directory"
36      usage
37      exit 1
38    fi
39    shift; shift
40    ;;
41    --std)
42    STD="${2}"
43    shift; shift
44    ;;
45    --arch)
46    ARCH="${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
69if [[ -z ${LIBCXX_ROOT+x} ]]; then echo "--libcxx-root is a required parameter"; usage; exit 1; fi
70if [[ -z ${LIBCXXABI_ROOT+x} ]]; then echo "--libcxxabi-root is a required parameter"; usage; exit 1; fi
71if [[ -z ${STD+x} ]]; then echo "--std is a required parameter"; usage; exit 1; fi
72if [[ -z ${ARCH+x} ]]; then echo "--arch is a required parameter"; usage; exit 1; fi
73if [[ -z ${ADDITIONAL_LIT_ARGS+x} ]]; then ADDITIONAL_LIT_ARGS=""; fi
74
75
76TEMP_DIR="$(mktemp -d)"
77echo "Created temporary directory ${TEMP_DIR}"
78function cleanup {
79  if [[ -z ${NO_CLEANUP+x} ]]; then
80    echo "Removing temporary directory ${TEMP_DIR}"
81    rm -rf "${TEMP_DIR}"
82  else
83    echo "Temporary directory is at '${TEMP_DIR}', make sure to clean it up yourself"
84  fi
85}
86trap cleanup EXIT
87
88
89LLVM_ROOT="${TEMP_DIR}/llvm"
90LIBCXX_BUILD_DIR="${TEMP_DIR}/libcxx-build"
91LIBCXX_INSTALL_DIR="${TEMP_DIR}/libcxx-install"
92LIBCXXABI_BUILD_DIR="${TEMP_DIR}/libcxxabi-build"
93LIBCXXABI_INSTALL_DIR="${TEMP_DIR}/libcxxabi-install"
94
95LLVM_TARBALL_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz"
96export CC="$(xcrun --find clang)"
97export CXX="$(xcrun --find clang++)"
98
99
100echo "@@@ Downloading LLVM tarball of master (only used for CMake configuration) @@@"
101mkdir "${LLVM_ROOT}"
102curl -L "${LLVM_TARBALL_URL}" | tar -xz --strip-components=1 -C "${LLVM_ROOT}"
103echo "@@@@@@"
104
105
106echo "@@@ Setting up LIT flags @@@"
107LIT_FLAGS="-sv --param=std=${STD} ${ADDITIONAL_LIT_ARGS}"
108if [[ "${ARCH}" == "32" ]]; then
109  LIT_FLAGS+=" --param=enable_32bit=true"
110fi
111echo "@@@@@@"
112
113
114echo "@@@ Configuring CMake for libc++ @@@"
115mkdir -p "${LIBCXX_BUILD_DIR}"
116(cd "${LIBCXX_BUILD_DIR}" &&
117  xcrun cmake "${LIBCXX_ROOT}" -GNinja \
118    -DLLVM_PATH="${LLVM_ROOT}" \
119    -DCMAKE_INSTALL_PREFIX="${LIBCXX_INSTALL_DIR}" \
120    -DLLVM_LIT_ARGS="${LIT_FLAGS}" \
121    -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib
122)
123echo "@@@@@@"
124
125
126echo "@@@ Configuring CMake for libc++abi @@@"
127mkdir -p "${LIBCXXABI_BUILD_DIR}"
128(cd "${LIBCXXABI_BUILD_DIR}" &&
129  xcrun cmake "${LIBCXXABI_ROOT}" -GNinja \
130    -DLIBCXXABI_LIBCXX_PATH="${LIBCXX_ROOT}" \
131    -DLLVM_PATH="${LLVM_ROOT}" \
132    -DCMAKE_INSTALL_PREFIX="${LIBCXXABI_INSTALL_DIR}" \
133    -DLLVM_LIT_ARGS="${LIT_FLAGS}" \
134    -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" # Build a universal dylib
135)
136echo "@@@@@@"
137
138
139echo "@@@ Building libc++.dylib and libc++abi.dylib from sources (just to make sure it works) @@@"
140ninja -C "${LIBCXX_BUILD_DIR}" install-cxx
141ninja -C "${LIBCXXABI_BUILD_DIR}" install-cxxabi
142echo "@@@@@@"
143
144
145echo "@@@ Running tests for libc++ @@@"
146# TODO: We should run check-cxx-abilist too
147ninja -C "${LIBCXX_BUILD_DIR}" check-cxx
148echo "@@@@@@"
149
150
151echo "@@@ Running tests for libc++abi @@@"
152ninja -C "${LIBCXXABI_BUILD_DIR}" check-cxxabi
153echo "@@@@@@"
154