blob: f9c146b05b93bd8ef969d2b7013a9be665a2610f [file] [log] [blame]
Abseil Team0cbdc772019-05-10 12:38:49 -07001#!/bin/bash
2#
3# Copyright 2019 The Abseil Authors.
4#
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
Abseil Teamd43b7992020-04-03 13:24:29 -070023if [[ -z ${ABSEIL_ROOT:-} ]]; then
Abseil Team0cbdc772019-05-10 12:38:49 -070024 ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
25fi
26
Abseil Teamd43b7992020-04-03 13:24:29 -070027if [[ -z ${STD:-} ]]; then
Derek Mauro4bbdb022022-07-05 09:37:54 -070028 STD="c++14 c++17 c++20"
Abseil Team0cbdc772019-05-10 12:38:49 -070029fi
30
Abseil Teamd43b7992020-04-03 13:24:29 -070031if [[ -z ${COMPILATION_MODE:-} ]]; then
Abseil Team0cbdc772019-05-10 12:38:49 -070032 COMPILATION_MODE="fastbuild opt"
33fi
34
Abseil Teamd43b7992020-04-03 13:24:29 -070035if [[ -z ${EXCEPTIONS_MODE:-} ]]; then
Abseil Team2d2d7fb2019-08-23 11:38:04 -070036 EXCEPTIONS_MODE="-fno-exceptions -fexceptions"
37fi
38
Abseil Team092ed972020-03-20 09:47:42 -070039source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh"
40readonly DOCKER_CONTAINER=${LINUX_CLANG_LATEST_CONTAINER}
Abseil Team0cbdc772019-05-10 12:38:49 -070041
42# USE_BAZEL_CACHE=1 only works on Kokoro.
43# Without access to the credentials this won't work.
Abseil Teamd43b7992020-04-03 13:24:29 -070044if [[ ${USE_BAZEL_CACHE:-0} -ne 0 ]]; then
Abseil Team4b915e72020-10-19 15:25:26 -070045 DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_KEYSTORE_DIR},target=/keystore,readonly ${DOCKER_EXTRA_ARGS:-}"
Abseil Team0cbdc772019-05-10 12:38:49 -070046 # 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
Abseil Team092ed972020-03-20 09:47:42 -070054# 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
Abseil Teamd43b7992020-04-03 13:24:29 -070057if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -d "${KOKORO_GFILE_DIR}/distdir" ]]; then
Abseil Team4b915e72020-10-19 15:25:26 -070058 DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_GFILE_DIR}/distdir,target=/distdir,readonly ${DOCKER_EXTRA_ARGS:-}"
Abseil Team092ed972020-03-20 09:47:42 -070059 BAZEL_EXTRA_ARGS="--distdir=/distdir ${BAZEL_EXTRA_ARGS:-}"
60fi
61
Abseil Team0cbdc772019-05-10 12:38:49 -070062for std in ${STD}; do
63 for compilation_mode in ${COMPILATION_MODE}; do
Abseil Team2d2d7fb2019-08-23 11:38:04 -070064 for exceptions_mode in ${EXCEPTIONS_MODE}; do
65 echo "--------------------------------------------------------------------"
66 time docker run \
Abseil Team4b915e72020-10-19 15:25:26 -070067 --mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp,readonly \
Abseil Team2d2d7fb2019-08-23 11:38:04 -070068 --workdir=/abseil-cpp \
69 --cap-add=SYS_PTRACE \
70 --rm \
71 -e CC="/opt/llvm/clang/bin/clang" \
Abseil Team2d2d7fb2019-08-23 11:38:04 -070072 -e BAZEL_CXXOPTS="-std=${std}:-nostdinc++" \
Abseil Teamc59e7e52022-01-14 04:25:20 -080073 -e BAZEL_LINKOPTS="-L/opt/llvm/libcxx/lib/x86_64-unknown-linux-gnu:-lc++:-lc++abi:-lm:-Wl,-rpath=/opt/llvm/libcxx/lib/x86_64-unknown-linux-gnu" \
74 -e CPLUS_INCLUDE_PATH="/opt/llvm/libcxx/include/x86_64-unknown-linux-gnu/c++/v1:/opt/llvm/libcxx/include/c++/v1" \
Abseil Team2d2d7fb2019-08-23 11:38:04 -070075 ${DOCKER_EXTRA_ARGS:-} \
76 ${DOCKER_CONTAINER} \
77 /usr/local/bin/bazel test ... \
78 --compilation_mode="${compilation_mode}" \
79 --copt="${exceptions_mode}" \
Abseil Team940c06c2022-01-28 09:04:58 -080080 --copt="-DGTEST_REMOVE_LEGACY_TEST_CASEAPI_=1" \
Abseil Team2d2d7fb2019-08-23 11:38:04 -070081 --copt="-fsanitize=address" \
82 --copt="-fsanitize=float-divide-by-zero" \
83 --copt="-fsanitize=nullability" \
84 --copt="-fsanitize=undefined" \
Abseil Team1de01662020-01-03 08:41:10 -080085 --copt="-fno-sanitize-blacklist" \
Abseil Team2d2d7fb2019-08-23 11:38:04 -070086 --copt=-Werror \
Abseil Team4a231512021-06-21 23:19:49 -070087 --distdir="/bazel-distdir" \
Derek Mauro59cba2b2022-08-15 07:00:03 -070088 --features=external_include_paths \
Abseil Team2d2d7fb2019-08-23 11:38:04 -070089 --keep_going \
90 --linkopt="-fsanitize=address" \
91 --linkopt="-fsanitize-link-c++-runtime" \
92 --show_timestamps \
93 --test_env="ASAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer" \
94 --test_env="TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo" \
95 --test_env="UBSAN_OPTIONS=print_stacktrace=1" \
96 --test_env="UBSAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer" \
97 --test_output=errors \
98 --test_tag_filters="-benchmark,-noasan" \
99 ${BAZEL_EXTRA_ARGS:-}
100 done
Abseil Team0cbdc772019-05-10 12:38:49 -0700101 done
102done