1#!/bin/bash -x 2 3set -e 4 5# This only exists in OS X, but it doesn't cause issues in Linux (the dir doesn't exist, so it's 6# ignored). 7export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" 8 9case $COMPILER in 10gcc-4.9) 11 export CC=gcc-4.9 12 export CXX=g++-4.9 13 ;; 14 15gcc-5) 16 export CC=gcc-5 17 export CXX=g++-5 18 ;; 19 20gcc-6) 21 export CC=gcc-6 22 export CXX=g++-6 23 ;; 24 25gcc-7) 26 export CC=gcc-7 27 export CXX=g++-7 28 ;; 29 30gcc-8) 31 export CC=gcc-8 32 export CXX=g++-8 33 ;; 34 35gcc-9) 36 export CC=gcc-9 37 export CXX=g++-9 38 ;; 39 40gcc-10) 41 export CC=gcc-10 42 export CXX=g++-10 43 ;; 44 45clang-3.5) 46 export CC=clang-3.5 47 export CXX=clang++-3.5 48 ;; 49 50clang-3.6) 51 export CC=clang-3.6 52 export CXX=clang++-3.6 53 ;; 54 55clang-3.7) 56 export CC=clang-3.7 57 export CXX=clang++-3.7 58 ;; 59 60clang-3.8) 61 export CC=clang-3.8 62 export CXX=clang++-3.8 63 ;; 64 65clang-3.9) 66 export CC=clang-3.9 67 export CXX=clang++-3.9 68 ;; 69 70clang-4.0) 71 export CC=clang-4.0 72 export CXX=clang++-4.0 73 ;; 74 75clang-5.0) 76 export CC=clang-5.0 77 export CXX=clang++-5.0 78 ;; 79 80clang-6.0) 81 export CC=clang-6.0 82 export CXX=clang++-6.0 83 ;; 84 85clang-7.0) 86 export CC=clang-7 87 export CXX=clang++-7 88 ;; 89 90clang-8.0) 91 export CC=clang-8 92 export CXX=clang++-8 93 ;; 94 95clang-9.0) 96 export CC=clang-9 97 export CXX=clang++-9 98 ;; 99 100clang-10.0) 101 export CC=clang-10 102 export CXX=clang++-10 103 ;; 104 105clang-11.0) 106 export CC=clang-11 107 export CXX=clang++-11 108 ;; 109 110clang-default) 111 export CC=clang 112 export CXX=clang++ 113 ;; 114 115bazel) 116 ;; 117 118*) 119 echo "Unrecognized value of COMPILER: $COMPILER" 120 exit 1 121esac 122 123run_make() { 124 make -j$N_JOBS 125} 126 127if [[ "${COMPILER}" != "bazel" ]] 128then 129 # This is only needed in OS X but it has no effect on Linux so we can add it unconditionally. 130 BOOST_INCLUDE_FLAG="-I /usr/local/include/boost -I /usr/local/include" 131 # -Wdtor-name (part of -pedantic) is *very* pedantic. Following that results in weird-looking code. 132 # See https://bugs.llvm.org/show_bug.cgi?id=46979. 133 COMMON_CXX_FLAGS="$STLARG $BOOST_INCLUDE_FLAG -Werror -pedantic -Wno-unknown-warning-option -Wno-dtor-name -Winvalid-pch" 134 135 echo CXX version: $($CXX --version) 136 echo C++ Standard library location: $(echo '#include <vector>' | $CXX -x c++ -E - | grep 'vector\"' | awk '{print $3}' | sed 's@/vector@@;s@\"@@g' | head -n 1) 137 echo Normalized C++ Standard library location: $(readlink -f $(echo '#include <vector>' | $CXX -x c++ -E - | grep 'vector\"' | awk '{print $3}' | sed 's@/vector@@;s@\"@@g' | head -n 1)) 138 139 case "$1" in 140 DebugPlain) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2") ;; 141 DebugPlainNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2") ;; 142 DebugPlainNoPch) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 143 DebugPlainNoPchNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 144 DebugAsan) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address") ;; 145 DebugAsanNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address") ;; 146 DebugAsanNoPch) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 147 DebugAsanNoPchNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 148 DebugAsanUbsan) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address,undefined") ;; 149 DebugAsanUbsanNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address,undefined") ;; 150 DebugAsanUbsanNoPch) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address,undefined" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 151 DebugAsanUbsanNoPchNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address,undefined" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 152 DebugValgrind) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2" -DRUN_TESTS_UNDER_VALGRIND=TRUE) ;; 153 DebugValgrindNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2" -DRUN_TESTS_UNDER_VALGRIND=TRUE) ;; 154 DebugValgrindNoPch) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2" -DRUN_TESTS_UNDER_VALGRIND=TRUE -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 155 DebugValgrindNoPchNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2" -DRUN_TESTS_UNDER_VALGRIND=TRUE -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 156 ReleasePlain) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS") ;; 157 ReleasePlainNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS") ;; 158 ReleasePlainNoPch) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 159 ReleasePlainNoPchNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 160 ReleaseValgrind) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS" -DRUN_TESTS_UNDER_VALGRIND=TRUE) ;; 161 ReleaseValgrindNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS" -DRUN_TESTS_UNDER_VALGRIND=TRUE) ;; 162 ReleaseValgrindNoPch) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=TRUE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS" -DRUN_TESTS_UNDER_VALGRIND=TRUE -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 163 ReleaseValgrindNoPchNoClangTidy) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DFRUIT_ENABLE_CLANG_TIDY=FALSE -DCMAKE_CXX_FLAGS="$COMMON_CXX_FLAGS" -DRUN_TESTS_UNDER_VALGRIND=TRUE -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;; 164 *) echo "Error: you need to specify one of the supported postsubmit modes (see postsubmit.sh)."; exit 1 ;; 165 esac 166 # Setting compilers only via env vars doesn't work when using recent versions of XCode. 167 CMAKE_ARGS+=(-DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX) 168 169 SOURCES_PATH="$PWD" 170 171 # This is not needed on Travis CI, but it's sometimes needed when running postsubmit.sh locally, to avoid "import 172 # file mismatch" errors. 173 rm -rf tests/__pycache__/ tests/*.pyc tests/*/__pycache__/ tests/*/*.pyc 174 175 rm -rf build 176 mkdir build 177 cd build 178 cmake .. "${CMAKE_ARGS[@]}" 179 echo 180 echo "Content of CMakeFiles/CMakeError.log:" 181 if [ -f "CMakeFiles/CMakeError.log" ] 182 then 183 cat CMakeFiles/CMakeError.log 184 fi 185 echo 186 run_make 187 188 cd examples 189 run_make 190 cd .. 191 192 cd tests 193 run_make 194 195 # We specify the path explicitly because old versions of pytest (e.g. the one in Ubuntu 14.04) 196 # don't support the testpaths setting in pytest.ini, so they will ignore it and they would 197 # otherwise run no tests. 198 py.test -n auto -r a "$SOURCES_PATH"/tests 199 cd .. 200 201 make install 202else 203 # COMPILER=bazel 204 205 # In recent versions of Bazel (as of May 2020), --python_path is ignored unless 206 # --noincompatible_use_python_toolchains is also used. 207 # Ignoring --python_path is ok in Ubuntu 20.04 since 3.8 is the default Python there, but causes problems in docker 208 # images with older Ubuntu versions that have both 3.8 and another 3.x version installed. 209 BAZEL_FLAGS=("--python_path=$(which python3.8)" "--noincompatible_use_python_toolchains") 210 case "$1" in 211 DebugPlain) ;; 212 ReleasePlain) BAZEL_FLAGS+=("-c" "opt") ;; 213 *) echo "Error: you need to specify one of the supported postsubmit modes (see postsubmit.sh)."; exit 1 ;; 214 esac 215 216 cd extras/bazel_root/third_party/fruit 217 bazel build "${BAZEL_FLAGS[@]}" :fruit examples/... tests/... 218 bazel test "${BAZEL_FLAGS[@]}" --test_output=errors tests/... 219fi 220