ci.sh (4036B)
1 #!/bin/sh 2 3 set -eux 4 5 export LC_ALL=C 6 7 # Print commit and relevant CI environment to allow reproducing the job outside of CI. 8 git show --no-patch 9 print_environment() { 10 # Turn off -x because it messes up the output 11 set +x 12 # There are many ways to print variable names and their content. This one 13 # does not rely on bash. 14 for var in WERROR_CFLAGS MAKEFLAGS BUILD \ 15 ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \ 16 EXPERIMENTAL ECDH RECOVERY SCHNORRSIG ELLSWIFT \ 17 SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS\ 18 EXAMPLES \ 19 HOST WRAPPER_CMD \ 20 CC CFLAGS CPPFLAGS AR NM 21 do 22 eval "isset=\${$var+x}" 23 if [ -n "$isset" ]; then 24 eval "val=\${$var}" 25 # shellcheck disable=SC2154 26 printf '%s="%s" ' "$var" "$val" 27 fi 28 done 29 echo "$0" 30 set -x 31 } 32 print_environment 33 34 env >> test_env.log 35 36 # If gcc is requested, assert that it's in fact gcc (and not some symlinked Apple clang). 37 case "${CC:-undefined}" in 38 *gcc*) 39 $CC -v 2>&1 | grep -q "gcc version" || exit 1; 40 ;; 41 esac 42 43 if [ -n "${CC+x}" ]; then 44 # The MSVC compiler "cl" doesn't understand "-v" 45 $CC -v || true 46 fi 47 if [ "$WITH_VALGRIND" = "yes" ]; then 48 valgrind --version 49 fi 50 if [ -n "$WRAPPER_CMD" ]; then 51 $WRAPPER_CMD --version 52 fi 53 54 # Workaround for https://bugs.kde.org/show_bug.cgi?id=452758 (fixed in valgrind 3.20.0). 55 case "${CC:-undefined}" in 56 clang*) 57 if [ "$CTIMETESTS" = "yes" ] && [ "$WITH_VALGRIND" = "yes" ] 58 then 59 export CFLAGS="${CFLAGS:+$CFLAGS }-gdwarf-4" 60 else 61 case "$WRAPPER_CMD" in 62 valgrind*) 63 export CFLAGS="${CFLAGS:+$CFLAGS }-gdwarf-4" 64 ;; 65 esac 66 fi 67 ;; 68 esac 69 70 ./autogen.sh 71 72 ./configure \ 73 --enable-experimental="$EXPERIMENTAL" \ 74 --with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \ 75 --with-ecmult-window="$ECMULTWINDOW" \ 76 --with-ecmult-gen-precision="$ECMULTGENPRECISION" \ 77 --enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \ 78 --enable-module-ellswift="$ELLSWIFT" \ 79 --enable-module-schnorrsig="$SCHNORRSIG" \ 80 --enable-examples="$EXAMPLES" \ 81 --enable-ctime-tests="$CTIMETESTS" \ 82 --with-valgrind="$WITH_VALGRIND" \ 83 --host="$HOST" $EXTRAFLAGS 84 85 # We have set "-j<n>" in MAKEFLAGS. 86 build_exit_code=0 87 make > make.log 2>&1 || build_exit_code=$? 88 cat make.log 89 if [ $build_exit_code -ne 0 ]; then 90 case "${CC:-undefined}" in 91 *snapshot*) 92 # Ignore internal compiler errors in gcc-snapshot and clang-snapshot 93 grep -e "internal compiler error:" -e "PLEASE submit a bug report" make.log 94 return $?; 95 ;; 96 *) 97 return 1; 98 ;; 99 esac 100 fi 101 102 # Print information about binaries so that we can see that the architecture is correct 103 file *tests* || true 104 file bench* || true 105 file .libs/* || true 106 107 # This tells `make check` to wrap test invocations. 108 export LOG_COMPILER="$WRAPPER_CMD" 109 110 make "$BUILD" 111 112 # Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool 113 EXEC='./libtool --mode=execute' 114 if [ -n "$WRAPPER_CMD" ] 115 then 116 EXEC="$EXEC $WRAPPER_CMD" 117 fi 118 119 if [ "$BENCH" = "yes" ] 120 then 121 { 122 $EXEC ./bench_ecmult 123 $EXEC ./bench_internal 124 $EXEC ./bench 125 } >> bench.log 2>&1 126 fi 127 128 if [ "$CTIMETESTS" = "yes" ] 129 then 130 if [ "$WITH_VALGRIND" = "yes" ]; then 131 ./libtool --mode=execute valgrind --error-exitcode=42 ./ctime_tests > ctime_tests.log 2>&1 132 else 133 $EXEC ./ctime_tests > ctime_tests.log 2>&1 134 fi 135 fi 136 137 # Rebuild precomputed files (if not cross-compiling). 138 if [ -z "$HOST" ] 139 then 140 make clean-precomp clean-testvectors 141 make precomp testvectors 142 fi 143 144 # Check that no repo files have been modified by the build. 145 # (This fails for example if the precomp files need to be updated in the repo.) 146 git diff --exit-code