diff --git a/.travis.yml b/.travis.yml index 5a8e2be9..e8789873 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ sudo: false +dist: trusty language: cpp compiler: - gcc @@ -9,10 +10,11 @@ addons: - ubuntu-toolchain-r-test packages: - g++-5 + - clang install: - export CXX="g++-5" -- script/configure +- scan-build script/configure script: - script/ci diff --git a/script/ci b/script/ci index 70035525..64690944 100755 --- a/script/ci +++ b/script/ci @@ -2,6 +2,9 @@ set -e +. script/lib.sh + script/fetch-fixtures script/check-mallocs -script/test +scan_build make +script/test -b diff --git a/script/lib.sh b/script/lib.sh new file mode 100755 index 00000000..786fc51d --- /dev/null +++ b/script/lib.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +function scan_build { + extra_args=() + + # AFAICT, in the trusty travis container the scan-build tool is from the 3.4 + # installation. Therefore, by default it will use clang-3.4 when analysing code + # which doesn't support the '-std=c++14' (it is available via '-std=c++1y'). + # Use the system-wide installed clang instead which is 3.5 and does support + # '-std=c++14'. + extra_args+=("--use-analyzer=$(which clang)") + + # scan-build will try to guess which CXX should be used to compile the actual + # code, which is usually g++ but we need g++5 in the CI. Explicitly pass + # $CC/$CXX to scan-build if they are set in the environment. + + if [[ ! -z "$CC" ]]; then + extra_args+=("--use-cc=$CC") + fi + + if [[ ! -z "$CXX" ]]; then + extra_args+=("--use-c++=$CXX") + fi + + scan-build "${extra_args[@]}" --status-bugs "$@" +} diff --git a/script/test b/script/test index 39f21793..35c7ec33 100755 --- a/script/test +++ b/script/test @@ -2,6 +2,8 @@ set -e +. script/lib.sh + function usage { cat <<-EOF USAGE @@ -12,6 +14,8 @@ OPTIONS -h print this message + -b run make under scan-build static analyzer + -d run tests in a debugger (either lldb or gdb) -g run tests with valgrind's memcheck tool @@ -26,6 +30,7 @@ OPTIONS -z pipe tests' stderr to \`dot(1)\` to render an SVG log + EOF } @@ -37,8 +42,9 @@ args=() target=tests export BUILDTYPE=Test cmd="out/${BUILDTYPE}/${target}" +run_scan_build= -while getopts "df:s:gGhpvS" option; do +while getopts "bdf:s:gGhpvS" option; do case ${option} in h) usage @@ -69,6 +75,9 @@ while getopts "df:s:gGhpvS" option; do S) mode=SVG ;; + b) + run_scan_build=true + ;; esac done @@ -78,7 +87,11 @@ else args+=("--reporter=singleline") fi -make $target +if [[ ! -z "$run_scan_build" ]]; then + scan_build make $target +else + make $target +fi args=${args:-""} if [[ -n $profile ]]; then