Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 1 | #!/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 | |
| 21 | set -euox pipefail |
| 22 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 23 | if [[ -z ${ABSEIL_ROOT:-} ]]; then |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 24 | ABSEIL_ROOT="$(realpath $(dirname ${0})/..)" |
| 25 | fi |
| 26 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 27 | if [[ -z ${STD:-} ]]; then |
| 28 | STD="c++11 c++14 c++17 c++20" |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 29 | fi |
| 30 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 31 | if [[ -z ${COMPILATION_MODE:-} ]]; then |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 32 | COMPILATION_MODE="fastbuild opt" |
| 33 | fi |
| 34 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 35 | if [[ -z ${EXCEPTIONS_MODE:-} ]]; then |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 36 | EXCEPTIONS_MODE="-fno-exceptions -fexceptions" |
| 37 | fi |
| 38 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 39 | source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh" |
| 40 | readonly DOCKER_CONTAINER=${LINUX_CLANG_LATEST_CONTAINER} |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 41 | |
| 42 | # USE_BAZEL_CACHE=1 only works on Kokoro. |
| 43 | # Without access to the credentials this won't work. |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 44 | if [[ ${USE_BAZEL_CACHE:-0} -ne 0 ]]; then |
| 45 | DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_KEYSTORE_DIR},target=/keystore,readonly ${DOCKER_EXTRA_ARGS:-}" |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 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:-}" |
| 52 | fi |
| 53 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 54 | # 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 |
| 57 | if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -d "${KOKORO_GFILE_DIR}/distdir" ]]; then |
| 58 | DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_GFILE_DIR}/distdir,target=/distdir,readonly ${DOCKER_EXTRA_ARGS:-}" |
| 59 | BAZEL_EXTRA_ARGS="--distdir=/distdir ${BAZEL_EXTRA_ARGS:-}" |
| 60 | fi |
| 61 | |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 62 | for 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 \ |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 67 | --mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp,readonly \ |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 68 | --workdir=/abseil-cpp \ |
| 69 | --cap-add=SYS_PTRACE \ |
| 70 | --rm \ |
| 71 | -e CC="/opt/llvm/clang/bin/clang" \ |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 72 | -e BAZEL_CXXOPTS="-std=${std}:-nostdinc++" \ |
| 73 | -e BAZEL_LINKOPTS="-L/opt/llvm/libcxx-tsan/lib:-lc++:-lc++abi:-lm:-Wl,-rpath=/opt/llvm/libcxx-tsan/lib" \ |
| 74 | -e CPLUS_INCLUDE_PATH="/opt/llvm/libcxx-tsan/include/c++/v1" \ |
| 75 | ${DOCKER_EXTRA_ARGS:-} \ |
| 76 | ${DOCKER_CONTAINER} \ |
| 77 | /usr/local/bin/bazel test ... \ |
| 78 | --build_tag_filters="-notsan" \ |
| 79 | --compilation_mode="${compilation_mode}" \ |
| 80 | --copt="${exceptions_mode}" \ |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 81 | --copt="-fsanitize=thread" \ |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 82 | --copt="-fno-sanitize-blacklist" \ |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 83 | --copt=-Werror \ |
| 84 | --keep_going \ |
| 85 | --linkopt="-fsanitize=thread" \ |
| 86 | --show_timestamps \ |
| 87 | --test_env="TSAN_OPTIONS=report_atomic_races=0" \ |
| 88 | --test_env="TSAN_SYMBOLIZER_PATH=/opt/llvm/clang/bin/llvm-symbolizer" \ |
| 89 | --test_env="TZDIR=/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo" \ |
| 90 | --test_output=errors \ |
| 91 | --test_tag_filters="-benchmark,-notsan" \ |
| 92 | ${BAZEL_EXTRA_ARGS:-} |
| 93 | done |
| 94 | done |
| 95 | done |