diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 3ee05d2c8c..a3a3190c0b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -75,6 +75,8 @@ You can link that script into a directory within your search `$PATH`. This allow * `build.sh -f` - Compile only * `build.sh -f -t` - Compile & test * `build.sh -u` - Update dependencies before compiling +* `build.sh -w` - Enter watch mode for automatic recompilation +* `build.sh -w -t` - Enter watch mode for automatic recompilation & running tests See `build.sh --help` for a full list of options and usage examples. diff --git a/hack/build.sh b/hack/build.sh index 6f5bbee348..5353ca4dfc 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -39,6 +39,11 @@ run() { exit 0 fi + if $(has_flag --watch -w); then + watch + # No exit, needs to be stopped with CTRL-C anyways + fi + if $(has_flag -u --update); then # Update dependencies update_deps @@ -105,6 +110,31 @@ generate_docs() { go run "./hack/generate-docs.go" "." } +watch() { + local command="./hack/build.sh --fast" + local notify_opts="--include cmd --include pkg --batch 500" + if $(has_flag --test -t); then + command="$command --test" + fi + if $(has_flag --verbose); then + notify_opts="$notify_opts --verbose" + fi + set +e + which xnotify >/dev/null 2>&1 + if [ $? -ne 0 ]; then + local green="" + local reset="" + + echo "🤷 Watch: Cannot find ${green}xnotify${reset}" + echo "🌏 Please download from ${green}https://github.com/AgentCosmic/xnotify/releases${reset} and install in \$PATH" + exit 1 + fi + set -e + + echo "🔁 Watch" + xnotify $notify_opts -- $command +} + # Dir where this script is located basedir() { # Default is current directory @@ -154,10 +184,12 @@ Usage: $(basename $BASH_SOURCE) [... options ...] with the following options: -f --fast Only compile (without formatting, testing, doc generation) --t --test Run tests when used with --fast +-t --test Run tests when used with --fast or --watch -u --update Update dependencies before compiling +-w --watch Watch for source changes and recompile in fast mode -h --help Display this help message - --verbose Verbose script output (set -x) + --verbose More output + --debug Debug information for this script (set -x) You can add a symbolic link to this build script into your PATH so that it can be called from everywhere. E.g.: @@ -169,10 +201,11 @@ Examples: * Compile, format, tests, docs: build.sh * Compile only: build.sh --fast * Compile with tests: build.sh -f -t +* Automatice recompilation: build.sh --watch EOT } -if $(has_flag --verbose); then +if $(has_flag --debug); then export PS4='+($(basename ${BASH_SOURCE[0]}):${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' set -x fi