|
3 | 3 | # Copyright (c) 2018, Postgres Professional
|
4 | 4 |
|
5 | 5 |
|
6 |
| -set -ux |
| 6 | +# provide a decent default level |
| 7 | +if [ -z ${LEVEL+x} ]; then |
| 8 | + LEVEL=scan-build |
| 9 | +fi |
7 | 10 |
|
| 11 | +set -ux |
8 | 12 |
|
9 | 13 | status=0
|
10 | 14 |
|
| 15 | + |
11 | 16 | # show pg_config just in case
|
12 | 17 | pg_config
|
13 | 18 |
|
14 |
| -# perform static analyzis |
15 |
| -scan-build --status-bugs make USE_PGXS=1 || status=$? |
16 | 19 |
|
17 |
| -# something's wrong, exit now! |
18 |
| -if [ $status -ne 0 ]; then exit 1; fi |
| 20 | +# perform code checks if asked to |
| 21 | +if [ "$LEVEL" = "scan-build" ]; then |
19 | 22 |
|
20 |
| -# don't forget to "make clean" |
21 |
| -make USE_PGXS=1 clean |
| 23 | + # perform static analyzis |
| 24 | + scan-build --status-bugs make USE_PGXS=1 || status=$? |
22 | 25 |
|
23 |
| -# initialize database |
24 |
| -initdb -D $PGDATA |
| 26 | + # something's wrong, exit now! |
| 27 | + if [ $status -ne 0 ]; then exit 1; fi |
| 28 | + |
| 29 | + # don't forget to "make clean" |
| 30 | + make USE_PGXS=1 clean |
| 31 | +fi |
| 32 | + |
| 33 | +# build with cassert + valgrind support |
| 34 | +if [ "$LEVEL" = "hardcore" ]; then |
| 35 | + |
| 36 | + set -e |
| 37 | + |
| 38 | + CUSTOM_PG_PATH=$PWD/pg_bin |
| 39 | + |
| 40 | + # here PG_VERSION is provided by postgres:X-alpine docker image |
| 41 | + wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" |
| 42 | + echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - |
| 43 | + |
| 44 | + mkdir postgresql |
| 45 | + |
| 46 | + tar \ |
| 47 | + --extract \ |
| 48 | + --file postgresql.tar.bz2 \ |
| 49 | + --directory postgresql \ |
| 50 | + --strip-components 1 |
| 51 | + |
| 52 | + cd postgresql |
| 53 | + |
| 54 | + # enable Valgrind support |
| 55 | + sed -i.bak "s/\/* #define USE_VALGRIND *\//#define USE_VALGRIND/g" src/include/pg_config_manual.h |
| 56 | + |
| 57 | + # enable additional options |
| 58 | + eval ./configure \ |
| 59 | + --with-gnu-ld \ |
| 60 | + --enable-debug \ |
| 61 | + --enable-cassert \ |
| 62 | + --prefix=$CUSTOM_PG_PATH |
| 63 | + |
| 64 | + # TODO: -j$(nproc) |
| 65 | + make -s -j1 && make install |
| 66 | + |
| 67 | + # override default PostgreSQL instance |
| 68 | + export PATH=$CUSTOM_PG_PATH/bin:$PATH |
| 69 | + |
| 70 | + # show pg_config path (just in case) |
| 71 | + which pg_config |
| 72 | + |
| 73 | + cd - |
| 74 | + |
| 75 | + set +e |
| 76 | +fi |
25 | 77 |
|
26 | 78 | # build and install extension (using PG_CPPFLAGS and SHLIB_LINK for gcov)
|
27 | 79 | make USE_PGXS=1 PG_CPPFLAGS="-coverage" SHLIB_LINK="-coverage"
|
28 | 80 | make USE_PGXS=1 install
|
29 | 81 |
|
| 82 | +# initialize database |
| 83 | +initdb -D $PGDATA |
| 84 | + |
30 | 85 | # restart cluster 'test'
|
31 | 86 | echo "port = 55435" >> $PGDATA/postgresql.conf
|
32 | 87 | pg_ctl start -l /tmp/postgres.log -w || status=$?
|
|
0 commit comments