Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·290 lines (269 loc) · 10.1 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·290 lines (269 loc) · 10.1 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
# Stop the script if any command fails
set -e
print_help() {
echo "Builds the project, runs tests, or cleans build files."
echo ""
echo "Usage: $0 [target] [options] | [command]"
echo ""
echo "Targets (defaults to 'debug' if unspecified but flags are present):"
echo " debug Builds with debug information, no optimizations."
echo " release Builds for production (optimized, no debug info)."
echo " relwithdebinfo Builds an optimized build with debug info."
echo " minsizerel Builds the smallest possible release."
echo ""
echo "Options:"
echo " --native Build for the build host's exact CPU (-march=native)."
echo " Faster but NOT portable -- local dev/bench only."
echo " Default is -march=x86-64-v3 (portable, shippable)."
echo " --asan Enables AddressSanitizer."
echo " --hyle Fetch + link the hyle consensus engine (core + services)"
echo " into cesluajitd. Pulls Rust/malachite-cpp; first build is slow."
echo " --hyle-src PATH Build --hyle against a local hyle checkout instead of the"
echo " published one. Implies --hyle."
echo " --mail Enable outbound mail (builtin:mail + SMTP with TLS). Needs"
echo " system OpenSSL. Gated behind CES_MAIL; off by default."
echo " --test [FILTER] Runs tests after building. Optional Boost.Test filter."
echo " Examples:"
echo " --test Run all tests"
echo " --test CesVMTests Run one suite"
echo " --test FileStore* Run by wildcard"
echo " --test */PutGetSmall Run one test case"
echo " --clean Cleans the target before building."
echo " --rm Deletes 'build/' dir before building."
echo " --help, -h Print help and exit."
echo ""
echo "Commands:"
echo " clean Cleans ALL targets."
echo " rm Deletes 'build/' dir."
echo ""
echo "Examples:"
echo " $0 --test --asan Build debug with ASan and run all tests"
echo " $0 --test CesVMTests Build debug and run only CesVM tests"
echo " $0 release --clean Rebuild (Clean + Build) release"
echo " $0 rm Wipe all builds"
}
deep_clean_project() {
echo "Deleting all builds..."
rm -rf build
echo "Done."
}
soft_clean_project() {
echo "Cleaning all targets..."
for dir in build/*/; do
if [ -d "$dir" ]; then
echo " cmake --build $dir --target clean"
cmake --build "$dir" --target clean 2>/dev/null || true
fi
done
}
clean_one_target() {
local BUILD_TYPE_LOWER="$1"
local BUILD_DIR="build/${BUILD_TYPE_LOWER}"
if [ -d "$BUILD_DIR" ]; then
echo "Cleaning ${BUILD_TYPE_LOWER}..."
cmake --build "$BUILD_DIR" --target clean 2>/dev/null || true
fi
}
build_one_config() {
local BUILD_TYPE_LOWER="$1"
local BUILD_TYPE_CAMEL="$2"
local BUILD_DIR="build/${BUILD_TYPE_LOWER}"
local EXTRA_ARGS=""
if [ "$ENABLE_ASAN" = true ]; then
EXTRA_ARGS="-DCMAKE_CXX_FLAGS=-fsanitize=address -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address"
fi
# hyle consensus engine on/off (explicit each run so it is not a sticky cache value).
local HYLE_ARG="-DCES_HYLE=OFF"
[ "$ENABLE_HYLE" = true ] && HYLE_ARG="-DCES_HYLE=ON"
# An empty FETCHCONTENT_SOURCE_DIR_HYLE means "download it", so passing this every run
# keeps a once-used local checkout from sticking in the cache.
local HYLE_SRC_ARG="-DFETCHCONTENT_SOURCE_DIR_HYLE=${HYLE_SRC}"
# mail feature on/off (builtin:mail + SMTP/TLS).
local MAIL_ARG="-DCES_MAIL=OFF"
[ "$ENABLE_MAIL" = true ] && MAIL_ARG="-DCES_MAIL=ON"
# Portable -march by default; --native pins to the build host.
local MARCH="x86-64-v3"
[ "$ENABLE_NATIVE" = true ] && MARCH="native"
# Always reconfigure: the git hash baked into the version stamp is
# captured at configure time (CMakeLists.txt, git rev-parse HEAD), so
# skipping configure on an existing build dir leaves the stamp stale.
echo "Configuring ${BUILD_TYPE_CAMEL} build (-march=${MARCH})..."
cmake -S . -B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE_CAMEL}" \
-DCES_MARCH="${MARCH}" \
$HYLE_ARG \
"$HYLE_SRC_ARG" \
$MAIL_ARG \
$EXTRA_ARGS
echo "Building ${BUILD_TYPE_CAMEL}..."
cmake --build "$BUILD_DIR" --parallel "$(nproc)"
echo "✅ ${BUILD_TYPE_CAMEL} build complete."
}
TARGET="debug"
CAMEL_TARGET="Debug"
ACTION="build"
RUN_TESTS=false
TEST_FILTER=""
DO_CLEAN=false
ENABLE_ASAN=false
ENABLE_NATIVE=false
ENABLE_HYLE=false
HYLE_SRC=""
ENABLE_MAIL=false
DO_DEEP_CLEAN=false
# Parse arguments — --test may optionally consume the next arg as a filter
ARGS=("$@")
i=0
while [ $i -lt ${#ARGS[@]} ]; do
arg="${ARGS[$i]}"
LOWER_ARG=$(echo "$arg" | tr '[:upper:]' '[:lower:]')
case "$LOWER_ARG" in
--help|-h)
print_help
exit 0
;;
--test)
RUN_TESTS=true
# Check if next arg is a filter (not another flag, not a target)
next_i=$((i + 1))
if [ $next_i -lt ${#ARGS[@]} ]; then
next="${ARGS[$next_i]}"
case "$next" in
--*|debug|release|relwithdebinfo|minsizerel|clean|rm)
;; # not a filter
*)
TEST_FILTER="$next"
i=$next_i
;;
esac
fi
;;
--clean)
DO_CLEAN=true
;;
--native)
ENABLE_NATIVE=true
;;
--hyle)
ENABLE_HYLE=true
;;
--hyle-src)
ENABLE_HYLE=true
next_i=$((i + 1))
if [ $next_i -ge ${#ARGS[@]} ]; then
echo "Error: --hyle-src needs a path" >&2
exit 1
fi
HYLE_SRC="$(cd "${ARGS[$next_i]}" && pwd)"
i=$next_i
;;
--mail)
ENABLE_MAIL=true
;;
--asan)
ENABLE_ASAN=true
;;
--rm)
DO_DEEP_CLEAN=true
;;
clean)
ACTION="soft_clean_all"
;;
rm)
ACTION="deep_clean"
;;
release)
TARGET="release"
CAMEL_TARGET="Release"
;;
relwithdebinfo)
TARGET="relwithdebinfo"
CAMEL_TARGET="RelWithDebInfo"
;;
minsizerel)
TARGET="minsizerel"
CAMEL_TARGET="MinSizeRel"
;;
debug)
TARGET="debug"
CAMEL_TARGET="Debug"
;;
*)
echo "❌ Error: Invalid argument '$arg'." >&2
exit 1
;;
esac
i=$((i + 1))
done
case "$ACTION" in
deep_clean)
deep_clean_project
exit 0
;;
soft_clean_all)
soft_clean_project
exit 0
;;
build)
if [ "$DO_DEEP_CLEAN" = true ]; then
deep_clean_project
fi
if [ "$DO_CLEAN" = true ]; then
clean_one_target "$TARGET"
fi
build_one_config "$TARGET" "$CAMEL_TARGET"
if [ "$RUN_TESTS" = true ]; then
BIN="build/${TARGET}/tests/cestests"
if [ -f "$BIN" ] && [ -x "$BIN" ]; then
# -l test_suite: per-suite progress during the run.
# --report_level=short: a count summary (cases/assertions) at the end.
BOOST_ARGS="-l test_suite --report_level=short"
LABEL="All Tests"
if [ -n "$TEST_FILTER" ]; then
BOOST_ARGS="$BOOST_ARGS --run_test=$TEST_FILTER"
LABEL="Tests ($TEST_FILTER)"
fi
echo "--- Running $LABEL ---"
# Per-run log file so concurrent build.sh --test invocations
# don't clobber each other's output/tally.
logf=$(mktemp "${TMPDIR:-/tmp}/cestests.XXXXXX.log")
set +e
test_start=$(date +%s.%N)
"$BIN" $BOOST_ARGS 2>&1 | tee "$logf"
rc=${PIPESTATUS[0]}
test_end=$(date +%s.%N)
set -e
# Wall-clock for the test run itself (not the build), for any
# filter. Sub-minute: "12.3s"; longer: "83.0s (1m 23s)".
elapsed=$(awk -v a="$test_start" -v b="$test_end" 'BEGIN{
d=b-a; if(d<0)d=0;
if(d>=60){m=int(d/60);r=d-m*60;printf "%.1fs (%dm %.0fs)",d,m,r}
else printf "%.1fs",d}')
# Build a one-line tally from the Boost short report. Never drive
# by the exit code alone (a wrapping command can mask it).
cases=$(grep -aoE '[0-9]+ test cases? out of [0-9]+ (passed|failed)' "$logf" | tail -1)
skipped=$(grep -aoE '[0-9]+ test cases? out of [0-9]+ skipped' "$logf" | tail -1)
asserts=$(grep -aoE '[0-9]+ assertions? out of [0-9]+ (passed|failed)' "$logf" | tail -1)
summary="$cases"
[ -n "$skipped" ] && summary="$summary, $skipped"
[ -n "$asserts" ] && summary="$summary; $asserts"
failed=$(grep -aoE '\*\*\* [0-9]+ failures? (are|is) detected|has failed with' "$logf" | tail -1)
if [ $rc -ne 0 ] || [ -n "$failed" ]; then
# Keep the log for inspection on failure; print its path.
echo "❌ $LABEL FAILED (exit code $rc) in $elapsed — ${summary:-see output above}"
echo " log: $logf"
exit 1
else
rm -f "$logf"
echo "✅ $LABEL passed in $elapsed — ${summary:-no tally}"
fi
else
echo "⚠️ cestests not found: $BIN"
exit 1
fi
fi
;;
esac
echo ""
echo "Done."