blob: 224aef81cbe7930175483d074dc36cbc79157867 [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001#!/bin/bash
2#
Austin Schuhb4691e92020-12-31 12:37:18 -08003# Copyright 2020 The Abseil Authors.
Austin Schuh36244a12019-09-21 17:52:38 -07004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# This script that can be invoked to test abseil-cpp in a hermetic environment
18# using a Docker image on Linux. You must have Docker installed to use this
19# script.
20
21set -euox pipefail
22
Austin Schuhb4691e92020-12-31 12:37:18 -080023if [[ -z ${ABSEIL_ROOT:-} ]]; then
Austin Schuh36244a12019-09-21 17:52:38 -070024 ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
25fi
26
Austin Schuhb4691e92020-12-31 12:37:18 -080027if [[ -z ${STD:-} ]]; then
Austin Schuh36244a12019-09-21 17:52:38 -070028 STD="c++11 c++14"
29fi
30
Austin Schuhb4691e92020-12-31 12:37:18 -080031if [[ -z ${COMPILATION_MODE:-} ]]; then
Austin Schuh36244a12019-09-21 17:52:38 -070032 COMPILATION_MODE="fastbuild opt"
33fi
34
Austin Schuhb4691e92020-12-31 12:37:18 -080035if [[ -z ${EXCEPTIONS_MODE:-} ]]; then
Austin Schuh36244a12019-09-21 17:52:38 -070036 EXCEPTIONS_MODE="-fno-exceptions -fexceptions"
37fi
38
Austin Schuhb4691e92020-12-31 12:37:18 -080039source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh"
40readonly DOCKER_CONTAINER=${LINUX_GCC_FLOOR_CONTAINER}
Austin Schuh36244a12019-09-21 17:52:38 -070041
42# USE_BAZEL_CACHE=1 only works on Kokoro.
43# Without access to the credentials this won't work.
Austin Schuhb4691e92020-12-31 12:37:18 -080044if [[ ${USE_BAZEL_CACHE:-0} -ne 0 ]]; then
Austin Schuh36244a12019-09-21 17:52:38 -070045 DOCKER_EXTRA_ARGS="--volume=${KOKORO_KEYSTORE_DIR}:/keystore:ro ${DOCKER_EXTRA_ARGS:-}"
46 # Bazel doesn't track changes to tools outside of the workspace
47 # (e.g. /usr/bin/gcc), so by appending the docker container to the
48 # remote_http_cache url, we make changes to the container part of
49 # the cache key. Hashing the key is to make it shorter and url-safe.
50 container_key=$(echo ${DOCKER_CONTAINER} | sha256sum | head -c 16)
51 BAZEL_EXTRA_ARGS="--remote_http_cache=https://storage.googleapis.com/absl-bazel-remote-cache/${container_key} --google_credentials=/keystore/73103_absl-bazel-remote-cache ${BAZEL_EXTRA_ARGS:-}"
52fi
53
Austin Schuhb4691e92020-12-31 12:37:18 -080054# Avoid depending on external sites like GitHub by checking --distdir for
55# external dependencies first.
56# https://docs.bazel.build/versions/master/guide.html#distdir
57if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -d "${KOKORO_GFILE_DIR}/distdir" ]]; then
58 DOCKER_EXTRA_ARGS="--volume=${KOKORO_GFILE_DIR}/distdir:/distdir:ro ${DOCKER_EXTRA_ARGS:-}"
59 BAZEL_EXTRA_ARGS="--distdir=/distdir ${BAZEL_EXTRA_ARGS:-}"
60fi
61
Austin Schuh36244a12019-09-21 17:52:38 -070062for std in ${STD}; do
63 for compilation_mode in ${COMPILATION_MODE}; do
64 for exceptions_mode in ${EXCEPTIONS_MODE}; do
65 echo "--------------------------------------------------------------------"
66 time docker run \
67 --volume="${ABSEIL_ROOT}:/abseil-cpp:ro" \
68 --workdir=/abseil-cpp \
69 --cap-add=SYS_PTRACE \
70 --rm \
Austin Schuhb4691e92020-12-31 12:37:18 -080071 -e CC="/usr/local/bin/gcc" \
Austin Schuh36244a12019-09-21 17:52:38 -070072 -e BAZEL_CXXOPTS="-std=${std}" \
73 ${DOCKER_EXTRA_ARGS:-} \
74 ${DOCKER_CONTAINER} \
75 /usr/local/bin/bazel test ... \
76 --compilation_mode="${compilation_mode}" \
77 --copt="${exceptions_mode}" \
78 --copt=-Werror \
79 --define="absl=1" \
80 --keep_going \
81 --show_timestamps \
82 --test_env="GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1" \
83 --test_env="TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo" \
84 --test_output=errors \
85 --test_tag_filters=-benchmark \
86 ${BAZEL_EXTRA_ARGS:-}
87 done
88 done
89done