forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ci-build.sh
executable file
·193 lines (164 loc) · 4.84 KB
/
ci-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
# this script performs a build & test pass
# it depends on the CC and CXX environment variables
set -ev
# max age of cache before force purging
CACHE_MAX_DAYS=30
WITH_TESTS=1
export TEMP_POSTGRES=0
PROTOCOL_CONFIG=""
while [[ -n "$1" ]]; do
COMMAND="$1"
shift
case "${COMMAND}" in
"--disable-tests")
WITH_TESTS=0
echo Disabling tests
;;
"--use-temp-db")
export TEMP_POSTGRES=1
echo Using temp database
;;
"--check-test-tx-meta")
if [[ -z "${PROTOCOL}" ]]; then
echo 'must specify --protocol before --check-test-tx-meta'
exit 1
fi
export TEST_SPEC='[tx]'
export STELLAR_CORE_TEST_PARAMS="--ll fatal -r simple --all-versions --rng-seed 12345 --check-test-tx-meta ${PWD}/test-tx-meta-baseline-${PROTOCOL}"
;;
"--protocol")
PROTOCOL="$1"
shift
echo Testing with protocol $PROTOCOL
case "${PROTOCOL}" in
"current")
;;
"next")
PROTOCOL_CONFIG="--enable-next-protocol-version-unsafe-for-production"
;;
*)
echo Unknown protocol ${PROTOCOL}
exit 1
;;
esac
;;
"")
;;
*)
echo Unknown parameter ${COMMAND}
echo Usage: $0 "[--disable-tests][--use-temp-db]"
exit 1
;;
esac
done
echo $TRAVIS_PULL_REQUEST
NPROCS=$(getconf _NPROCESSORS_ONLN)
echo "Found $NPROCS processors"
date
# Short-circuit transient 'auto-initialization' builds
git fetch origin master
MASTER=$(git describe --always FETCH_HEAD)
HEAD=$(git describe --always HEAD)
echo $MASTER
echo $HEAD
if [ $HEAD == $MASTER ]
then
echo "HEAD SHA1 equals master; probably just establishing merge, exiting build early"
exit 1
fi
# Try to ensure we're using the real g++ and clang++ versions we want
mkdir bin
export PATH=`pwd`/bin:$PATH
echo "PATH is $PATH"
hash -r
if test $CXX = 'clang++'; then
RUN_PARTITIONS=$(seq 0 $((NPROCS-1)))
which clang-12
ln -s `which clang-12` bin/clang
which clang++-12
ln -s `which clang++-12` bin/clang++
which llvm-symbolizer-12
ln -s `which llvm-symbolizer-12` bin/llvm-symbolizer
clang -v
llvm-symbolizer --version || true
elif test $CXX = 'g++'; then
RUN_PARTITIONS=$(seq $NPROCS $((2*NPROCS-1)))
which gcc-10
ln -s `which gcc-10` bin/gcc
which g++-10
ln -s `which g++-10` bin/g++
which g++
g++ -v
fi
config_flags="--enable-asan --enable-extrachecks --enable-ccache --enable-sdfprefs ${PROTOCOL_CONFIG}"
export CFLAGS="-O2 -g1 -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fno-common"
export CXXFLAGS="-w $CFLAGS"
# quarantine_size_mb / malloc_context_size : reduce memory usage to avoid
# crashing in tests that churn a lot of memory
# disable leak detection: this requires the container to be run with
# "--cap-add SYS_PTRACE" or "--privileged"
# as the leak detector relies on ptrace
export ASAN_OPTIONS="quarantine_size_mb=100:malloc_context_size=4:detect_leaks=0:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:log_path=stdout"
echo "config_flags = $config_flags"
#### ccache config
export CCACHE_DIR=$HOME/.ccache
export CCACHE_COMPRESS=true
export CCACHE_COMPRESSLEVEL=9
# cache size should be large enough for a full build
export CCACHE_MAXSIZE=500M
export CCACHE_CPP2=true
# purge cache if it's too old
if [ -d "$CCACHE_DIR" ] ; then
if [ -n "$(find $CCACHE_DIR -mtime +$CACHE_MAX_DAYS -print -quit)" ] ; then
echo Purging old cache $CCACHE_DIR
rm -rf $CCACHE_DIR
fi
fi
ccache -p
ccache -s
date
time ./autogen.sh
time ./configure $config_flags
make format
d=`git diff | wc -l`
if [ $d -ne 0 ]
then
echo "clang format must be run as part of the pull request, current diff:"
git diff
exit 1
fi
crlf=$(find . ! \( -type d -o -path './.git/*' -o -path './Builds/*' -o -path './lib/*' \) -print0 | xargs -0 -n1 -P9 file "{}" | grep CRLF || true)
if [ -n "$crlf" ]
then
echo "Found some files with Windows line endings:"
echo "$crlf"
exit 1
fi
date
time make -j$(($NPROCS + 1))
ccache -s
if [ $WITH_TESTS -eq 0 ] ; then
echo "Build done, skipping tests"
exit 0
fi
if [ $TEMP_POSTGRES -eq 0 ] ; then
# Create postgres databases
export PGUSER=postgres
psql -c "create database test;"
# we run NPROCS jobs in parallel
for j in $(seq 0 $((NPROCS-1))); do
base_instance=$((j*50))
for i in $(seq $base_instance $((base_instance+15))); do
psql -c "create database test$i;"
done
done
fi
export ALL_VERSIONS=1
export NUM_PARTITIONS=$((NPROCS*2))
export RUN_PARTITIONS
ulimit -n 256
time make check
echo All done
date
exit 0