xref: /aosp_15_r20/external/protobuf/kokoro/macos-next/cpp/build.sh (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1#!/bin/bash -eux
2#
3# Build file to set up and run tests
4
5set -o pipefail
6
7if [[ -h /tmpfs ]] && [[ ${PWD} == /tmpfs/src ]]; then
8  # Workaround for internal Kokoro bug: b/227401944
9  cd /Volumes/BuildData/tmpfs/src
10fi
11
12# These vars can be changed when running manually, e.g.:
13#
14#   % BUILD_CONFIG=RelWithDebInfo path/to/build.sh
15
16# By default, build using Debug config.
17: ${BUILD_CONFIG:=Debug}
18
19# By default, find the sources based on this script path.
20: ${SOURCE_DIR:=$(cd $(dirname $0)/../../..; pwd)}
21
22# By default, put outputs under <git root>/cmake/build.
23: ${BUILD_DIR:=${SOURCE_DIR}/cmake/build}
24
25source ${SOURCE_DIR}/kokoro/caplog.sh
26
27#
28# Update submodules
29#
30git -C "${SOURCE_DIR}" submodule update --init --recursive
31
32#
33# Configure and build in a separate directory
34#
35mkdir -p "${BUILD_DIR}"
36
37caplog 01_configure \
38  cmake -S "${SOURCE_DIR}" -B "${BUILD_DIR}" ${CAPLOG_CMAKE_ARGS:-}
39
40if [[ -n ${CAPLOG_DIR:-} ]]; then
41  mkdir -p "${CAPLOG_DIR}/CMakeFiles"
42  cp "${BUILD_DIR}"/CMakeFiles/CMake*.log "${CAPLOG_DIR}/CMakeFiles"
43fi
44
45caplog 02_build \
46  cmake --build "${BUILD_DIR}" --config "${BUILD_CONFIG}"
47
48#
49# Run tests
50#
51(
52  cd "${BUILD_DIR}"
53  caplog 03_combined_testlog \
54    ctest -C "${BUILD_CONFIG}" -j4 ${CAPLOG_CTEST_ARGS:-}
55)
56