Squashed 'libs/protobuf/' content from commit fcd3b9a85
git-subtree-dir: libs/protobuf git-subtree-split: fcd3b9a85ef36e46643dc30176cea1a7ad62e02b
This commit is contained in:
46
kokoro/common/bazel_flags.sh
Executable file
46
kokoro/common/bazel_flags.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Helper for setting up common bazel flags in Kokoro.
|
||||
#
|
||||
# This script prints extra flags to a bazel invocation when it is run from
|
||||
# Kokoro. When the special environment variables are not present (e.g., if you
|
||||
# run Kokoro build scripts locally), this script only flips some debug settings.
|
||||
#
|
||||
# Example of running directly:
|
||||
# bazel test $(path/to/bazel_flags.sh) //...
|
||||
|
||||
function bazel_flags::gen_invocation_id() {
|
||||
# Create a new invocation ID and store in the artifacts dir.
|
||||
local _invocation_id=$(uuidgen | tr A-Z a-z)
|
||||
|
||||
# Put the new invocation ID at the start of the output IDs file. Some
|
||||
# Google-internal tools only look at the first entry, so this ensures the most
|
||||
# recent entry is first.
|
||||
local _ids_file=${KOKORO_ARTIFACTS_DIR}/bazel_invocation_ids
|
||||
local _temp_ids=$(mktemp)
|
||||
echo ${_invocation_id} > ${_temp_ids}
|
||||
[[ -e ${_ids_file} ]] && cat ${_ids_file} >> ${_temp_ids}
|
||||
mv -f ${_temp_ids} ${_ids_file}
|
||||
|
||||
echo -n ${_invocation_id}
|
||||
}
|
||||
|
||||
# Prints flags to use on Kokoro.
|
||||
function bazel_flags::kokoro_flags() {
|
||||
[[ -n ${KOKORO_JOB_NAME:-} ]] || return
|
||||
|
||||
local -a _flags
|
||||
_flags+=(
|
||||
--invocation_id=$(bazel_flags::gen_invocation_id)
|
||||
--remote_cache=https://storage.googleapis.com/protobuf-bazel-cache/${KOKORO_JOB_NAME}
|
||||
)
|
||||
if [[ -n ${KOKORO_BAZEL_AUTH_CREDENTIAL:-} ]]; then
|
||||
_flags+=( --google_credentials=${KOKORO_BAZEL_AUTH_CREDENTIAL} )
|
||||
else
|
||||
_flags+=( --google_default_credentials=true )
|
||||
fi
|
||||
|
||||
echo "${_flags[@]}"
|
||||
}
|
||||
|
||||
echo "$(bazel_flags::kokoro_flags) --keep_going --test_output=errors"
|
||||
92
kokoro/common/caplog.sh
Normal file
92
kokoro/common/caplog.sh
Normal file
@@ -0,0 +1,92 @@
|
||||
# Log capturing for the Kokoro runtime environment.
|
||||
#
|
||||
# This script should be `source`d from Kokoro build scripts to configure log
|
||||
# capturing when running under Kokoro.
|
||||
#
|
||||
# When not running under Kokoro, no logs will be collected. If you want to run
|
||||
# locally and collect logs anyway, set the KOKORO_ARTIFACTS_DIR environment
|
||||
# variable to a directory where the logs should go.
|
||||
#
|
||||
# The job `.cfg` file needs the following stanzas to declare the captured logs
|
||||
# as outputs (yes, these are globs, not regexes):
|
||||
#
|
||||
# action: {
|
||||
# define_artifacts: {
|
||||
# regex: "**/*sponge_log.log"
|
||||
# regex: "**/*sponge_log.xml"
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# Use the provided functions below as build/test fixtures, e.g.:
|
||||
#
|
||||
# source kokoro/common/capture_logs.sh
|
||||
# caplog build/step1 <build command>
|
||||
# caplog tests/step2 <test command>
|
||||
#
|
||||
# If log capturing is enabled, this script will set some variables that can be
|
||||
# used if necessary:
|
||||
#
|
||||
# CAPLOG_DIR is used for logs
|
||||
# CAPLOG_CMAKE_ARGS contains extra cmake args to enable test XML output
|
||||
# CAPLOG_CTEST_ARGS contains extra ctest args to capture combined test logs
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# if [[ -v CAPLOG_DIR_BUILD ]]; then
|
||||
# cp extra_diagnostics.log "${CAPLOG_DIR_BUILD}/diagnostics.log"
|
||||
# fi
|
||||
#
|
||||
# # Use ${...:-} form under `set -u`:
|
||||
# caplog build/01_configure cmake -G Ninja ${CAPLOG_CMAKE_ARGS:-}
|
||||
# caplog build/02_build cmake --build
|
||||
# caplog test/03_test ctest ${CAPLOG_CTEST_ARGS:-}
|
||||
|
||||
if [[ -z ${KOKORO_ARTIFACTS_DIR:-} ]]; then
|
||||
function caplog() { shift; "$@"; }
|
||||
else
|
||||
|
||||
CAPLOG_DIR="$(mktemp -d)"
|
||||
CAPLOG_CMAKE_ARGS="-Dprotobuf_TEST_XML_OUTDIR=${CAPLOG_DIR}/tests/"
|
||||
CAPLOG_CTEST_ARGS="--verbose"
|
||||
|
||||
# Captures the stdout/stderr of a command to a named log file.
|
||||
# Usage: caplog NAME COMMAND [ARGS...]
|
||||
function caplog() {
|
||||
_name="${CAPLOG_DIR}/${1%.log}.log"; shift
|
||||
mkdir -p "${_name%/*}"
|
||||
date
|
||||
time ( "$@" 2>&1 | tee "${_name}" )
|
||||
if [[ $? != 0 ]] ; then
|
||||
cat "${_name}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Trap handler: renames logs on script exit so they will be found by Kokoro.
|
||||
function _caplog_onexit() {
|
||||
_rc=$?
|
||||
set +x
|
||||
echo "Collecting logs [${BASH_SOURCE}]"
|
||||
|
||||
find "${CAPLOG_DIR}" -type f -name '*.log' \
|
||||
| while read _textlog; do
|
||||
# Ensure an XML file exists for each .log file.
|
||||
touch ${_textlog%.log}.xml
|
||||
done
|
||||
|
||||
find "${CAPLOG_DIR}" -type f \( -name '*.xml' -or -name '*.log' \) \
|
||||
| while read _src; do
|
||||
# Move to artifacts dir, preserving the path relative to CAPLOG_DIR.
|
||||
# The filename changes from foo/bar.log to foo/bar/sponge_log.log.
|
||||
_logfile=${_src/${CAPLOG_DIR}\//}
|
||||
_stem=${KOKORO_ARTIFACTS_DIR}/${_logfile%.*}
|
||||
_ext=${_logfile##*.}
|
||||
mkdir -p ${_stem}
|
||||
mv -v "${_src}" "${_stem}/sponge_log.${_ext}"
|
||||
done
|
||||
rm -rv "${CAPLOG_DIR}"
|
||||
exit ${_rc}
|
||||
}
|
||||
trap _caplog_onexit EXIT
|
||||
|
||||
fi
|
||||
84
kokoro/common/cmake.sh
Executable file
84
kokoro/common/cmake.sh
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Build tests under CMake.
|
||||
#
|
||||
# This script is used from macos and linux builds. It runs cmake and ctest in
|
||||
# the current directory. Any additional setup should be done before running this
|
||||
# script.
|
||||
#
|
||||
# This script uses `caplog` to save logfiles. See caplog.sh for details.
|
||||
|
||||
set -eu -o pipefail
|
||||
: ${SCRIPT_ROOT:=$(cd $(dirname $0)/../..; pwd)}
|
||||
|
||||
################################################################################
|
||||
# If you are using this script to run tests, you can set some environment
|
||||
# variables to control behavior:
|
||||
#
|
||||
# By default, find the sources based on this script's path.
|
||||
: ${SOURCE_DIR:=${SCRIPT_ROOT}}
|
||||
#
|
||||
# By default, put outputs under <git root>/cmake/build.
|
||||
: ${BUILD_DIR:=${SOURCE_DIR}/cmake/build}
|
||||
#
|
||||
# CMAKE_BUILD_TYPE is supported in cmake 3.22+. If set, we pass the value of this
|
||||
# variable explicitly for compatibility with older versions of cmake. See:
|
||||
# https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
|
||||
# (N.B.: not to be confused with CMAKE_CONFIG_TYPE.)
|
||||
if [[ -n ${CMAKE_BUILD_TYPE:-} ]]; then
|
||||
CMAKE_BUILD_TYPE_FLAG="-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
|
||||
else
|
||||
CMAKE_BUILD_TYPE_FLAG=
|
||||
fi
|
||||
#
|
||||
# For several other CMake options, see docs here:
|
||||
# https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html
|
||||
#
|
||||
# Some variables you may want to override (see cmake docs for details):
|
||||
# CMAKE_BUILD_PARALLEL_LEVEL
|
||||
# CMAKE_CONFIG_TYPE (N.B.: not to be confused with CMAKE_BUILD_TYPE)
|
||||
# CMAKE_GENERATOR
|
||||
# CTEST_PARALLEL_LEVEL
|
||||
################################################################################
|
||||
|
||||
echo "Building using..."
|
||||
echo " Sources: ${SOURCE_DIR}"
|
||||
echo " Build output: ${BUILD_DIR}"
|
||||
if [[ ${SOURCE_DIR} != ${SCRIPT_ROOT} ]]; then
|
||||
echo " Build scripts: ${SCRIPT_ROOT}"
|
||||
fi
|
||||
set -x
|
||||
source ${SCRIPT_ROOT}/kokoro/common/caplog.sh
|
||||
|
||||
#
|
||||
# Configure under $BUILD_DIR:
|
||||
#
|
||||
mkdir -p "${BUILD_DIR}"
|
||||
|
||||
(
|
||||
cd "${BUILD_DIR}"
|
||||
caplog 01_configure \
|
||||
cmake -S "${SOURCE_DIR}" \
|
||||
${CMAKE_BUILD_TYPE_FLAG} \
|
||||
${CAPLOG_CMAKE_ARGS:-}
|
||||
)
|
||||
if [[ -n ${CAPLOG_DIR:-} ]]; then
|
||||
# Save configuration logs.
|
||||
mkdir -p "${CAPLOG_DIR}/CMakeFiles"
|
||||
cp "${BUILD_DIR}"/CMakeFiles/CMake*.log "${CAPLOG_DIR}/CMakeFiles"
|
||||
fi
|
||||
|
||||
#
|
||||
# Build:
|
||||
#
|
||||
caplog 02_build \
|
||||
cmake --build "${BUILD_DIR}"
|
||||
|
||||
#
|
||||
# Run tests
|
||||
#
|
||||
(
|
||||
cd "${BUILD_DIR}"
|
||||
caplog 03_combined_testlog \
|
||||
ctest ${CAPLOG_CTEST_ARGS:-}
|
||||
)
|
||||
Reference in New Issue
Block a user