Skip to content

Commit 6bf5590

Browse files
committed
One build directory for every cmake flag combination
This will increase disk space usage. There is also no auto cleanup. But it allows to have multiple servers with multiple different cmake flags using the same source git repo. Without deleting the build directory on every rebuild or using the wrong flags.
1 parent 67bca61 commit 6bf5590

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

lib/include/update/cmake.sh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#!/bin/bash
22

3+
# prints the folder name of the cmake build directory
4+
# the format is always the following:
5+
#
6+
# build-[sha256sum of cmake flags]
7+
#
8+
get_cmake_build_dir() {
9+
local sum
10+
sum="$(printf '%s' "${CFG_CMAKE_FLAGS[*]}" | sha256sum | cut -d' ' -f1)"
11+
printf 'build-%s' "$sum"
12+
}
13+
314
function cmake_refresh_teeworlds_binary() {
415
if [ ! -f "$CFG_GIT_PATH_MOD/build/$CFG_COMPILED_BIN" ]
516
then
@@ -19,24 +30,25 @@ function cmake_refresh_teeworlds_binary() {
1930
if [ "$CFG_GITPATH_ANTIBOT" != "" ]
2031
then
2132
log "refreshing antibot binary ..."
33+
local build_dir="$(get_cmake_build_dir)"
2234

2335
if [ -f "$CFG_GITPATH_ANTIBOT"/libantibot.so ] && \
24-
[ -f "$CFG_GITPATH_ANTIBOT"/build/libantibot.so ]
36+
[ -f "$CFG_GITPATH_ANTIBOT"/"$build_dir"/libantibot.so ]
2537
then
2638
err "Error: found libantibot.so in root and build dir of $CFG_GITPATH_ANTIBOT"
2739
err " this is ambiguous. Please delete one of the files"
2840
err ""
2941
err " $CFG_GITPATH_ANTIBOT/libantibot.so"
30-
err " $CFG_GITPATH_ANTIBOT/build/libantibot.so"
42+
err " $CFG_GITPATH_ANTIBOT/$build_dir/libantibot.so"
3143
err ""
3244
exit 1
3345
fi
3446

3547
local libantibot_path=''
3648
for libantibot_path_candidate in \
3749
"$CFG_GITPATH_ANTIBOT"/libantibot.so \
38-
"$CFG_GITPATH_ANTIBOT"/build/libantibot.so \
39-
"$CFG_GIT_PATH_MOD"/build/libantibot.so
50+
"$CFG_GITPATH_ANTIBOT"/"$build_dir"/libantibot.so \
51+
"$CFG_GIT_PATH_MOD"/"$build_dir"/libantibot.so
4052
do
4153
if [ -f "$libantibot_path_candidate" ]
4254
then
@@ -180,6 +192,7 @@ function cmake_update() {
180192
update_antibot
181193
apply_git_patches
182194
bin_commit="$(git rev-parse HEAD)"
195+
local build_dir="$(get_cmake_build_dir)"
183196
mkdir -p "$SCRIPT_ROOT/lib/tmp"
184197
local cmake_cache="$SCRIPT_ROOT/lib/tmp/cmake_flags.txt"
185198
if [ -f "$cmake_cache" ]
@@ -189,16 +202,17 @@ function cmake_update() {
189202
log "cmake flags changed:"
190203
log " old='$(cat "$cmake_cache")'"
191204
log " new='${arg_cmake_flags[*]}'"
192-
log "deleting build directory ..."
193-
rm -rf build
205+
log "you might want to cleanup the now potentially old unused build dir in $PWD"
206+
# log "deleting build directory ..."
207+
# rm -rf "$build_dir"
194208
fi
195209
fi
196210

197211
register_hook_before_compile
198212

199213
echo "${arg_cmake_flags[*]}" > "$cmake_cache"
200-
mkdir -p build || { err "Error: creating dir build/"; exit 1; }
201-
cd build || { err "Could not enter build/ directory"; exit 1; }
214+
mkdir -p "$build_dir" || { err "Error: creating dir $build_dir"; exit 1; }
215+
cd "$build_dir" || { err "Could not enter $build_dir directory"; exit 1; }
202216
branch="$(git branch | sed -n '/\* /s///p')"
203217

204218
local build_fail=0

0 commit comments

Comments
 (0)