forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci-build.sh
More file actions
executable file
·224 lines (192 loc) · 6.18 KB
/
ci-build.sh
File metadata and controls
executable file
·224 lines (192 loc) · 6.18 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/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=""
DISABLE_POSTGRES=""
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
;;
"--disable-postgres")
export DISABLE_POSTGRES='--disable-postgres'
echo Disabling postgres
;;
"--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][--disable-postgres]"
exit 1
;;
esac
done
NPROCS=$(getconf _NPROCESSORS_ONLN)
echo "Found $NPROCS processors"
date
if [ -z "${PROTOCOL}" ] ; then
echo "PROTOCOL not set, please use --protocol to set it"
exit 1
fi
SRC_DIR=$(pwd)
mkdir -p "build-${CC}-${PROTOCOL}"
cd "build-${CC}-${PROTOCOL}"
# Check to see if we _just_ tested this rev in
# a merge queue, and if so don't bother doing
# it again. Wastes billable CPU time.
if [ -e prev-pass-rev ]
then
PREV_REV=$(cat prev-pass-rev)
CURR_REV=$(git -C "${SRC_DIR}" rev-parse HEAD)
if [ "${PREV_REV}" = "${CURR_REV}" ]
then
exit 0
fi
rm -f prev-pass-rev
fi
# Try to ensure we're using the real g++ and clang++ versions we want
mkdir -p bin
export PATH=`pwd`/bin:$PATH
echo "PATH is $PATH"
hash -r
if test $CXX = 'clang++'; then
RUN_PARTITIONS=$(seq 0 $((NPROCS-1)))
# Use CLANG_VERSION environment variable if set, otherwise default to 20
CLANG_VER=${CLANG_VERSION:-20}
if test ${CLANG_VER} != 'none'; then
which clang-${CLANG_VER}
ln -sf `which clang-${CLANG_VER}` bin/clang
which clang++-${CLANG_VER}
ln -sf `which clang++-${CLANG_VER}` bin/clang++
which llvm-symbolizer-${CLANG_VER}
ln -sf `which llvm-symbolizer-${CLANG_VER}` bin/llvm-symbolizer
clang -v
llvm-symbolizer --version || true
fi
elif test $CXX = 'g++'; then
RUN_PARTITIONS=$(seq $NPROCS $((2*NPROCS-1)))
which gcc-14
ln -sf `which gcc-14` bin/gcc
which g++-14
ln -sf `which g++-14` bin/g++
which g++
g++ -v
fi
config_flags="--enable-asan --enable-extrachecks --enable-ccache --enable-sdfprefs --enable-threadsafety ${PROTOCOL_CONFIG} ${DISABLE_POSTGRES}"
# NB: use `-gdwarf-3` (not -g or -gdwarf-4 or later) specifically as
# it produces the highest-fidelity backtraces with our current
# rust/gimli-backed backtrace system.
export CFLAGS="-O2 -gdwarf-3 -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fno-common"
export CXXFLAGS="$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=$(pwd)/.ccache
export CCACHE_COMPRESS=true
export CCACHE_COMPRESSLEVEL=9
# cache size should be large enough for a full build
export CCACHE_MAXSIZE=800M
export CCACHE_CPP2=true
# periodically check to see if caches are old and purge them if so
if [ -d "$CCACHE_DIR" ] ; then
if [ -n "$(find $CCACHE_DIR -mtime +$CACHE_MAX_DAYS -print -quit)" ] ; then
echo Purging old cache dirs $CCACHE_DIR ./target $HOME/.cargo/registry $HOME/.cargo/git
rm -rf $CCACHE_DIR ./target $HOME/.cargo/registry $HOME/.cargo/git
fi
fi
ccache -p
ccache -s
ccache -z
date
time (cd "${SRC_DIR}" && ./autogen.sh)
time "${SRC_DIR}/configure" $config_flags
if [ -z "${SKIP_FORMAT_CHECK}" ]; then
make format
d=`git -C "${SRC_DIR}" diff | wc -l`
if [ $d -ne 0 ]
then
echo "clang format must be run as part of the pull request, current diff:"
git -C "${SRC_DIR}" diff
exit 1
fi
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
### incrementally purge old content from target directory
(cd "${SRC_DIR}" && CARGO_TARGET_DIR="build-${CC}-${PROTOCOL}/target" cargo sweep --maxsize 800MB)
if [ $WITH_TESTS -eq 0 ] ; then
echo "Build done, skipping tests"
exit 0
fi
if [ $DISABLE_POSTGRES != '--disable-postgres' ] ; then
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
fi
export ALL_VERSIONS=1
export NUM_PARTITIONS=$((NPROCS*2))
export RUN_PARTITIONS
export RND_SEED=$(($(date +%s) / 86400)) # Convert to days since epoch
echo "Using RND_SEED: $RND_SEED"
ulimit -n 4096
export INTERACTIVE=0
time make check
echo Running fixed check-test-tx-meta tests
export TEST_SPEC='[tx]'
export STELLAR_CORE_TEST_PARAMS="--ll fatal -r simple --disable-dots --all-versions --rng-seed 12345 --check-test-tx-meta ${SRC_DIR}/test-tx-meta-baseline-${PROTOCOL}"
export SKIP_SOROBAN_TESTS=true
time make check
echo All done
date
git -C "${SRC_DIR}" rev-parse HEAD >prev-pass-rev
exit 0