serene/builder

192 lines
4.2 KiB
Plaintext
Raw Permalink Normal View History

2020-07-10 20:41:46 +01:00
#! /bin/bash
command=$1
# Utilize `ccache` if available
if type "ccache" > /dev/null
then
CC="$(which ccache) $(which clang)"
CXX="$(which ccache) $(which clang++)"
else
CC=$(which clang)
CXX=$(which clang++)
fi
2020-07-10 20:41:46 +01:00
export CC
export CXX
export CCACHE_SLOPPINESS="pch_defines,time_macros"
# Meke sure to use `lld` linker it faster and has a better UX
export LDFLAGS="-fuse-ld=lld"
2021-06-15 01:21:48 +01:00
export ASAN_FLAG="-fsanitize=address"
export ASAN_OPTIONS=check_initialization_order=1
LSAN_OPTIONS=suppressions=$(pwd)/.ignore_sanitize
export LSAN_OPTIONS
# The `builder` script is supposed to be run from the
# root of the source tree
ROOT_DIR=$(pwd)
2020-07-10 20:41:46 +01:00
BUILD_DIR=$ROOT_DIR/build
scanbuild=scan-build
2020-07-10 20:41:46 +01:00
function pushed_build() {
pushd "$BUILD_DIR" > /dev/null || return
}
function popd_build() {
popd > /dev/null || return
}
2020-07-10 20:41:46 +01:00
function compile() {
pushed_build
ninja -j "$(nproc)"
popd_build
2020-07-10 20:41:46 +01:00
}
function build() {
pushed_build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug "$@" "$ROOT_DIR"
ninja -j "$(nproc)"
popd_build
2020-07-10 20:41:46 +01:00
}
2021-04-07 19:56:54 +01:00
function build-20() {
pushed_build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCPP_20_SUPPORT=ON "$@" "$ROOT_DIR"
ninja -j "$(nproc)"
2021-04-07 19:56:54 +01:00
popd_build
}
function build-release() {
pushed_build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "$ROOT_DIR"
ninja -j "$(nproc)"
popd_build
}
function build-docs() {
pushed_build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Docs "$ROOT_DIR"
ninja -j "$(nproc)"
popd_build
}
2020-07-10 20:41:46 +01:00
function clean() {
rm -rf "$BUILD_DIR"
2020-07-10 20:41:46 +01:00
}
function run() {
pushed_build
"$BUILD_DIR"/bin/serenec "$@"
popd_build
2020-07-10 20:41:46 +01:00
}
function memcheck() {
2021-06-15 01:21:48 +01:00
export ASAN_FLAG=""
build
pushed_build
valgrind --tool=memcheck --leak-check=yes --trace-children=yes "$BUILD_DIR"/bin/serenec "$@"
popd_build
2020-07-10 20:41:46 +01:00
}
2021-04-06 00:21:43 +01:00
function run-tests() {
"$BUILD_DIR"/src/tests/tests
2021-04-06 00:21:43 +01:00
}
2020-07-10 20:41:46 +01:00
function tests() {
pushed_build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON "$ROOT_DIR"
ninja -j "$(nproc)"
popd_build
2020-07-10 20:41:46 +01:00
}
case "$command" in
2020-07-23 21:53:42 +01:00
"setup")
pushd ./scripts || return
2021-04-13 10:39:13 +01:00
./git-pre-commit-format install
popd || return
echo "=== Manual action required ==="
echo "Set this environment variable. (clang-format-diff.py is located inside llvm's source directory)."
echo 'export CLANG_FORMAT_DIFF="python3 /path/to/llvm/saurce/llvm-project/clang/tools/clang-format/clang-format-diff.py"'
2020-07-23 21:53:42 +01:00
;;
2020-07-10 20:41:46 +01:00
"build")
clean
mkdir -p "$BUILD_DIR"
build "${@:2}"
2020-07-10 20:41:46 +01:00
;;
2021-04-07 19:56:54 +01:00
"build-20")
clean
mkdir -p "$BUILD_DIR"
2021-04-07 19:56:54 +01:00
build-20 "${@:2}"
;;
"build-docs")
clean
mkdir -p "$BUILD_DIR"
build-docs "${@:2}"
;;
"build-release")
clean
mkdir -p "$BUILD_DIR"
build-release "${@:2}"
;;
2020-07-10 20:41:46 +01:00
"compile")
compile
2020-07-10 20:41:46 +01:00
;;
2021-04-06 00:21:43 +01:00
"compile-and-test")
compile
run-tests
;;
2020-07-10 20:41:46 +01:00
"run")
2020-07-21 22:23:11 +01:00
run "${@:2}"
2020-07-10 20:41:46 +01:00
;;
2021-04-08 19:59:47 +01:00
"run-tests")
run-tests "${@:2}"
;;
2020-07-10 20:41:46 +01:00
"scan-build")
clean
mkdir -p "$BUILD_DIR"
pushed_build
exec $scanbuild cmake "$ROOT_DIR"
2020-07-10 20:41:46 +01:00
exec $scanbuild scan-build make -j 4
popd_build
2020-07-10 20:41:46 +01:00
;;
"memcheck")
2021-06-15 01:21:48 +01:00
memcheck "${@:2}"
2020-07-10 20:41:46 +01:00
;;
2021-04-06 00:21:43 +01:00
"tests")
clean
mkdir -p "$BUILD_DIR"
2020-07-10 20:41:46 +01:00
tests
2021-04-06 00:21:43 +01:00
run-tests
2020-07-10 20:41:46 +01:00
;;
"clean")
rm -rf "$BUILD_DIR"
2020-07-10 20:41:46 +01:00
;;
"full-build")
clean
mkdir -p "$BUILD_DIR"
2020-07-10 20:41:46 +01:00
build
tests
2021-04-06 00:21:43 +01:00
run-tests
2020-07-10 20:41:46 +01:00
memcheck
;;
*)
echo "Commands: "
echo "setup - Setup the githooks for devs"
2020-07-10 20:41:46 +01:00
echo "full-build - Build and test Serene."
echo "build - Build Serene from scratch in DEBUG mode."
echo "build-release - Build Serene from scratch in RELEASE mode."
2020-07-10 20:41:46 +01:00
echo "compile - reCompiles the project using the already exist cmake configuration"
2021-04-13 10:39:13 +01:00
echo "compile-and-tests - reCompiles the project using the already exist cmake configuration and runs the tests"
2020-07-10 20:41:46 +01:00
echo "run - Runs the serene executable"
echo "scan-build - Compiles serene with static analyzer"
echo "tests - Runs the test cases"
echo "memcheck - Runs the memcheck(valgrind) tool."
2020-07-10 20:41:46 +01:00
echo "clean - :D"
;;
esac