Skip to content

Commit 1b22896

Browse files
committed
enable static code analysis on Travis-CI
1 parent 58a3264 commit 1b22896

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

Diff for: .travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
os:
22
- linux
33

4+
sudo: required
5+
dist: trusty
6+
47
language: c
58

69
compiler:
@@ -11,6 +14,7 @@ before_install:
1114
- sudo sh ./travis/apt.postgresql.org.sh
1215

1316
env:
14-
- PGVERSION=9.5
17+
- PGVERSION=9.5 CHECK_CODE=true
18+
- PGVERSION=9.5 CHECK_CODE=false
1519

1620
script: bash ./travis/pg-travis-test.sh

Diff for: travis/pg-travis-test.sh

+50-7
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,73 @@ set -eux
44

55
sudo apt-get update
66

7+
8+
# required packages
79
packages="postgresql-$PGVERSION postgresql-server-dev-$PGVERSION postgresql-common"
810

11+
# exit code
12+
status=0
13+
14+
# pg_config path
15+
config_path=/usr/lib/postgresql/$PGVERSION/bin/pg_config
16+
17+
918
# bug: http://www.postgresql.org/message-id/[email protected]
1019
sudo update-alternatives --remove-all postmaster.1.gz
1120

1221
# stop all existing instances (because of https://github.com/travis-ci/travis-cookbooks/pull/221)
1322
sudo service postgresql stop
14-
# and make sure they don't come back
23+
# ... and make sure they don't come back
1524
echo 'exit 0' | sudo tee /etc/init.d/postgresql
1625
sudo chmod a+x /etc/init.d/postgresql
1726

18-
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install $packages
27+
# install required packages
28+
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install -qq $packages
1929

20-
status=0
30+
# create cluster 'test'
2131
sudo pg_createcluster --start $PGVERSION test -p 55435 -- -A trust
2232

23-
make USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/$PGVERSION/bin/pg_config
24-
sudo make install USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/$PGVERSION/bin/pg_config
33+
# perform code analysis if necessary
34+
if [ $CHECK_CODE = "true" ]; then
35+
36+
if [ "$CC" = "clang" ]; then
37+
sudo apt-get -y install -qq clang-3.5
38+
39+
scan-build-3.5 --status-bugs make USE_PGXS=1 PG_CONFIG=$config_path || status=$?
40+
exit $status
41+
42+
elif [ "$CC" = "gcc" ]; then
43+
sudo apt-get -y install -qq cppcheck
44+
45+
cppcheck --template "{file} ({line}): {severity} ({id}): {message}" \
46+
--enable=warning,portability,performance \
47+
--suppress=redundantAssignment \
48+
--suppress=uselessAssignmentPtrArg \
49+
--std=c89 src/*.c src/*.h 2> cppcheck.log
50+
51+
if [ -s cppcheck.log ]; then
52+
cat cppcheck.log
53+
status=1 # error
54+
fi
55+
56+
exit $status
57+
fi
58+
59+
# don't forget to "make clean"
60+
make clean USE_PGXS=1 PG_CONFIG=$config_path
61+
fi
62+
63+
# build pg_pathman
64+
make USE_PGXS=1 PG_CONFIG=$config_path
65+
sudo make install USE_PGXS=1 PG_CONFIG=$config_path
2566

26-
# add pg_pathman to shared_preload_libraries
67+
# add pg_pathman to shared_preload_libraries and restart cluster 'test'
2768
sudo bash -c "echo \"shared_preload_libraries = 'pg_pathman'\" >> /etc/postgresql/$PGVERSION/test/postgresql.conf"
2869
sudo pg_ctlcluster $PGVERSION test restart
2970

30-
PGPORT=55435 make installcheck USE_PGXS=1 PGUSER=postgres PG_CONFIG=/usr/lib/postgresql/$PGVERSION/bin/pg_config || status=$?
71+
# run regression tests
72+
PGPORT=55435 make installcheck USE_PGXS=1 PGUSER=postgres PG_CONFIG=$config_path || status=$?
3173

74+
# show diff if it exists
3275
if test -f regression.diffs; then cat regression.diffs; fi
3376
exit $status

0 commit comments

Comments
 (0)