From 681c39414547f76933bf1b3e901143d73d2ecec7 Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Tue, 7 Mar 2023 14:35:41 +0100 Subject: [PATCH] Allow fallback to common work directory --- wrath | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/wrath b/wrath index abba064..05a832e 100755 --- a/wrath +++ b/wrath @@ -16,13 +16,14 @@ # declare -g -A refs built parsed pids hashes lib group sources mainClass -declare -g run fetch scala scalac compiler repl esc overrideMain execClass +declare -g run fetch scala scalac compiler repl esc overrideMain execClass defaultDir declare -i columns group[dotty]="lampepfl" esc=$'\e' compiler="$(realpath scala)" columns=${COLUMNS:-116} +configFile="${XDG_CONFIG_HOME:-$HOME/.config}/wrath.conf" nonempty() { if [ "$2" = "" ] @@ -40,6 +41,7 @@ Builds a project with Wrath. Options: -c, --clean clean the target project -C, --deep-clean clean all targets + -d, --default look inside directory for dependencies -f, --fetch automatically fetch missing dependencies -F, --fetch-all automatically fetch missing dependencies and compiler -h, --help show this help message @@ -131,6 +133,15 @@ package() { jar cf "${jarFile}" "${args[@]}" } +readConfig() { + if [ "$defaultDir" = "" ] + then + if [ -e "$configFile" ] + then defaultDir="$(cat $configFile)" + fi + fi +} + readToml() { local file dir section IFS isMain buildModule buildComponent local -i lineNo @@ -249,18 +260,22 @@ build() { then root="$(realpath .)" else root="$(realpath "$buildModule")" fi - + IFS=' ' - + if [ ! -d "$root" ] then - if [ ! "$fetch" = "" ] - then - message "$buildModule" "$buildComponent" "Cloning Git repository" - fetch "$buildModule" + if [ -d "$defaultDir"/"$buildModule" ] + then root="$(realpath "$defaultDir"/"$buildModule")" else - message "$buildModule" "$buildComponent" "Module not found" - fail "$buildModule" "$buildComponent" "Try again with -f or create a symlink to $root." + if [ ! "$fetch" = "" ] + then + message "$buildModule" "$buildComponent" "Cloning Git repository" + fetch "$buildModule" + else + message "$buildModule" "$buildComponent" "Module not found" + fail "$buildModule" "$buildComponent" "Try again with -f or create a symlink to $root." + fi fi fi @@ -406,6 +421,10 @@ parseOpts() { -C|--deep-clean) clean="2" shift 1 ;; + -d|--default) + nonempty "$@" + defaultDir="$2" + shift 2 ;; -f|--fetch) fetch="1" shift 1 ;; @@ -455,6 +474,8 @@ checkTarget() { } parseOpts "$@" +gmessage "Reading global config" +readConfig gmessage "Starting build" readToml "$module" "$component" "build.wrath" 1