cannam@48: #! /usr/bin/env bash cannam@48: cannam@48: set -euo pipefail cannam@48: cannam@48: doit() { cannam@48: echo "@@@@ $@" cannam@48: "$@" cannam@48: } cannam@48: cannam@48: QUICK= cannam@48: cannam@48: while [ $# -gt 0 ]; do cannam@48: case "$1" in cannam@48: test ) cannam@48: ;; # nothing cannam@48: quick ) cannam@48: QUICK=quick cannam@48: ;; cannam@48: caffeinate ) cannam@48: # Re-run preventing sleep. cannam@48: shift cannam@48: exec caffeinate -ims $0 $@ cannam@48: ;; cannam@48: tmpdir ) cannam@48: # Clone to a temp directory. cannam@48: if [ "$#" -lt 2 ]; then cannam@48: echo "usage: $0 tmpdir NAME [COMMAND]" >&2 cannam@48: exit 1 cannam@48: fi cannam@48: DIR=/tmp/$2 cannam@48: shift 2 cannam@48: if [ -e $DIR ]; then cannam@48: if [ "${DIR/*..*}" = "" ]; then cannam@48: echo "NO DO NOT PUT .. IN THERE IT'S GOING TO GO IN /tmp AND I'M GONNA DELETE IT" >&2 cannam@48: exit 1 cannam@48: fi cannam@48: if [ ! -e "$DIR/super-test.sh" ]; then cannam@48: echo "$DIR exists and it doesn't look like one of mine." >&2 cannam@48: exit 1 cannam@48: fi cannam@48: # make distcheck leaves non-writable files when it fails, so we need to chmod to be safe. cannam@48: chmod -R +w $DIR cannam@48: rm -rf $DIR cannam@48: fi cannam@48: git clone . $DIR cannam@48: cd $DIR cannam@48: exec ./super-test.sh "$@" cannam@48: ;; cannam@48: remote ) cannam@48: if [ "$#" -lt 2 ]; then cannam@48: echo "usage: $0 remote HOST [COMMAND]" >&2 cannam@48: exit 1 cannam@48: fi cannam@48: HOST=$2 cannam@48: shift 2 cannam@48: echo "=========================================================================" cannam@48: echo "Pushing code to $HOST..." cannam@48: echo "=========================================================================" cannam@48: BRANCH=$(git rev-parse --abbrev-ref HEAD) cannam@48: ssh $HOST '(chmod -fR +w tmp-test-capnp || true) && rm -rf tmp-test-capnp && mkdir tmp-test-capnp && git init tmp-test-capnp' cannam@48: git push ssh://$HOST/~/tmp-test-capnp "$BRANCH:test" cannam@48: ssh $HOST "cd tmp-test-capnp && git checkout test" cannam@48: exec ssh $HOST "cd tmp-test-capnp && ./super-test.sh $@ && cd .. && rm -rf tmp-test-capnp" cannam@48: ;; cannam@48: clang ) cannam@48: export CXX=clang++ cannam@48: ;; cannam@48: gcc-4.9 ) cannam@48: export CXX=g++-4.9 cannam@48: ;; cannam@48: gcc-4.8 ) cannam@48: export CXX=g++-4.8 cannam@48: ;; cannam@48: gcc-4.7 ) cannam@48: export CXX=g++-4.7 cannam@48: ;; cannam@48: mingw ) cannam@48: if [ "$#" -ne 2 ]; then cannam@48: echo "usage: $0 mingw CROSS_HOST" >&2 cannam@48: exit 1 cannam@48: fi cannam@48: CROSS_HOST=$2 cannam@48: cannam@48: cd c++ cannam@48: test -e configure || doit autoreconf -i cannam@48: test ! -e Makefile || (echo "ERROR: Directory unclean!" >&2 && false) cannam@48: doit ./configure --host="$CROSS_HOST" --disable-shared CXXFLAGS='-static-libgcc -static-libstdc++' cannam@48: doit make -j6 capnp.exe capnpc-c++.exe cannam@48: cannam@48: cp capnp.exe capnp-mingw.exe cannam@48: cp capnpc-c++.exe capnpc-c++-mingw.exe cannam@48: cannam@48: doit make distclean cannam@48: doit ./configure --host="$CROSS_HOST" --with-external-capnp --disable-shared --disable-reflection CXXFLAGS='-static-libgcc -static-libstdc++' CAPNP=./capnp-mingw.exe CAPNPC_CXX=./capnpc-c++-mingw.exe cannam@48: cannam@48: doit make -j6 check cannam@48: doit make distclean cannam@48: rm -f *-mingw.exe cannam@48: exit 0 cannam@48: ;; cannam@48: android ) cannam@48: if [ "$#" -ne 4 ]; then cannam@48: echo "usage: $0 android SDK_HOME TOOLCHAIN_HOME CROSS_HOST" >&2 cannam@48: exit 1 cannam@48: fi cannam@48: SDK_HOME=$2 cannam@48: TOOLCHAIN_HOME=$3 cannam@48: CROSS_HOST=$4 cannam@48: cannam@48: cd c++ cannam@48: test -e configure || doit autoreconf -i cannam@48: test ! -e Makefile || (echo "ERROR: Directory unclean!" >&2 && false) cannam@48: doit ./configure --disable-shared cannam@48: doit make -j6 capnp capnpc-c++ cannam@48: cannam@48: cp capnp capnp-host cannam@48: cp capnpc-c++ capnpc-c++-host cannam@48: cannam@48: export PATH="$TOOLCHAIN_HOME/bin:$PATH" cannam@48: doit make distclean cannam@48: doit ./configure --host="$CROSS_HOST" --with-external-capnp --disable-shared CXXFLAGS='-pie -fPIE' CAPNP=./capnp-host CAPNPC_CXX=./capnpc-c++-host cannam@48: cannam@48: doit make -j6 cannam@48: doit make -j6 capnp-test cannam@48: cannam@48: echo "Starting emulator..." cannam@48: trap 'kill $(jobs -p)' EXIT cannam@48: $SDK_HOME/tools/emulator -avd n6 -no-window & cannam@48: $SDK_HOME/platform-tools/adb wait-for-device cannam@48: echo "Waiting for localhost to be resolvable..." cannam@48: $SDK_HOME/platform-tools/adb shell 'while ! ping -c 1 localhost > /dev/null 2>&1; do sleep 1; done' cannam@48: doit $SDK_HOME/platform-tools/adb push capnp-test /data/capnp-test cannam@48: doit $SDK_HOME/platform-tools/adb shell 'cd /data && /data/capnp-test && echo ANDROID_""TESTS_PASSED' | tee android-test.log cannam@48: grep -q ANDROID_TESTS_PASSED android-test.log cannam@48: cannam@48: doit make distclean cannam@48: rm -f capnp-host capnpc-c++-host cannam@48: exit 0 cannam@48: ;; cannam@48: cmake ) cannam@48: cd c++ cannam@48: rm -rf cmake-build cannam@48: mkdir cmake-build cannam@48: cd cmake-build cannam@48: doit cmake -G "Unix Makefiles" .. cannam@48: doit make -j6 check cannam@48: exit 0 cannam@48: ;; cannam@48: exotic ) cannam@48: echo "=========================================================================" cannam@48: echo "MinGW 64-bit" cannam@48: echo "=========================================================================" cannam@48: "$0" mingw x86_64-w64-mingw32 cannam@48: echo "=========================================================================" cannam@48: echo "MinGW 32-bit" cannam@48: echo "=========================================================================" cannam@48: "$0" mingw i686-w64-mingw32 cannam@48: echo "=========================================================================" cannam@48: echo "Android" cannam@48: echo "=========================================================================" cannam@48: "$0" android /home/kenton/android/android-sdk-linux /home/kenton/android/android-16 arm-linux-androideabi cannam@48: echo "=========================================================================" cannam@48: echo "CMake" cannam@48: echo "=========================================================================" cannam@48: "$0" cmake cannam@48: exit 0 cannam@48: ;; cannam@48: clean ) cannam@48: rm -rf tmp-staging cannam@48: cd c++ cannam@48: if [ -e Makefile ]; then cannam@48: doit make maintainer-clean cannam@48: fi cannam@48: rm -f capnproto-*.tar.gz samples/addressbook samples/addressbook.capnp.c++ \ cannam@48: samples/addressbook.capnp.h cannam@48: exit 0 cannam@48: ;; cannam@48: help ) cannam@48: echo "usage: $0 [COMMAND]" cannam@48: echo "commands:" cannam@48: echo " test Runs tests (the default)." cannam@48: echo " clang Runs tests using Clang compiler." cannam@48: echo " gcc-4.7 Runs tests using gcc-4.7." cannam@48: echo " gcc-4.8 Runs tests using gcc-4.8." cannam@48: echo " gcc-4.9 Runs tests using gcc-4.9." cannam@48: echo " remote HOST Runs tests on HOST via SSH." cannam@48: echo " mingw Cross-compiles to MinGW and runs tests using WINE." cannam@48: echo " android Cross-compiles to Android and runs tests using emulator." cannam@48: echo " clean Delete temporary files that may be left after failure." cannam@48: echo " help Prints this help text." cannam@48: exit 0 cannam@48: ;; cannam@48: * ) cannam@48: echo "unknown command: $1" >&2 cannam@48: echo "try: $0 help" >&2 cannam@48: exit 1 cannam@48: ;; cannam@48: esac cannam@48: shift cannam@48: done cannam@48: cannam@48: # Build optimized builds because they catch more problems, but also enable debugging macros. cannam@48: # Enable lots of warnings and make sure the build breaks if they fire. Disable strict-aliasing cannam@48: # because GCC warns about code that I know is OK. Disable sign-compare because I've fixed more cannam@48: # sign-compare warnings than probably all other warnings combined and I've never seen it flag a cannam@48: # real problem. Disable unused parameters because it's stupidly noisy and never a real problem. cannam@48: export CXXFLAGS="-O2 -DDEBUG -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-sign-compare -Wno-unused-parameter" cannam@48: cannam@48: STAGING=$PWD/tmp-staging cannam@48: cannam@48: rm -rf "$STAGING" cannam@48: mkdir "$STAGING" cannam@48: mkdir "$STAGING/bin" cannam@48: mkdir "$STAGING/lib" cannam@48: export PATH=$STAGING/bin:$PATH cannam@48: export LD_LIBRARY_PATH=$STAGING/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} cannam@48: export PKG_CONFIG_PATH=$STAGING/lib/pkgconfig cannam@48: cannam@48: if [ "$QUICK" = quick ]; then cannam@48: echo "************************** QUICK TEST ***********************************" cannam@48: fi cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Building c++" cannam@48: echo "=========================================================================" cannam@48: cannam@48: # Apple now aliases gcc to clang, so probe to find out what compiler we're really using. cannam@48: if (${CXX:-g++} -dM -E -x c++ /dev/null 2>&1 | grep -q '__clang__'); then cannam@48: IS_CLANG=yes cannam@48: else cannam@48: IS_CLANG=no cannam@48: fi cannam@48: cannam@48: if [ $IS_CLANG = yes ]; then cannam@48: # Don't fail out on this ridiculous "argument unused during compilation" warning. cannam@48: export CXXFLAGS="$CXXFLAGS -Wno-error=unused-command-line-argument" cannam@48: else cannam@48: # GCC emits uninitialized warnings all over and they seem bogus. We use valgrind to test for cannam@48: # uninitialized memory usage later on. cannam@48: CXXFLAGS="$CXXFLAGS -Wno-maybe-uninitialized" cannam@48: fi cannam@48: cannam@48: cd c++ cannam@48: doit autoreconf -i cannam@48: doit ./configure --prefix="$STAGING" cannam@48: doit make -j6 check cannam@48: cannam@48: if [ $IS_CLANG = no ]; then cannam@48: # Verify that generated code compiles with pedantic warnings. Make sure to treat capnp headers cannam@48: # as system headers so warnings in them are ignored. cannam@48: doit ${CXX:-g++} -isystem src -std=c++11 -fno-permissive -pedantic -Wall -Wextra -Werror \ cannam@48: -c src/capnp/test.capnp.c++ -o /dev/null cannam@48: fi cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Testing c++ install" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit make install cannam@48: cannam@48: test "x$(which capnp)" = "x$STAGING/bin/capnp" cannam@48: test "x$(which capnpc-c++)" = "x$STAGING/bin/capnpc-c++" cannam@48: cannam@48: cd samples cannam@48: cannam@48: doit capnp compile -oc++ addressbook.capnp -I"$STAGING"/include --no-standard-import cannam@48: doit ${CXX:-g++} -std=c++11 addressbook.c++ addressbook.capnp.c++ -o addressbook \ cannam@48: $CXXFLAGS $(pkg-config --cflags --libs capnp) cannam@48: echo "@@@@ ./addressbook (in various configurations)" cannam@48: ./addressbook write | ./addressbook read cannam@48: ./addressbook dwrite | ./addressbook dread cannam@48: rm addressbook addressbook.capnp.c++ addressbook.capnp.h cannam@48: cannam@48: doit capnp compile -oc++ calculator.capnp -I"$STAGING"/include --no-standard-import cannam@48: doit ${CXX:-g++} -std=c++11 calculator-client.c++ calculator.capnp.c++ -o calculator-client \ cannam@48: $CXXFLAGS $(pkg-config --cflags --libs capnp-rpc) cannam@48: doit ${CXX:-g++} -std=c++11 calculator-server.c++ calculator.capnp.c++ -o calculator-server \ cannam@48: $CXXFLAGS $(pkg-config --cflags --libs capnp-rpc) cannam@48: rm -f /tmp/capnp-calculator-example-$$ cannam@48: ./calculator-server unix:/tmp/capnp-calculator-example-$$ & cannam@48: sleep 0.1 cannam@48: ./calculator-client unix:/tmp/capnp-calculator-example-$$ cannam@48: kill %+ cannam@48: wait %+ || true cannam@48: rm calculator-client calculator-server calculator.capnp.c++ calculator.capnp.h /tmp/capnp-calculator-example-$$ cannam@48: cannam@48: cd .. cannam@48: cannam@48: if [ "$QUICK" = quick ]; then cannam@48: doit make maintainer-clean cannam@48: rm -rf "$STAGING" cannam@48: exit 0 cannam@48: fi cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Testing --with-external-capnp" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit make distclean cannam@48: doit ./configure --prefix="$STAGING" --disable-shared \ cannam@48: --with-external-capnp CAPNP=$STAGING/bin/capnp cannam@48: doit make -j6 check cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Testing --disable-reflection" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit make distclean cannam@48: doit ./configure --prefix="$STAGING" --disable-shared --disable-reflection \ cannam@48: --with-external-capnp CAPNP=$STAGING/bin/capnp cannam@48: doit make -j6 check cannam@48: doit make distclean cannam@48: cannam@48: # Test 32-bit build now while we have $STAGING available for cross-compiling. cannam@48: if [ "x`uname -m`" = "xx86_64" ]; then cannam@48: echo "=========================================================================" cannam@48: echo "Testing 32-bit build" cannam@48: echo "=========================================================================" cannam@48: cannam@48: if [[ "`uname`" =~ CYGWIN ]]; then cannam@48: # It's just not possible to run cygwin32 binaries from within cygwin64. cannam@48: cannam@48: # Build as if we are cross-compiling, using the capnp we installed to $STAGING. cannam@48: doit ./configure --prefix="$STAGING" --disable-shared --host=i686-pc-cygwin \ cannam@48: --with-external-capnp CAPNP=$STAGING/bin/capnp cannam@48: doit make -j6 cannam@48: doit make -j6 capnp-test.exe cannam@48: cannam@48: # Expect a cygwin32 sshd to be listening at localhost port 2222, and use it cannam@48: # to run the tests. cannam@48: doit scp -P 2222 capnp-test.exe localhost:~/tmp-capnp-test.exe cannam@48: doit ssh -p 2222 localhost './tmp-capnp-test.exe && rm tmp-capnp-test.exe' cannam@48: cannam@48: doit make distclean cannam@48: cannam@48: elif [ "x${CXX:-g++}" != "xg++-4.8" ]; then cannam@48: doit ./configure CXX="${CXX:-g++} -m32" --disable-shared cannam@48: doit make -j6 check cannam@48: doit make distclean cannam@48: fi cannam@48: fi cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Testing c++ uninstall" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit ./configure --prefix="$STAGING" cannam@48: doit make uninstall cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Testing c++ dist" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit make -j6 distcheck cannam@48: doit make distclean cannam@48: rm capnproto-*.tar.gz cannam@48: cannam@48: if [ "x`uname`" = xLinux ]; then cannam@48: echo "=========================================================================" cannam@48: echo "Testing generic Unix (no Linux-specific features)" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -DKJ_USE_FUTEX=0 -DKJ_USE_EPOLL=0" cannam@48: doit make -j6 check cannam@48: doit make distclean cannam@48: fi cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Testing with -fno-rtti and -fno-exceptions" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-rtti" cannam@48: doit make -j6 check cannam@48: doit make distclean cannam@48: doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-exceptions" cannam@48: doit make -j6 check cannam@48: doit make distclean cannam@48: doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions" cannam@48: doit make -j6 check cannam@48: cannam@48: # Valgrind is currently "experimental and mostly broken" on OSX and fails to run the full test cannam@48: # suite, but I have it installed because it did manage to help me track down a bug or two. Anyway, cannam@48: # skip it on OSX for now. cannam@48: if [ "x`uname`" != xDarwin ] && which valgrind > /dev/null; then cannam@48: doit make distclean cannam@48: cannam@48: echo "=========================================================================" cannam@48: echo "Testing with valgrind" cannam@48: echo "=========================================================================" cannam@48: cannam@48: doit ./configure --disable-shared CXXFLAGS="-g" cannam@48: doit make -j6 cannam@48: doit make -j6 capnp-test cannam@48: doit valgrind --leak-check=full --track-fds=yes --error-exitcode=1 ./capnp-test cannam@48: fi cannam@48: cannam@48: doit make maintainer-clean cannam@48: cannam@48: rm -rf "$STAGING"