|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# |
| 4 | +# Copyright (c) 2019, Postgres Professional |
| 5 | +# |
| 6 | +# supported levels: |
| 7 | +# * standard |
| 8 | +# * scan-build |
| 9 | +# * hardcore |
| 10 | +# |
| 11 | + |
| 12 | +set -ux |
| 13 | +status=0 |
| 14 | + |
| 15 | + |
| 16 | +# rebuild PostgreSQL with cassert support |
| 17 | +if [ "$LEVEL" = "hardcore" ]; then |
| 18 | + |
| 19 | + set -e |
| 20 | + |
| 21 | + CUSTOM_PG_BIN=$PWD/pg_bin |
| 22 | + CUSTOM_PG_SRC=$PWD/postgresql |
| 23 | + |
| 24 | + # here PG_VERSION is provided by postgres:X-alpine docker image |
| 25 | + curl "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" -o postgresql.tar.bz2 |
| 26 | + echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - |
| 27 | + |
| 28 | + mkdir $CUSTOM_PG_SRC |
| 29 | + |
| 30 | + tar \ |
| 31 | + --extract \ |
| 32 | + --file postgresql.tar.bz2 \ |
| 33 | + --directory $CUSTOM_PG_SRC \ |
| 34 | + --strip-components 1 |
| 35 | + |
| 36 | + cd $CUSTOM_PG_SRC |
| 37 | + |
| 38 | + # enable additional options |
| 39 | + ./configure \ |
| 40 | + CFLAGS='-O0 -ggdb3 -fno-omit-frame-pointer' \ |
| 41 | + --enable-cassert \ |
| 42 | + --prefix=$CUSTOM_PG_BIN \ |
| 43 | + --quiet |
| 44 | + |
| 45 | + time make -s -j$(nproc) && make -s install |
| 46 | + |
| 47 | + # override default PostgreSQL instance |
| 48 | + export PATH=$CUSTOM_PG_BIN/bin:$PATH |
| 49 | + export LD_LIBRARY_PATH=$CUSTOM_PG_BIN/lib |
| 50 | + |
| 51 | + # show pg_config path (just in case) |
| 52 | + which pg_config |
| 53 | + |
| 54 | + cd - |
| 55 | + |
| 56 | + set +e |
| 57 | +fi |
| 58 | + |
| 59 | +# show pg_config just in case |
| 60 | +pg_config |
| 61 | + |
| 62 | +# perform code checks if asked to |
| 63 | +if [ "$LEVEL" = "scan-build" ] || \ |
| 64 | + [ "$LEVEL" = "hardcore" ]; then |
| 65 | + |
| 66 | + # perform static analyzis |
| 67 | + scan-build --status-bugs make USE_PGXS=1 || status=$? |
| 68 | + |
| 69 | + # something's wrong, exit now! |
| 70 | + if [ $status -ne 0 ]; then exit 1; fi |
| 71 | + |
| 72 | + # don't forget to "make clean" |
| 73 | + make USE_PGXS=1 clean |
| 74 | +fi |
| 75 | + |
| 76 | + |
| 77 | +# build and install extension (using PG_CPPFLAGS and SHLIB_LINK for gcov) |
| 78 | +make USE_PGXS=1 PG_CPPFLAGS="-coverage" SHLIB_LINK="-coverage" install |
| 79 | + |
| 80 | +# initialize database |
| 81 | +initdb -D $PGDATA |
| 82 | + |
| 83 | +# set appropriate port |
| 84 | +export PGPORT=55435 |
| 85 | +echo "port = $PGPORT" >> $PGDATA/postgresql.conf |
| 86 | + |
| 87 | +# restart cluster 'test' |
| 88 | +pg_ctl start -l /tmp/postgres.log -w || status=$? |
| 89 | + |
| 90 | +# something's wrong, exit now! |
| 91 | +if [ $status -ne 0 ]; then cat /tmp/postgres.log; exit 1; fi |
| 92 | + |
| 93 | +# run regression tests |
| 94 | +export PG_REGRESS_DIFF_OPTS="-w -U3" # for alpine's diff (BusyBox) |
| 95 | +make USE_PGXS=1 installcheck || status=$? |
| 96 | + |
| 97 | +# show diff if it exists |
| 98 | +if test -f regression.diffs; then cat regression.diffs; fi |
| 99 | + |
| 100 | +# something's wrong, exit now! |
| 101 | +if [ $status -ne 0 ]; then exit 1; fi |
| 102 | + |
| 103 | +# generate *.gcov files |
| 104 | +gcov *.c *.h |
| 105 | + |
| 106 | + |
| 107 | +set +ux |
| 108 | + |
| 109 | + |
| 110 | +# send coverage stats to Codecov |
| 111 | +bash <(curl -s https://codecov.io/bash) |
0 commit comments