Fix the shellchecker issues in the builder
This commit is contained in:
parent
55dd688e17
commit
bb60d83dc6
125
builder
125
builder
|
@ -39,11 +39,17 @@ set -e
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
command=$1
|
command=$1
|
||||||
|
|
||||||
VERSION="0.4.0"
|
VERSION="0.4.0"
|
||||||
|
|
||||||
export CC=$(which clang)
|
# Serene subprojects. We use this array to run common tasks on all the projects
|
||||||
export CXX=$(which clang++)
|
# like running the test cases
|
||||||
|
PROJECTS=(libserene serenec serene-repl serene-tblgen)
|
||||||
|
|
||||||
|
CC=$(which clang)
|
||||||
|
CXX=$(which clang++)
|
||||||
|
|
||||||
|
export CC
|
||||||
|
export CXX
|
||||||
|
|
||||||
# TODO: Add sloppiness to the cmake list file as well
|
# TODO: Add sloppiness to the cmake list file as well
|
||||||
export CCACHE_SLOPPINESS="pch_defines,time_macros"
|
export CCACHE_SLOPPINESS="pch_defines,time_macros"
|
||||||
|
@ -67,16 +73,19 @@ CMAKEARGS=" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSERENE_CCACHE_DIR=$HOME/.ccache
|
||||||
# Helper functions
|
# Helper functions
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
function fn-names() {
|
function fn-names() {
|
||||||
grep -E '^function [0-9a-zA-Z_-]+\(\) \{ ## .*$$' $0 | sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1/'
|
grep -E '^function [0-9a-zA-Z_-]+\(\) \{ ## .*$$' "$0" | sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function gen_precompile_header_index() {
|
function gen_precompile_header_index() {
|
||||||
echo "// DO NOT EDIT THIS FILE: It is aute generated by './builder gen_precompile_index'" > ./include/serene_precompiles.h
|
{
|
||||||
echo "#ifndef SERENE_PRECOMPIL_H" >> ./include/serene_precompiles.h
|
echo "// DO NOT EDIT THIS FILE: It is aute generated by './builder gen_precompile_index'"
|
||||||
echo "#define SERENE_PRECOMPIL_H" >> ./include/serene_precompiles.h
|
echo "#ifndef SERENE_PRECOMPIL_H"
|
||||||
grep -oP "#include .llvm/.*" . -R|cut -d':' -f2|tail +2 >> ./include/serene_precompiles.h
|
echo "#define SERENE_PRECOMPIL_H"
|
||||||
grep -oP "#include .mlir/.*" . -R|cut -d':' -f2|tail +2 >> ./include/serene_precompiles.h
|
grep -oP "#include .llvm/.*" . -R|cut -d':' -f2|tail +2
|
||||||
echo "#endif" >> ./include/serene_precompiles.h
|
grep -oP "#include .mlir/.*" . -R|cut -d':' -f2|tail +2
|
||||||
|
echo "#endif"
|
||||||
|
} > ./include/serene_precompiles.h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,18 +94,42 @@ function pushed_build() {
|
||||||
pushd "$BUILD_DIR" > /dev/null || return
|
pushd "$BUILD_DIR" > /dev/null || return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function popd_build() {
|
function popd_build() {
|
||||||
popd > /dev/null || return
|
popd > /dev/null || return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function build-gen() {
|
function build-gen() {
|
||||||
pushed_build
|
pushed_build
|
||||||
echo "Running: "
|
info "Running: "
|
||||||
echo "cmake -G Ninja $CMAKEARGS $CMAKEARGS_DEBUG \"$@\" \"$ROOT_DIR\""
|
info "cmake -G Ninja $CMAKEARGS $CMAKEARGS_DEBUG \"$*\" \"$ROOT_DIR\""
|
||||||
cmake -G Ninja $CMAKEARGS $CMAKEARGS_DEBUG "$@" "$ROOT_DIR"
|
cmake -G Ninja "$CMAKEARGS" "$CMAKEARGS_DEBUG" "$*" "$ROOT_DIR"
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function info() {
|
||||||
|
if [ "$1" ]
|
||||||
|
then
|
||||||
|
echo -e "[\033[01;32mINFO\033[00m]: $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function error() {
|
||||||
|
if [ "$1" ]
|
||||||
|
then
|
||||||
|
echo -e "[\033[01;31mERR\033[00m]: $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function warn() {
|
||||||
|
if [ "$1" ]
|
||||||
|
then
|
||||||
|
echo -e "[\033[01;33mWARN\033[00m]: $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Subcomaands
|
# Subcomaands
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
@ -136,7 +169,7 @@ function build-release() { ## Builds the project in "Release" mode
|
||||||
|
|
||||||
function build-docs() { ## Builds the documentation of Serene
|
function build-docs() { ## Builds the documentation of Serene
|
||||||
clean
|
clean
|
||||||
pip install -r $ME/docs/requirements.txt
|
pip install -r "$ME/docs/requirements.txt"
|
||||||
pushed_build
|
pushed_build
|
||||||
cmake -G Ninja -DSERENE_ENABLE_DOCS=ON "$ROOT_DIR"
|
cmake -G Ninja -DSERENE_ENABLE_DOCS=ON "$ROOT_DIR"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
@ -144,12 +177,12 @@ function build-docs() { ## Builds the documentation of Serene
|
||||||
}
|
}
|
||||||
|
|
||||||
function serve-docs() { ## Serve the docs directory from build dir
|
function serve-docs() { ## Serve the docs directory from build dir
|
||||||
python -m http.server --directory $BUILD_DIR/docs/sphinx/
|
python -m http.server --directory "$BUILD_DIR/docs/sphinx/"
|
||||||
}
|
}
|
||||||
|
|
||||||
function clean() { ## Cleans up the source dir and removes the build
|
function clean() { ## Cleans up the source dir and removes the build
|
||||||
rm -rf "$BUILD_DIR"
|
rm -rf "$BUILD_DIR"
|
||||||
rm -rf $(find . -iname "*~")
|
rm -rf "$(find . -iname '*~')"
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() { ## Runs `serenec` and passes all the given aruguments to it
|
function run() { ## Runs `serenec` and passes all the given aruguments to it
|
||||||
|
@ -170,60 +203,78 @@ function memcheck-serene() { ## Runs `valgrind` to check `serenec` birany
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
function run-tests() { ## Runs all the test cases
|
function tests() { ## Runs all the test cases
|
||||||
|
if [[ "$1" == "all" || "$1" == "" ]]; then
|
||||||
|
info "Run the entire test suit"
|
||||||
|
for proj in "${PROJECTS[@]}"; do
|
||||||
|
local test_file="$BUILD_DIR/$proj/tests/${proj}Tests"
|
||||||
|
|
||||||
|
if [[ -f "$test_file" ]]; then
|
||||||
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
||||||
"$BUILD_DIR"/src/tests/tests
|
eval "$test_file" "${@:2}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
||||||
|
eval "$BUILD_DIR/$1/tests/$1Tests" "${@:2}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function tests() { ## Generates and build the project including the test cases
|
function build-tests() { ## Generates and build the project including the test cases
|
||||||
|
clean
|
||||||
pushed_build
|
pushed_build
|
||||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON "$ROOT_DIR"
|
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DSERENE_BUILD_TESTING=ON "$ROOT_DIR"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
function build-llvm-image() { ## Build the LLVM image that we use to build Serene's image
|
function build-llvm-image() { ## Build the LLVM image that we use to build Serene's image
|
||||||
|
# shellcheck source=/dev/null
|
||||||
source .env
|
source .env
|
||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
-f $ME/resources/docker/llvm/Dockerfile \
|
-f "$ME/resources/docker/llvm/Dockerfile" \
|
||||||
-t $REGISTRY/llvm:$1-$2 \
|
-t "$REGISTRY/llvm:$1-$2" \
|
||||||
--build-arg VERSION=$1 \
|
--build-arg VERSION="$1" \
|
||||||
.
|
.
|
||||||
}
|
}
|
||||||
|
|
||||||
function push-llvm-image() { ## Pushes the LLVM image to the registery
|
function push-llvm-image() { ## Pushes the LLVM image to the registery
|
||||||
|
# shellcheck source=/dev/null
|
||||||
source .env
|
source .env
|
||||||
|
|
||||||
docker login $REGISTRY -u $SERENE_REGISTERY_USER -p $SERENE_REGISTERY_PASS
|
docker login "$REGISTRY" -u "$SERENE_REGISTERY_USER" -p "$SERENE_REGISTERY_PASS"
|
||||||
docker push $REGISTRY/llvm:$1
|
docker push "$REGISTRY/llvm:$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function build-serene-image() { ## Build the Serene docker image for the current HEAD
|
function build-serene-image() { ## Build the Serene docker image for the current HEAD
|
||||||
|
# shellcheck source=/dev/null
|
||||||
source .env
|
source .env
|
||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
-f $ME/resources/docker/serene/Dockerfile \
|
-f "$ME/resources/docker/serene/Dockerfile" \
|
||||||
-t $REGISTRY/serene:$VERSION-$(git rev-parse HEAD) \
|
-t "$REGISTRY/serene:$VERSION-$(git rev-parse HEAD)" \
|
||||||
.
|
.
|
||||||
}
|
}
|
||||||
|
|
||||||
function release-serene-image() { ## Build and push the Serene docker image for the current HEAD in Release mode
|
function release-serene-image() { ## Build and push the Serene docker image for the current HEAD in Release mode
|
||||||
|
# shellcheck source=/dev/null
|
||||||
source .env
|
source .env
|
||||||
docker build \
|
docker build \
|
||||||
-f $ME/resources/docker/serene/Dockerfile \
|
-f "$ME/resources/docker/serene/Dockerfile" \
|
||||||
-t $REGISTRY/serene:$VERSION \
|
-t "$REGISTRY/serene:$VERSION" \
|
||||||
--build-arg TASK=build-release \
|
--build-arg TASK=build-release \
|
||||||
.
|
.
|
||||||
docker login $REGISTRY -u $SERENE_REGISTERY_USER -p $SERENE_REGISTERY_PASS
|
docker login "$REGISTRY" -u "$SERENE_REGISTERY_USER" -p "$SERENE_REGISTERY_PASS"
|
||||||
docker push $REGISTRY/serene:$VERSION
|
docker push "$REGISTRY/serene:$VERSION"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function setup() { ## Setup the working directory and make it ready for development
|
function setup() { ## Setup the working directory and make it ready for development
|
||||||
rm -rfv $ME/.git/hooks/pre-commit
|
rm -rfv "$ME/.git/hooks/pre-commit"
|
||||||
ln -s $ME/scripts/pre-commit $ME/.git/hooks/pre-commit
|
ln -s "$ME/scripts/pre-commit" "$ME/.git/hooks/pre-commit"
|
||||||
}
|
}
|
||||||
|
|
||||||
function scan-build() { ## Runs the `scan-build` utility to analyze the build process
|
function scan-build() { ## Runs the `scan-build` utility to analyze the build process
|
||||||
|
@ -231,13 +282,13 @@ function scan-build() { ## Runs the `scan-build` utility to analyze the build pr
|
||||||
build-gen
|
build-gen
|
||||||
pushed_build
|
pushed_build
|
||||||
# The scan-build utility scans the build for bugs checkout the man page
|
# The scan-build utility scans the build for bugs checkout the man page
|
||||||
scan-build --force-analyze-debug-code --use-analyzer=$(which clang) cmake --build .
|
scan-build --force-analyze-debug-code --use-analyzer="$CC" cmake --build .
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
function help() { ## Print out this help message
|
function help() { ## Print out this help message
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' $0 | \
|
grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' "$0" | \
|
||||||
sort | \
|
sort | \
|
||||||
sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1:\2/' | \
|
sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1:\2/' | \
|
||||||
awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}'
|
awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}'
|
||||||
|
@ -257,7 +308,7 @@ echo -e "for details take a look at the LICENSE file.\n"
|
||||||
# Find the subcommand in the functions and run we find it.
|
# Find the subcommand in the functions and run we find it.
|
||||||
for fn in $(fn-names); do
|
for fn in $(fn-names); do
|
||||||
if [[ $fn == "$command" ]]; then
|
if [[ $fn == "$command" ]]; then
|
||||||
eval "$fn ${@:2}"
|
eval "$fn" "${@:2}"
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue