241 lines
7.0 KiB
Bash
Executable File
241 lines
7.0 KiB
Bash
Executable File
#! /bin/bash
|
|
# Feynman -- Wayland compositor for GNU Emacs
|
|
#
|
|
# Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, version 2.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Commentary
|
|
# -----------------------------------------------------------------------------
|
|
# This is the builder script for the Feynman project. It makes it easier to
|
|
# interact with the CMake build scripts.
|
|
#
|
|
# In order to define a subcommand all you need to do is to define a function
|
|
# with the following syntax:
|
|
#
|
|
# function subcommand-name() { ## DESCRIPTION
|
|
# .. subcommand body ..
|
|
# }
|
|
#
|
|
# Make sure to provid one line of DESCRIPTION for the subcommand and use two "#"
|
|
# characters to start the description following by a space. Otherwise, your
|
|
# subcommand won't be registered
|
|
#
|
|
## Verbos Mode
|
|
# In order to turn on the verbose mode for your build just invoke the builder script
|
|
# like:
|
|
#
|
|
# $ VERBOSE=ON ./builder build/
|
|
#
|
|
|
|
set -e
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Vars & Config
|
|
# -----------------------------------------------------------------------------
|
|
|
|
command=$1
|
|
VERSION="0.1.0"
|
|
|
|
EMACS_DEV=${EMACS_DEV:-$HOME/builds/emacs/2022-08-05/}
|
|
|
|
CC=$(which clang)
|
|
CXX=$(which clang++)
|
|
|
|
export CC
|
|
export CXX
|
|
|
|
# TODO: Add sloppiness to the cmake list file as well
|
|
export CCACHE_SLOPPINESS="pch_defines,time_macros"
|
|
|
|
export ASAN_OPTIONS=check_initialization_order=1
|
|
LSAN_OPTIONS=suppressions=$(pwd)/.ignore_sanitize
|
|
export LSAN_OPTIONS
|
|
export LDFLAGS="-fuse-ld=lld"
|
|
|
|
# The `builder` script is supposed to be run from the
|
|
# root of the source tree
|
|
ROOT_DIR=$(pwd)
|
|
BUILD_DIR=$ROOT_DIR/build
|
|
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
|
|
|
|
CMAKEARGS_DEBUG=("-DCMAKE_BUILD_TYPE=Debug")
|
|
CMAKEARGS=("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
|
|
"-DFEYNMAN_EMACS_DIR=$EMACS_DEV"
|
|
"-DFEYNMAN_CCACHE_DIR=$HOME/.ccache")
|
|
|
|
# shellcheck source=./scripts/utils.sh
|
|
source "$ME/scripts/utils.sh"
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Helper functions
|
|
# -----------------------------------------------------------------------------
|
|
|
|
function pushed_build() {
|
|
mkdir -p "$BUILD_DIR"
|
|
pushd "$BUILD_DIR" > /dev/null || return
|
|
}
|
|
|
|
|
|
function popd_build() {
|
|
popd > /dev/null || return
|
|
}
|
|
|
|
|
|
function build-gen() {
|
|
pushed_build
|
|
info "Running: "
|
|
info "cmake -G Ninja ${CMAKEARGS[*]} ${CMAKEARGS[*]}" "\"$*\" \"$ROOT_DIR\""
|
|
cmake -G Ninja "${CMAKEARGS[@]}" "${CMAKEARGS_DEBUG[@]}" "$*" "$ROOT_DIR"
|
|
popd_build
|
|
}
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Subcomaands
|
|
# -----------------------------------------------------------------------------
|
|
function compile() { ## Compiles the project using the generated build scripts
|
|
pushed_build
|
|
cmake --build .
|
|
popd_build
|
|
}
|
|
|
|
function build() { ## Builds the project by regenerating the build scripts
|
|
local cpus
|
|
|
|
clean
|
|
build-gen "$@"
|
|
pushed_build
|
|
|
|
cpus=$(nproc)
|
|
cmake --build . -j "$cpus"
|
|
|
|
popd_build
|
|
}
|
|
|
|
|
|
function build-tidy() { ## Builds the project using clang-tidy (It takes longer than usual)
|
|
build "-DFEYNMAN_ENABLE_TIDY=ON" "${@:2}"
|
|
}
|
|
|
|
function build-release() { ## Builds the project in "Release" mode
|
|
clean
|
|
pushed_build
|
|
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "${CMAKEARGS[@]}" "$ROOT_DIR"
|
|
cmake --build . --config Release
|
|
popd_build
|
|
}
|
|
|
|
function clean() { ## Cleans up the source dir and removes the build
|
|
rm -rf "$BUILD_DIR"
|
|
rm -rf "$(find . -iname '*~')"
|
|
}
|
|
|
|
function x() { ## Runs Xephyr for testing purposes
|
|
Xephyr -br -ac -noreset -screen 800x600 :1 &
|
|
}
|
|
|
|
function run() { ## Runs feynman inside Xephyr
|
|
#
|
|
DISPLAY=:1 EMACS_DEV=$EMACS_DEV "$BUILD_DIR/src/feynman-wm" "$@"
|
|
}
|
|
|
|
function d() { ## Runs the debugger
|
|
##settings set target.process.follow-fork-mode child
|
|
#lldb --source scripts/debugger_init "$BUILD_DIR/src/feynman-wm"
|
|
gdb --x scripts/debugger_init "$BUILD_DIR/src/feynman-wm"
|
|
}
|
|
|
|
|
|
function memcheck-feynman() { ## Runs `valgrind` to check `feynman` birany
|
|
export ASAN_FLAG=""
|
|
build
|
|
pushed_build
|
|
valgrind --tool=memcheck --leak-check=yes --trace-children=yes "$BUILD_DIR"/bin/feynman "$@"
|
|
popd_build
|
|
}
|
|
|
|
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
|
|
eval "$test_file ${*:2}"
|
|
fi
|
|
done
|
|
else
|
|
eval "$BUILD_DIR/$1/tests/$1Tests ${*:2}"
|
|
fi
|
|
}
|
|
|
|
function build-tests() { ## Generates and build the project including the test cases
|
|
clean
|
|
pushed_build
|
|
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DFEYNMAN_BUILD_TESTING=ON "$ROOT_DIR"
|
|
cmake --build .
|
|
popd_build
|
|
}
|
|
|
|
|
|
function setup() { ## Setup the working directory and make it ready for development
|
|
if command -v python3 >/dev/null 2>&1; then
|
|
pip install pre-commit
|
|
pre-commit install
|
|
else
|
|
error "Python is required to setup pre-commit"
|
|
fi
|
|
}
|
|
|
|
|
|
function scan-build() { ## Runs the `scan-build` utility to analyze the build process
|
|
clean
|
|
build-gen
|
|
pushed_build
|
|
# The scan-build utility scans the build for bugs checkout the man page
|
|
scan-build --force-analyze-debug-code --use-analyzer="$CC" cmake --build .
|
|
popd_build
|
|
}
|
|
|
|
function help() { ## Print out this help message
|
|
echo "Commands:"
|
|
grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' "$0" | \
|
|
sort | \
|
|
sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1:\2/' | \
|
|
awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}'
|
|
}
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Main logic
|
|
# -----------------------------------------------------------------------------
|
|
echo -e "\nFeynman Builder Version $VERSION"
|
|
echo -e "\nCopyright (C) 2022"
|
|
echo -e "Sameer Rahmani <lxsameer@gnu.org>"
|
|
echo -e "Feynman comes with ABSOLUTELY NO WARRANTY;"
|
|
echo -e "This is free software, and you are welcome"
|
|
echo -e "to redistribute it under certain conditions;"
|
|
echo -e "for details take a look at the LICENSE file.\n"
|
|
|
|
# Find the subcommand in the functions and run we find it.
|
|
for fn in $(fn-names); do
|
|
if [[ $fn == "$command" ]]; then
|
|
eval "$fn ${*:2}"
|
|
exit $?
|
|
fi
|
|
done
|
|
|
|
# If we couldn't find the command print out the help message
|
|
help
|