• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
35clang-3.5)
36    export CC=clang-3.5
37    export CXX=clang++-3.5
38    ;;
39
40clang-3.6)
41    export CC=clang-3.6
42    export CXX=clang++-3.6
43    ;;
44
45clang-3.7)
46    export CC=clang-3.7
47    export CXX=clang++-3.7
48    ;;
49
50clang-3.8)
51    export CC=clang-3.8
52    export CXX=clang++-3.8
53    ;;
54
55clang-3.9)
56    export CC=clang-3.9
57    export CXX=clang++-3.9
58    ;;
59
60clang-4.0)
61    case "$OS" in
62    linux)
63        export CC=clang-4.0
64        export CXX=clang++-4.0
65        ;;
66    osx)
67        export CC=/usr/local/opt/llvm/bin/clang
68        export CXX=/usr/local/opt/llvm/bin/clang++
69        ;;
70    *) echo "Error: unexpected OS: $OS"; exit 1 ;;
71    esac
72    ;;
73
74clang-5.0)
75    export CC=clang-5.0
76    export CXX=clang++-5.0
77    ;;
78
79clang-6.0)
80    export CC=clang-6.0
81    export CXX=clang++-6.0
82    ;;
83
84clang-7.0)
85    export CC=clang-7
86    export CXX=clang++-7
87    ;;
88
89clang-default)
90    export CC=clang
91    export CXX=clang++
92    ;;
93
94bazel)
95    ;;
96
97*)
98    echo "Unrecognized value of COMPILER: $COMPILER"
99    exit 1
100esac
101
102run_make() {
103  make -j$N_JOBS
104}
105
106if [[ "${COMPILER}" != "bazel" ]]
107then
108    echo CXX version: $($CXX --version)
109    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)
110    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))
111
112    case "$1" in
113    DebugPlain)           CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2") ;;
114    DebugPlainNoPch)      CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;;
115    DebugAsan)            CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address") ;;
116    DebugAsanNoPch)       CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;;
117    DebugAsanUbsan)       CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address,undefined") ;;
118    DebugAsanUbsanNoPch)  CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O0 -fsanitize=address,undefined" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;;
119    DebugValgrind)        CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2"     -DRUN_TESTS_UNDER_VALGRIND=TRUE) ;;
120    DebugValgrindNoPch)   CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Debug   -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic -DFRUIT_DEBUG=1 -DFRUIT_EXTRA_DEBUG=1 -D_GLIBCXX_DEBUG=1 -O2"     -DRUN_TESTS_UNDER_VALGRIND=TRUE -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;;
121    ReleasePlain)         CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic") ;;
122    ReleasePlainNoPch)    CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic" -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;;
123    ReleaseValgrind)      CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic" -DRUN_TESTS_UNDER_VALGRIND=TRUE) ;;
124    ReleaseValgrindNoPch) CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="$STLARG -Werror -pedantic" -DRUN_TESTS_UNDER_VALGRIND=TRUE -DFRUIT_TESTS_USE_PRECOMPILED_HEADERS=OFF) ;;
125    *) echo "Error: you need to specify one of the supported postsubmit modes (see postsubmit.sh)."; exit 1 ;;
126    esac
127
128    SOURCES_PATH="$PWD"
129
130    # This is not needed on Travis CI, but it's sometimes needed when running postsubmit.sh locally, to avoid "import
131    # file mismatch" errors.
132    rm -rf tests/__pycache__/ tests/*.pyc tests/*/__pycache__/ tests/*/*.pyc
133
134    rm -rf build
135    mkdir build
136    cd build
137    cmake .. "${CMAKE_ARGS[@]}"
138    echo
139    echo "Content of CMakeFiles/CMakeError.log:"
140    if [ -f "CMakeFiles/CMakeError.log" ]
141    then
142      cat CMakeFiles/CMakeError.log
143    fi
144    echo
145    run_make
146
147    cd examples
148    run_make
149    cd ..
150
151    cd tests
152    run_make
153
154    # We specify the path explicitly because old versions of pytest (e.g. the one in Ubuntu 14.04)
155    # don't support the testpaths setting in pytest.ini, so they will ignore it and they would
156    # otherwise run no tests.
157    py.test -n auto -r a "$SOURCES_PATH"/tests
158    cd ..
159
160    make install
161else
162    # COMPILER=bazel
163
164    BAZEL_FLAGS=("--python_path=$(which python3)")
165    case "$1" in
166    DebugPlain)      ;;
167    ReleasePlain)    BAZEL_FLAGS+=("-c" "opt") ;;
168    *) echo "Error: you need to specify one of the supported postsubmit modes (see postsubmit.sh)."; exit 1 ;;
169    esac
170
171    cd extras/bazel_root/third_party/fruit
172    bazel build "${BAZEL_FLAGS[@]}" :fruit examples/... tests/...
173    bazel test "${BAZEL_FLAGS[@]}" --test_output=errors tests/...
174fi
175