From: Michael Wallner Date: Tue, 14 Jan 2014 16:24:50 +0000 (+0100) Subject: btrc & btrd X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=36ab11ad208509a177f3976333d0728069e06ee8;p=m6w6%2Fbtr btrc & btrd --- diff --git a/.gitignore b/.gitignore index 8d174c9..5c80847 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ missing Makefile config.log config.status +config.cache +btr-?.?.* diff --git a/Makefile.am b/Makefile.am index 3260af8..9efa5a9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,18 +1,4 @@ -dist_bin_SCRIPTS = bin/btr \ - bin/btr-irc-relay \ - bin/btr-irc-send +EXTRA_SCRIPTS = btrdir = $(prefix) -nobase_dist_btr_SCRIPTS = share/btr/build/pecl.mk \ - share/btr/build/make.mk \ - share/btr/build/gnu.mk \ - share/btr/build/php.mk \ - share/btr/build/composer.mk \ - share/btr/report/mail.mk \ - share/btr/report/twilio.mk \ - share/btr/report/notify-send.mk \ - share/btr/report/irc.mk \ - share/btr/source/cvs.mk \ - share/btr/source/git.mk \ - share/btr/source/svn.mk \ - share/btr/btr.sh \ - share/btr/irc.php +dist_bin_SCRIPTS = $(BTR_BIN) +nobase_dist_btr_SCRIPTS = $(BTR_SHARE) diff --git a/TODO.md b/TODO.md index 4b8ee4b..bbab2b0 100644 --- a/TODO.md +++ b/TODO.md @@ -10,6 +10,8 @@ * Mercurial Implement! +* Push/commit etc. hooks + # Build * CMake? diff --git a/bin/btr b/bin/btr index 6f303b7..a8a29a4 100755 --- a/bin/btr +++ b/bin/btr @@ -1,29 +1,21 @@ #!/bin/bash -export DATE=$(date +%Y%m%d%H%M%S) -export CPUS=${CPUS:-$(grep -c "^processor" /proc/cpuinfo)} +export BTR_BINDIR=$(realpath $(dirname $0)/) +export BTR_LIBDIR=$(realpath $(dirname $0)/../share/btr) +BTR_BANNER="Build, test & report. Simple and stupid." -export BINDIR=$(realpath $(dirname $0)/) -export LIBDIR=$(realpath $(dirname $0)/../share/btr) +. $BTR_LIBDIR/common.sh +. $BTR_LIBDIR/btr.sh -. $LIBDIR/btr.sh +btr-parseopts "$@" +btr-setup -QUIET=false -VERBOSE=false -FORCEYES=false - -parseopts "$@" -setup - -if $VERBOSE +if $BTR_VERBOSE then - show_conf - $FORCEYES || confirm "Everything setup. Do you want to continue?" || exit + btr-conf-show + btr-confirm "Everything setup. Do you want to continue?" fi -set -e -make -e $SILENT_FLAG -C $BTRDIR -f $LIBDIR/source/$SOURCE_RULES.mk -make -e $SILENT_FLAG -C $BTRDIR -f $LIBDIR/build/$BUILD_RULES.mk -make -e $SILENT_FLAG -C $BTRDIR -f $LIBDIR/report/$REPORT_RULES.mk +btr-run # vim: noet diff --git a/bin/btrc b/bin/btrc new file mode 100755 index 0000000..85634bd --- /dev/null +++ b/bin/btrc @@ -0,0 +1,28 @@ +#!/bin/bash + +export BTR_BINDIR=$(realpath $(dirname $0)/) +export BTR_LIBDIR=$(realpath $(dirname $0)/../share/btr) +BTR_BANNER="Control \`btrd\` daemons." + +. $BTR_LIBDIR/common.sh +. $BTR_LIBDIR/btrc.sh + +btrc-parseopts "$@" +btrc-setup + +case "$BTR_ACTION" in +status) + ncat --recv-only -U "$BTR_COMFILE" + ;; +cancel) + btrc-signal INT + ;; +run) + btrc-signal HUP + ;; +term) + btrc-signal TERM + ;; +esac + +# vim: noet diff --git a/bin/btrd b/bin/btrd new file mode 100755 index 0000000..055bd7b --- /dev/null +++ b/bin/btrd @@ -0,0 +1,26 @@ +#!/bin/bash + +export BTR_BINDIR=$(realpath $(dirname $0)/) +export BTR_LIBDIR=$(realpath $(dirname $0)/../share/btr) +BTR_BANNER="Run btr as background daemon receiving jobs for a repo." + +. $BTR_LIBDIR/common.sh +. $BTR_LIBDIR/btr.sh + +btr-parseopts "$@" +btr-setup + +if $BTR_VERBOSE +then + btr-conf-show + btr-confirm "Everything setup. Do you want to start the daemon?" +elif ! $BTR_QUIET +then + echo "Starting the daemon. Control with \`btrc $BTR_BUILD\`" +else + echo "$BUILD" +fi + +setsid $SHELL -c "$BTR_LIBDIR/btrd.sh &" + +# vim: noet diff --git a/configure.ac b/configure.ac index 0e51c87..f5f981f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,10 @@ -AC_INIT([btr], [1.0.0], [mike@php.net]) -AC_CONFIG_SRCDIR([share/btr/btr.sh]) +AC_INIT([btr], [0.4.0], [mike@php.net]) +AC_CONFIG_SRCDIR([./share/btr/btr.sh]) AM_INIT_AUTOMAKE([foreign]) AM_SILENT_RULES([yes]) +BTR_BIN='$(echo $$abs_srcdir/bin/*)' +BTR_SHARE='$(echo $$abs_srcdir/share/{*,*/*}/*.*)' +AC_SUBST([BTR_BIN], [$BTR_BIN]) +AC_SUBST([BTR_SHARE], [$BTR_SHARE]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/curl.example.conf b/curl.example.conf index 0039ed6..3f7c677 100644 --- a/curl.example.conf +++ b/curl.example.conf @@ -1,5 +1,5 @@ -VERBOSE=true -SOURCE_RULES=git -SOURCE_ARGS=https://github.com/bagder/curl.git -BUILD_RULES=gnu -REPORT_RULES=mail +BTR_VERBOSE=true +BTR_SOURCE_RULES=git +BTR_SOURCE_ARGS=https://github.com/bagder/curl.git +BTR_BUILD_RULES=gnu +BTR_REPORT_RULES=mail diff --git a/php.example.conf b/php.example.conf index 4a1bd10..c52ad8b 100644 --- a/php.example.conf +++ b/php.example.conf @@ -1,7 +1,7 @@ -SOURCE_RULES=git -SOURCE_ARGS=git@php.net:php/php-src.git -BRANCH=PHP-5.5 -BUILD_RULES=php -BUILD_ARGS=--enable-debug -TEST_ARGS=-m -REPORT_RULES=notify-send +BTR_SOURCE_RULES=git +BTR_SOURCE_ARGS=git@php.net:php/php-src.git +BTR_BRANCH=PHP-5.5 +BTR_BUILD_RULES=php +BTR_BUILD_ARGS=--enable-debug +BTR_TEST_ARGS=-m +BTR_REPORT_RULES=notify-send diff --git a/share/btr/btr.sh b/share/btr/btr.sh index d0db095..91bd801 100755 --- a/share/btr/btr.sh +++ b/share/btr/btr.sh @@ -1,7 +1,7 @@ #!/bin/sh -function help { - echo "btr v0.3.0, (c) Michael Wallner " +function btr-help { + btr-banner echo echo "Usage: $(basename $0) [-hyvqcC] []" echo @@ -34,7 +34,7 @@ function help { for ruleset in source build report do printf " %10s: %s\n" $ruleset \ - "$(find "$LIBDIR/$ruleset" -name '*.mk' -exec basename {} .mk \; | sort | xargs)" + "$(find "$BTR_LIBDIR/$ruleset" -name '*.mk' -exec basename {} .mk \; | sort | xargs)" done echo echo " Examples:" @@ -54,8 +54,9 @@ function help { echo exit } +export -f btr-help -function parseopts { +function btr-parseopts { local shortoptions="hvqycCf:T:B:D:S:s:b:r:" local longoptions="help,verbose,quiet,yes,clean,vcsclean,config:,test:,branch:,directory:,suffix:,source:,build:,report:" local options=$(getopt \ @@ -74,24 +75,24 @@ function parseopts { do case "$1" in -h|--help) - help + btr-help ;; -v|--verbose) - QUIET=false - VERBOSE=true + BTR_QUIET=false + BTR_VERBOSE=true ;; -q|--quiet) - QUIET=true - VERBOSE=false + BTR_QUIET=true + BTR_VERBOSE=false ;; -y|--yes) - FORCEYES=true + BTR_FORCEYES=true ;; -c|--clean) - BUILD_CLEAN=true + BTR_BUILD_CLEAN=true ;; -C|--vcsclean) - SOURCE_CLEAN=true + BTR_SOURCE_CLEAN=true ;; #### -f|--config) @@ -100,46 +101,46 @@ function parseopts { ;; #### -B|--branch) - BRANCH="$2" + BTR_BRANCH="$2" shift ;; -D|--directory) - BTRDIR="$2" + BTR_RUNDIR="$2" shift ;; -S|--suffix) - SUFFIX="$2" + BTR_SUFFIX="$2" shift ;; -T|--test) - TEST_ARGS="$2" + BTR_TEST_ARGS="$2" shift ;; #### -s|--source) case "$2" in git*) - test -z "$BRANCH" && BRANCH=master + test -z "$BTR_BRANCH" && BTR_BRANCH=master ;; svn*) - test -z "$BRANCH" && BRANCH=trunk + test -z "$BTR_BRANCH" && BTR_BRANCH=trunk ;; cvs*) - test -z "$BRANCH" && BRANCH=HEAD + test -z "$BTR_BRANCH" && BTR_BRANCH=HEAD ;; esac - SOURCE_RULES="$(cut -d= -f1 <<<$2)" - SOURCE_ARGS="$(cut -s -d= -f2- <<<$2)" + BTR_SOURCE_RULES="$(cut -d= -f1 <<<$2)" + BTR_SOURCE_ARGS="$(cut -s -d= -f2- <<<$2)" shift ;; -b|--build) - BUILD_RULES="$(cut -d= -f1 <<<$2)" - BUILD_ARGS="$(cut -s -d= -f2- <<<$2)" + BTR_BUILD_RULES="$(cut -d= -f1 <<<$2)" + BTR_BUILD_ARGS="$(cut -s -d= -f2- <<<$2)" shift ;; -r|--report) - REPORT_RULES="$(cut -d= -f1 <<<$2)" - REPORT_ARGS="$(cut -s -d= -f2- <<<$2)" + BTR_REPORT_RULES="$(cut -d= -f1 <<<$2)" + BTR_REPORT_ARGS="$(cut -s -d= -f2- <<<$2)" shift ;; #### @@ -147,7 +148,7 @@ function parseopts { # legacy if test "$2" then - SOURCE_ARGS="$2" + BTR_SOURCE_ARGS="$2" fi shift ;; @@ -155,122 +156,107 @@ function parseopts { shift done } +export -f btr-parseopts -function error { - echo "$@" >&2 - exit -} - -function setup { - if test -z "$SOURCE_RULES" -o -z "$BUILD_RULES" -o -z "$REPORT_RULES" +function btr-setup { + if test -z "$BTR_SOURCE_RULES" -o -z "$BTR_BUILD_RULES" -o -z "$BTR_REPORT_RULES" then - help + btr-help fi - if $VERBOSE - then - QUIET_FLAG= - SILENT_FLAG= - VERBOSE_FLAG="-v" - SAY="echo; echo" - elif $QUIET - then - QUIET_FLAG="-q" - SILENT_FLAG="-s" - VERBOSE_FLAG= - SAY="@true" - else - QUIET_FLAG= - SILENT_FLAG="-s" - VERBOSE_FLAG= - SAY="@echo" - fi - - export QUIET VERBOSE FORCEYES QUIET_FLAG SILENT_FLAG VERBOSE_FLAG SAY - - if test -z "$BTRDIR" - then - export BTRDIR="/tmp/btr" - else - export BTRDIR=$(realpath "$BTRDIR") - fi - - mkdir -p "$BTRDIR" || error "Could not create $BTRDIR" + btr-setup-verbosity true + btr-setup-rundir - - export SOURCE_RULES BUILD_RULES REPORT_RULES - test -z "$SOURCE_ARGS" || export SOURCE_ARGS - test -z "$SOURCE_CLEAN" || export SOURCE_CLEAN - test -z "$BUILD_ARGS" || export BUILD_ARGS - test -z "$BUILD_CLEAN" || export BUILD_CLEAN - test -z "$TEST_ARGS" || export TEST_ARGS - test -z "$REPORT_ARGS" || export REPORT_ARGS - REPO=$(basename $(sed -re 's~^.*[/:#]~~' <<<"$SOURCE_ARGS") .git) - SAFE_BRANCH=$(tr ":" "_" <<<$(basename "$BRANCH")) - export REPO BRANCH SAFE_BRANCH + export BTR_SOURCE_RULES BTR_BUILD_RULES BTR_REPORT_RULES + test -z "$BTR_SOURCE_ARGS" || export BTR_SOURCE_ARGS + test -z "$BTR_SOURCE_CLEAN" || export BTR_SOURCE_CLEAN + test -z "$BTR_BUILD_ARGS" || export BTR_BUILD_ARGS + test -z "$BTR_BUILD_CLEAN" || export BTR_BUILD_CLEAN + test -z "$BTR_TEST_ARGS" || export BTR_TEST_ARGS + test -z "$BTR_REPORT_ARGS" || export BTR_REPORT_ARGS + BTR_REPO=$(basename $(sed -re 's~^.*[/:#]~~' <<<"$BTR_SOURCE_ARGS") .git) + BTR_SAFE_BRANCH=$(tr ":/" "_" <<<$(basename "$BTR_BRANCH")) + export BTR_REPO BTR_BRANCH BTR_SAFE_BRANCH - if test -z "$SUFFIX" + if test -z "$BTR_SUFFIX" then - export BUILD="$REPO@$SAFE_BRANCH" + export BTR_BUILD="$BTR_REPO@$BTR_SAFE_BRANCH" else - export BUILD="$REPO@$SAFE_BRANCH-$SUFFIX" + export BTR_BUILD="$BTR_REPO@$BTR_SAFE_BRANCH-$BTR_SUFFIX" fi - export CLEAN_DIR="btr+clean-$REPO" - export BRANCH_DIR="btr+branch-$REPO@$SAFE_BRANCH" - export BUILD_DIR="btr+build-$BUILD" - export CONFIG_REPORT="btr+config-$BUILD-$DATE" - export BUILD_REPORT="btr+build-$BUILD-$DATE" - export TEST_REPORT="btr+tests-$BUILD-$DATE" - export LAST_REPORT=$(basename $(ls -t "$BTRDIR/btr+tests-$BUILD"* 2>/dev/null | head -n1) 2>/dev/null) - export REPORT="btr+report-$BUILD-$DATE" + export BTR_REPO_DIR="$BTR_REPO" + export BTR_BRANCH_DIR="$BTR_BUILD/checkout" + export BTR_BUILD_DIR="$BTR_BUILD/build" + export BTR_LOG_DIR="$BTR_BUILD/log" + export BTR_CONFIG_REPORT="$BTR_LOG_DIR/config@$DATE.log" + export BTR_BUILD_REPORT="$BTR_LOG_DIR/build@$DATE.log" + export BTR_TEST_REPORT="$BTR_LOG_DIR/test@$DATE.log" + export BTR_LAST_REPORT=$(basename $(ls -t "$BTR_RUNDIR/$BTR_LOG_DIR/test@"* 2>/dev/null | head -n1) 2>/dev/null) + export BTR_REPORT="$BTR_LOG_DIR/report@$DATE.log" } +export -f btr-setup -function show_conf { - echo - echo "Configuration:" - echo "==============" +function btr-conf-dump { + echo "BTR_QUIET='$BTR_QUIET'" + echo "BTR_VERBOSE='$BTR_VEROSE'" + echo "BTR_FORCEYES='$BTR_FORCEYES'" + echo "BTR_BRANCH='$BTR_BRANCH'" + echo "BTR_SUFFIX='$BTR_SUFFIX'" + echo "BTR_RUNDIR='$BTR_RUNDIR'" + echo "BTR_SOURCE_RULES='$BTR_SOURCE_RULES'" + test ${BTR_SOURCE_ARGS+defined} && echo "BTR_SOURCE_ARGS='$BTR_SOURCE_ARGS'" + test ${BTR_SOURC_CLEAN+defined} && echo "BTR_SOURCE_CLEAN='$BTR_SOURCE_CLEAN'" + echo "BTR_BUILD_RULES='$BTR_BUILD_RULES'" + test ${BTR_BUILD_ARGS+defined} && echo "BTR_BUILD_ARGS='$BTR_BUILD_ARGS'" + test ${BTR_BUILD_CLEAN+defined} && echo "BTR_BUILD_CLEAN='$BTR_BUILD_CLEAN'" + test ${BTR_TEST_ARGS+defined} && echo "BTR_TEST_ARGS='$BTR_TEST_ARGS'" + echo "BTR_REPORT_RULES='$BTR_REPORT_RULES'" + test ${BTR_REPORT_ARGS+defined} && echo "BTR_REPORT_ARGS='$BTR_REPORT_ARGS'" +} +export -f btr-conf-dump + +function btr-conf-show { echo - echo "BTRDIR = $BTRDIR" - echo "BINDIR = $BINDIR" - echo "LIBDIR = $LIBDIR" + echo "# Configuration:" echo - echo "SOURCE_RULES = $SOURCE_RULES" - echo "SOURCE_ARGS = $SOURCE_ARGS" - echo "SOURCE_CLEAN = $SOURCE_CLEAN" - echo "BUILD_RULES = $BUILD_RULES" - echo "BUILD_ARGS = $BUILD_ARGS" - echo "BUILD_CLEAN = $BUILD_CLEAN" - echo "TEST_ARGS = $TEST_ARGS" - echo "REPORT_RULES = $REPORT_RULES" - echo "REPORT_ARGS = $REPORT_ARGS" + echo "BTR_RUNDIR = $BTR_RUNDIR" + echo "BTR_BINDIR = $BTR_BINDIR" + echo "BTR_LIBDIR = $BTR_LIBDIR" echo - echo "REPO = $REPO" - echo "BRANCH = $BRANCH" - echo "SAFE_BRANCH = $SAFE_BRANCH" + echo "BTR_SOURCE_RULES = $BTR_SOURCE_RULES" + echo "BTR_SOURCE_ARGS = $BTR_SOURCE_ARGS" + echo "BTR_SOURCE_CLEAN = $BTR_SOURCE_CLEAN" + echo "BTR_BUILD_RULES = $BTR_BUILD_RULES" + echo "BTR_BUILD_ARGS = $BTR_BUILD_ARGS" + echo "BTR_BUILD_CLEAN = $BTR_BUILD_CLEAN" + echo "BTR_TEST_ARGS = $BTR_TEST_ARGS" + echo "BTR_REPORT_RULES = $BTR_REPORT_RULES" + echo "BTR_REPORT_ARGS = $BTR_REPORT_ARGS" + echo "BTR_REPO = $BTR_REPO" + echo "BTR_BRANCH = $BTR_BRANCH" + echo "BTR_SAFE_BRANCH = $BTR_SAFE_BRANCH" + echo "BTR_BUILD = $BTR_BUILD" echo - echo "CLEAN_DIR = $CLEAN_DIR" - echo "BRANCH_DIR = $BRANCH_DIR" - echo "BUILD_DIR = $BUILD_DIR" - echo "CONFIG_REPORT = $CONFIG_REPORT" - echo "BUILD_REPORT = $BUILD_REPORT" - echo "TEST_REPORT = $TEST_REPORT" - echo "LAST_REPORT = $LAST_REPORT" + echo "BTR_REPO_DIR = $BTR_REPO_DIR" + echo "BTR_BRANCH_DIR = $BTR_BRANCH_DIR" + echo "BTR_BUILD_DIR = $BTR_BUILD_DIR" + echo "BTR_LOG_DIR = $BTR_LOG_DIR" + echo "BTR_CONFIG_REPORT = $BTR_CONFIG_REPORT" + echo "BTR_BUILD_REPORT = $BTR_BUILD_REPORT" + echo "BTR_TEST_REPORT = $BTR_TEST_REPORT" + echo "BTR_LAST_REPORT = $BTR_LAST_REPORT" echo } +export -f btr-conf-show -function confirm { - local CONTINUE - echo -n "$1 (y/N) " - read -r CONTINUE - case $CONTINUE in - y*|Y*) - echo - ;; - *) - exit -1 - ;; - esac +function btr-run { + set -e + make -e $BTR_SILENT_FLAG -C $BTR_RUNDIR -f $BTR_LIBDIR/source/$BTR_SOURCE_RULES.mk + make -e $BTR_SILENT_FLAG -C $BTR_RUNDIR -f $BTR_LIBDIR/build/$BTR_BUILD_RULES.mk + make -e $BTR_SILENT_FLAG -C $BTR_RUNDIR -f $BTR_LIBDIR/report/$BTR_REPORT_RULES.mk + set +e } +export -f btr-run # vim: noet diff --git a/share/btr/btrc.sh b/share/btr/btrc.sh new file mode 100644 index 0000000..703a909 --- /dev/null +++ b/share/btr/btrc.sh @@ -0,0 +1,159 @@ +#!/bin/bash + +function btrc-help { + btr-banner + echo + echo "Usage: $(basename $0) [-hyvq] [] [action] " + echo + echo " -h, --help Display this help" + echo " -y, --yes Always assume yes" + echo " -v, --verbose Be more verbose" + echo " -q, --quiet Be more quiet" + echo + echo " Options:" + echo " -D, --directory=" + echo " Use this directory as work root" + echo + echo " Actions:" + echo " s[tatus] Show the status of the build" + echo " r[un] Make a BTR run" + echo " c[ancel] Cancel any currently running BTR job" + echo " t[erminate] Terminate the BTR daemon" + echo + echo " Arguments:" + echo " The build id of the \`btrd\` daemon, usually" + echo " something like \$repository@\$branch[-\$suffix]." + echo + exit +} +export -f btrc-help + +function btrc-parseargs { + while test $# -gt 0 + do + case "$1" in + s|st|sta|stat|statu|status) + BTR_ACTION=status + ;; + r|ru|run) + BTR_ACTION=run + ;; + c|ca|can|cancel) + BTR_ACTION=cancel + ;; + t|te|ter|term|termi|termin|termina|terminat|terminate) + BTR_ACTION=term + ;; + *) + if test -z "$BTR_BUILD" + then + BTR_BUILD="$1" + else + error "Unknown action: '$BTR_BUILD' for build id '$1'!" + fi + ;; + esac + shift + done +} + +function btrc-parseopts { + local shortoptions="hvqyD:" + local longoptions="help,verbose,quiet,yes,directory:" + local options=$(getopt \ + --options "$shortoptions" \ + --longoptions "$longoptions" \ + -- "$@" \ + ) + + if test $? -ne 0 ; then + btrc-help + fi + + eval set -- "$options" + + while test $# -gt 1 + do + case "$1" in + -h|--help) + btrc-help + ;; + -y|--yes) + BTR_FORCEYES=true + ;; + -v|--verbose) + BTR_VERBOSE=true + BTR_QUIET=false + ;; + -q|--quiet) + BTR_QUIET=true + BTR_VERBOSE=false + ;; + # + -d|--directory) + BTR_RUNDIR="$2" + shift + ;; + # + --) + shift + btrc-parseargs "$@" + esac + shift + done +} +export -f btrc-parseopts + +function btrc-setup { + if test -z "$BTR_BUILD" + then + btrc-help + fi + + if test -z "$BTR_ACTION" + then + BTR_ACTION=status + fi + + btr-setup-rundir + btr-setup-verbosity + + BTR_PIDFILE="$BTR_RUNDIR/$BTR_BUILD.pid" + BTR_LOGFILE="$BTR_RUNDIR/$BTR_BUILD.log" + BTR_COMFILE="$BTR_RUNDIR/$BTR_BUILD.socket" + + if test -r "$BTR_PIDFILE" + then + export BTR_PIDFILE BTR_LOGFILE BTR_COMFILE + else + if test -e "$BTR_LOGFILE" + then + cat "$BTR_LOGFILE" + echo + fi + error "Could not find pid file of btr daemon for '$BTR_BUILD' in $BTR_RUNDIR." + fi +} +export -f btrc-setup + +function btrc-signal { + local sig=$1 + local pid=$(cat "$BTR_PIDFILE") + kill -s $sig $pid + kill -s CONT $pid + case "$sig" in + TERM|SIGTERM|15) + $SAY -n "Waiting for the daemon to shutdown..." + while kill -s 0 $pid &>/dev/null + do + $SAY -n "." + sleep .1 + done + $SAY " Done, bye." + ;; + esac +} +export -f btrc-signal + + +# vim: noet diff --git a/share/btr/btrd.sh b/share/btr/btrd.sh new file mode 100755 index 0000000..ca9f55c --- /dev/null +++ b/share/btr/btrd.sh @@ -0,0 +1,126 @@ +#!/bin/bash + +function btrd-start { + btrd-cancel + DATE=$(date +%Y%m%d%H%M%S) + btr-setup + btr-run & + BTR_WORKER=$! +} +export -f btrd-start + +function btrd-cancel { + if btrd-worker-started + then + kill $BTR_WORKER + wait $BTR_WORKER + fi + BTR_WORKER=0 +} +export -f btrd-cancel + +function btrd-stop { + BTR_DAEMON=false +} +export -f btrd-stop + +function btrd-ctime { + stat -c %y "$1" +} +export -f btrd-ctime + +function btrd-fsize { + local bytes=$(stat -c %s "$1") +} +export -f btrd-fsize + +function btrd-status { + echo "BTR_BUILD='$BTR_BUILD'" + echo "BTR_SERVER='$BTR_SERVER'" + echo "BTR_PIDFILE='$BTR_PIDFILE'" + echo "BTR_LOGFILE='$BTR_LOGFILE'" + echo "BTR_COMFILE='$BTR_COMFILE'" +} +export -f btrd-status + +function btrd-logrotate { + local i=1 + local f="$BTR_LOGFILE" + + if test -e "$f" + then + while test -e "$f.$i" + do + i=$((i+1)) + done + mv "$f" "$f.$i" + fi + +} +export -f btrd-logrotate + +function btrd-worker-started { + test "$BTR_WORKER" -gt 1 +} +export -f btrd-worker-started + +function btrd-worker-running { + kill -s 0 $BTR_WORKER +} +export -f btrd-worker-running + +function btrd-worker-reap { + wait $BTR_WORKER + BTR_WORKER=0 +} +export -f btrd-worker-reap + +function btrd-worker-kill { + kill $BTR_WORKER +} +export -f btrd-worker-kill + +BTR_DAEMON=true +BTR_WORKER=0 +BTR_SERVER=0 +BTR_PIDFILE="$BTR_RUNDIR/$BTR_BUILD.pid" +BTR_LOGFILE="$BTR_RUNDIR/$BTR_BUILD.log" +BTR_COMFILE="$BTR_RUNDIR/$BTR_BUILD.socket" + +export BTR_DAEMON BTR_WORKER BTR_SERVER BTR_PIDFILE BTR_LOGFILE BTR_COMFILE + +btrd-logrotate + +exec >"$BTR_LOGFILE" 2>&1 +echo $$ >"$BTR_PIDFILE" + +ncat -lkU -c btrd-status "$BTR_COMFILE" & +BTR_SERVER=$! + +trap btrd-start HUP +trap btrd-cancel INT +trap btrd-stop TERM + +while $BTR_DAEMON +do + if btrd-worker-started && btrd-worker-running + then + btrd-worker-reap + else + kill -s STOP $$ + fi +done + +btrd-cancel + +if test "$BTR_SERVER" -gt 1 +then + kill $BTR_SERVER + wait $BTR_SERVER +fi + +test -e "$BTR_PIDFILE" && rm "$BTR_PIDFILE" +test -e "$BTR_LOGFILE" && rm "$BTR_LOGFILE" +test -S "$BTR_COMFILE" && rm "$BTR_COMFILE" + +# vim: noet diff --git a/share/btr/build/composer.mk b/share/btr/build/composer.mk index f08e8e2..ce190d0 100644 --- a/share/btr/build/composer.mk +++ b/share/btr/build/composer.mk @@ -1,29 +1,29 @@ -BUILD_CLEAN=false -BUILD_ARGS= install --dev -TEST_ARGS= --strict --coverage-text +BTR_BUILD_CLEAN=false +BTR_BUILD_ARGS= install --dev +BTR_TEST_ARGS= --strict --coverage-text .PHONY: all clean .SUFFIXES: -all: clean $(REPORT) - $(SAY) "Result: $$(cat $(REPORT))" +all: clean $(BTR_REPORT) + $(SAY) "Result: $$(cat $(BTR_REPORT))" -clean: $(CONFIG_REPORT) - if $(BUILD_CLEAN); \ +clean: $(BTR_CONFIG_REPORT) + if $(BTR_BUILD_CLEAN); \ then \ - cd $(BUILD_DIR) && \ + cd $(BTR_BUILD_DIR) && \ rm -rf vendor; \ fi; -$(REPORT): $(TEST_REPORT) +$(BTR_REPORT): $(BTR_TEST_REPORT) @( \ - TESTS_PASSED=$$(grep -Pc '^ok \d+' < $(TEST_REPORT)); \ - TESTS_FAILED=$$(grep -Pc '^not ok \d+' < $(TEST_REPORT)); \ + TESTS_PASSED=$$(grep -Pc '^ok \d+' < $(BTR_TEST_REPORT)); \ + TESTS_FAILED=$$(grep -Pc '^not ok \d+' < $(BTR_TEST_REPORT)); \ \ printf "%d/%d" $$TESTS_PASSED $$TESTS_FAILED >$@; \ - if test -s "$(LAST_REPORT)"; then \ - LAST_PASSED=$$(grep -Pc '^ok \d+' < $(LAST_REPORT)); \ - LAST_FAILED=$$(grep -Pc '^not ok \d+' < $(LAST_REPORT)); \ + if test -s "$(BTR_LAST_REPORT)"; then \ + LAST_PASSED=$$(grep -Pc '^ok \d+' < $(BTR_LAST_REPORT)); \ + LAST_FAILED=$$(grep -Pc '^not ok \d+' < $(BTR_LAST_REPORT)); \ DIFF_PASSED=$$(bc <<<"$$TESTS_PASSED - $$LAST_PASSED"); \ DIFF_FAILED=$$(bc <<<"$$TESTS_FAILED - $$LAST_FAILED"); \ printf " %+d/%+d" $$DIFF_PASSED $$DIFF_FAILED >>$@; \ @@ -31,36 +31,43 @@ $(REPORT): $(TEST_REPORT) printf "\n" >>$@; \ ) -$(TEST_REPORT): $(BUILD_REPORT) +$(BTR_TEST_REPORT): $(BTR_BUILD_REPORT) $(SAY) "Running unit tests..." - cd $(BUILD_DIR) && \ - phpunit --tap $(TEST_ARGS) . >../$@ + (cd $(BTR_BUILD_DIR) && \ + phpunit --tap $(BTR_TEST_ARGS) . \ + ) >$@ -$(BUILD_REPORT): $(CONFIG_REPORT) $(BUILD_DIR)/composer.lock +$(BTR_BUILD_REPORT): $(BTR_CONFIG_REPORT) $(BTR_BUILD_DIR)/composer.lock $(SAY) "Installing dependencies..." - cd $(BUILD_DIR) && \ - ./composer.phar -n --no-ansi $(QUIET_FLAG) $(VERBOSE_FLAG) $(BUILD_ARGS) \ - >../$@ + (cd $(BTR_BUILD_DIR) && \ + ./composer.phar -n --no-ansi $(BTR_QUIET_FLAG) $(BTR_VERBOSE_FLAG) $(BTR_BUILD_ARGS) \ + ) >$@ -$(CONFIG_REPORT): $(BUILD_DIR)/composer.json $(BUILD_DIR)/composer.phar - touch $(CONFIG_REPORT) +$(BTR_CONFIG_REPORT): $(BTR_BUILD_DIR)/composer.json $(BTR_BUILD_DIR)/composer.phar | $(BTR_LOG_DIR) + touch $@ -$(BUILD_DIR)/composer.phar: +$(BTR_BUILD_DIR): + mkdir -p $@ + +$(BTR_LOG_DIR): + mkdir -p $@ + +$(BTR_BUILD_DIR)/composer.phar: | $(BTR_BUILD_DIR) $(BTR_LOG_DIR) $(SAY) "Orchestrating composer..." - @cd $(BUILD_DIR) && ( \ + (cd $(BTR_BUILD_DIR) && \ COMPOSER=$$(command -v composer); \ if test $$? -eq 0; \ then \ ln -s $$COMPOSER composer.phar; \ else \ - curl $(SILENT_FLAG) -S http://getcomposer.org/installer | php; \ + curl $(BTR_SILENT_FLAG) -S http://getcomposer.org/installer | php; \ fi; \ - ) >>$(CONFIG_REPORT) + ) >>$(BTR_CONFIG_REPORT) -$(BUILD_DIR)/composer.json: $(BRANCH_DIR)/composer.json - rsync $(QUIET_FLAG) $(VERBOSE_FLAG) -a --delete $(BRANCH_DIR)/ $(BUILD_DIR)/ \ - >> $(CONFIG_REPORT) +$(BTR_BUILD_DIR)/composer.json: $(BTR_BRANCH_DIR)/composer.json | $(BTR_BUILD_DIR) $(BTR_LOG_DIR) + rsync $(BTR_QUIET_FLAG) $(BTR_VERBOSE_FLAG) -a --delete $(BTR_BRANCH_DIR)/ $(BTR_BUILD_DIR)/ \ + >>$(BTR_CONFIG_REPORT) -$(BUILD_DIR)/composer.lock: $(BUILD_DIR)/composer.json $(BUILD_DIR)/composer.phar +$(BTR_BUILD_DIR)/composer.lock: $(BTR_BUILD_DIR)/composer.json $(BTR_BUILD_DIR)/composer.phar # vim: noet diff --git a/share/btr/build/gnu.mk b/share/btr/build/gnu.mk index 8dc05e3..0047ab7 100644 --- a/share/btr/build/gnu.mk +++ b/share/btr/build/gnu.mk @@ -1,52 +1,55 @@ -BUILD_CLEAN=false -BUILD_ARGS= -TEST_ARGS= +BTR_BUILD_CLEAN=false +BTR_BUILD_ARGS= +BTR_TEST_ARGS= .PHONY: all clean .SUFFIXES: -CONFIGS=$(wildcard $(BRANCH_DIR)/configure.*) +CONFIGS=$(wildcard $(BTR_BRANCH_DIR)/configure.*) -all: clean $(REPORT) - $(SAY) "Result: $$(cat $(REPORT))" +all: clean $(BTR_REPORT) + $(SAY) "Result: $$(cat $(BTR_REPORT))" -clean: $(CONFIG_REPORT) - if $(BUILD_CLEAN); \ +clean: $(BTR_CONFIG_REPORT) + if $(BTR_BUILD_CLEAN); \ then \ - cd $(BUILD_DIR) && \ - make $(SILENT_FLAG) clean; \ + cd $(BTR_BUILD_DIR) && \ + make $(BTR_SILENT_FLAG) clean; \ fi; -$(REPORT): $(TEST_REPORT) - if test -z "$(LAST_REPORT)"; then \ +$(BTR_REPORT): $(BTR_TEST_REPORT) + if test -z "$(BTR_LAST_REPORT)"; then \ echo 0; \ - elif test -s "$(LAST_REPORT)" -o -s "$(TEST_REPORT)"; then \ - cmp $(LAST_REPORT) $(TEST_REPORT) 2>&1 || true; \ + elif test -s "$(BTR_LAST_REPORT)" -o -s "$(BTR_TEST_REPORT)"; then \ + cmp $(BTR_LAST_REPORT) $(BTR_TEST_REPORT) 2>&1 || true; \ else \ echo 0; \ fi; -$(TEST_REPORT): $(BUILD_REPORT) +$(BTR_TEST_REPORT): $(BTR_BUILD_REPORT) $(SAY) "Running checks..." - cd $(BUILD_DIR) && \ - make check $(TEST_ARGS) >../$@ 2>&1 + cd $(BTR_BUILD_DIR) && \ + make check $(BTR_TEST_ARGS) >../$@ 2>&1 -$(BUILD_REPORT): $(CONFIG_REPORT) +$(BTR_BUILD_REPORT): $(BTR_CONFIG_REPORT) $(SAY) "Making build..." - cd $(BUILD_DIR) && \ + cd $(BTR_BUILD_DIR) && \ make -j $(CPUS) >../$@ 2>&1 -$(CONFIG_REPORT): $(BRANCH_DIR)/configure $(BUILD_DIR) +$(BTR_CONFIG_REPORT): $(BTR_BRANCH_DIR)/configure | $(BTR_BUILD_DIR) $(BTR_LOG_DIR) $(SAY) "Running configure..." - cd $(BUILD_DIR) && \ - ../$(BRANCH_DIR)/configure -C $(BUILD_ARGS) >../$@ 2>&1 + cd $(BTR_BUILD_DIR) && \ + ../$(BTR_BRANCH_DIR)/configure -C $(BTR_BUILD_ARGS) >../$@ 2>&1 -$(BUILD_DIR): +$(BTR_BUILD_DIR): mkdir -p $@ - -$(BRANCH_DIR)/configure: $(CONFIGS) + +$(BTR_LOG_DIR): + mkdir -p $@ + +$(BTR_BRANCH_DIR)/configure: $(CONFIGS) $(SAY) "Building configure..." - cd $(BRANCH_DIR) && \ + cd $(BTR_BRANCH_DIR) && \ autoreconf -i -f -W none >/dev/null # vim: noet diff --git a/share/btr/build/pecl.mk b/share/btr/build/pecl.mk index c27b23a..3ce75cc 100644 --- a/share/btr/build/pecl.mk +++ b/share/btr/build/pecl.mk @@ -1,30 +1,30 @@ -BUILD_CLEAN=false -BUILD_ARGS= -TEST_ARGS= -q +BTR_BUILD_CLEAN=false +BTR_BUILD_ARGS= +BTR_TEST_ARGS= -q .PHONY: all clean .SUFFIXES: -CONFIGS=$(wildcard $(BRANCH_DIR)/config*.m4 $(BRANCH_DIR)/*/config*.m4) +CONFIGS=$(wildcard $(BTR_BRANCH_DIR)/config*.m4 $(BTR_BRANCH_DIR)/*/config*.m4) -all: clean $(REPORT) - $(SAY) "Result: $$(cat $(REPORT))" +all: clean $(BTR_REPORT) + $(SAY) "Result: $$(cat $(BTR_REPORT))" -clean: $(CONFIG_REPORT) - if $(BUILD_CLEAN); \ +clean: $(BTR_CONFIG_REPORT) + if $(BTR_BUILD_CLEAN); \ then \ - cd $(BUILD_DIR) && \ - make $(SILENT_FLAG) clean; \ + cd $(BTR_BUILD_DIR) && \ + make $(BTR_SILENT_FLAG) clean; \ fi; -$(REPORT): $(TEST_REPORT) +$(BTR_REPORT): $(BTR_TEST_REPORT) @(\ - TESTS_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(TEST_REPORT)); \ - TESTS_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(TEST_REPORT)); \ + TESTS_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(BTR_TEST_REPORT)); \ + TESTS_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(BTR_TEST_REPORT)); \ printf "%d/%d" $$TESTS_PASSED $$TESTS_FAILED >$@; \ - if test -s "$(LAST_REPORT)"; then \ - LAST_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(LAST_REPORT)); \ - LAST_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(LAST_REPORT)); \ + if test -s "$(BTR_LAST_REPORT)"; then \ + LAST_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(BTR_LAST_REPORT)); \ + LAST_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(BTR_LAST_REPORT)); \ DIFF_PASSED=$$(bc <<<"$$TESTS_PASSED - $$LAST_PASSED"); \ DIFF_FAILED=$$(bc <<<"$$TESTS_FAILED - $$LAST_FAILED"); \ printf " %+d/%+d" $$DIFF_PASSED $$DIFF_FAILED >>$@; \ @@ -32,27 +32,30 @@ $(REPORT): $(TEST_REPORT) printf "\n" >>$@; \ ) -$(TEST_REPORT): $(BUILD_REPORT) +$(BTR_TEST_REPORT): $(BTR_BUILD_REPORT) $(SAY) "Running tests... " - cd $(BUILD_DIR) && \ - make test TESTS="$(TEST_ARGS) -s ../$@" >/dev/null + cd $(BTR_BUILD_DIR) && \ + make test TESTS="$(BTR_TEST_ARGS) -s ../$@" >/dev/null -$(BUILD_REPORT): $(CONFIG_REPORT) +$(BTR_BUILD_REPORT): $(BTR_CONFIG_REPORT) $(SAY) "Making build..." - cd $(BUILD_DIR) && \ + cd $(BTR_BUILD_DIR) && \ make -j $(CPUS) >../$@ 2>&1 -$(CONFIG_REPORT): $(BRANCH_DIR)/configure $(BUILD_DIR) +$(BTR_CONFIG_REPORT): $(BTR_BRANCH_DIR)/configure | $(BTR_BUILD_DIR) $(BTR_LOG_DIR) $(SAY) "Running 'configure'..." - cd $(BUILD_DIR) && \ - ../$(BRANCH_DIR)/configure -C $(BUILD_ARGS) >../$@ 2>&1 + cd $(BTR_BUILD_DIR) && \ + ../$(BTR_BRANCH_DIR)/configure -C $(BTR_BUILD_ARGS) >../$@ 2>&1 -$(BUILD_DIR): +$(BTR_BUILD_DIR): mkdir -p $@ - -$(BRANCH_DIR)/configure: $(CONFIGS) + +$(BTR_LOG_DIR): + mkdir -p $@ + +$(BTR_BRANCH_DIR)/configure: $(CONFIGS) $(SAY) "Running phpize..." - cd $(BRANCH_DIR) && \ + cd $(BTR_BRANCH_DIR) && \ phpize >/dev/null # vim: noet diff --git a/share/btr/build/php.mk b/share/btr/build/php.mk index 35a7c71..b858e2a 100644 --- a/share/btr/build/php.mk +++ b/share/btr/build/php.mk @@ -1,30 +1,30 @@ -BUILD_CLEAN=false -BUILD_ARGS= --enable-debug -TEST_ARGS= -q +BTR_BUILD_CLEAN=false +BTR_BUILD_ARGS= --enable-debug +BTR_TEST_ARGS= -q .PHONY: all clean .SUFFIXES: -CONFIGS=$(wildcard $(BRANCH_DIR)/ext/*/config*.m4) +CONFIGS=$(wildcard $(BTR_BRANCH_DIR)/ext/*/config*.m4) -all: clean $(REPORT) - $(SAY) "Result: $$(cat $(REPORT))" +all: clean $(BTR_REPORT) + $(SAY) "Result: $$(cat $(BTR_REPORT))" -clean: $(CONFIG_REPORT) - if $(BUILD_CLEAN); \ +clean: $(BTR_CONFIG_REPORT) + if $(BTR_BUILD_CLEAN); \ then \ - cd $(BUILD_DIR) && \ - make $(SILENT_FLAG) clean; \ + cd $(BTR_BUILD_DIR) && \ + make $(BTR_SILENT_FLAG) clean; \ fi; -$(REPORT): $(TEST_REPORT) +$(BTR_REPORT): $(BTR_TEST_REPORT) @(\ - TESTS_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(TEST_REPORT)); \ - TESTS_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(TEST_REPORT)); \ + TESTS_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(BTR_TEST_REPORT)); \ + TESTS_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(BTR_TEST_REPORT)); \ printf "%d/%d" $$TESTS_PASSED $$TESTS_FAILED >$@; \ - if test -s "$(LAST_REPORT)"; then \ - LAST_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(LAST_REPORT)); \ - LAST_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(LAST_REPORT)); \ + if test -s "$(BTR_LAST_REPORT)"; then \ + LAST_PASSED=$$(awk '/^Tests passed/{print $$4}' < $(BTR_LAST_REPORT)); \ + LAST_FAILED=$$(awk '/^Tests failed/{print $$4}' < $(BTR_LAST_REPORT)); \ DIFF_PASSED=$$(bc <<<"$$TESTS_PASSED - $$LAST_PASSED"); \ DIFF_FAILED=$$(bc <<<"$$TESTS_FAILED - $$LAST_FAILED"); \ printf " %+d/%+d" $$DIFF_PASSED $$DIFF_FAILED >>$@; \ @@ -32,27 +32,30 @@ $(REPORT): $(TEST_REPORT) printf "\n" >>$@; \ ) -$(TEST_REPORT): $(BUILD_REPORT) +$(BTR_TEST_REPORT): $(BTR_BUILD_REPORT) $(SAY) "Running tests... " - cd $(BUILD_DIR) && \ - make test TESTS="$(TEST_ARGS) -s ../$@" + cd $(BTR_BUILD_DIR) && \ + make test TESTS="$(BTR_TEST_ARGS) -s ../$@" -$(BUILD_REPORT): $(CONFIG_REPORT) +$(BTR_BUILD_REPORT): $(BTR_CONFIG_REPORT) $(SAY) "Making build..." - cd $(BUILD_DIR) && \ + cd $(BTR_BUILD_DIR) && \ make -j $(CPUS) >../$@ 2>&1 -$(CONFIG_REPORT): $(BRANCH_DIR)/configure $(BUILD_DIR) +$(BTR_CONFIG_REPORT): $(BTR_BRANCH_DIR)/configure | $(BTR_BUILD_DIR) $(BTR_LOG_DIR) $(SAY) "Running 'configure'..." - cd $(BUILD_DIR) && \ - ../$(BRANCH_DIR)/configure -C $(BUILD_ARGS) >../$@ 2>&1 + cd $(BTR_BUILD_DIR) && \ + ../$(BTR_BRANCH_DIR)/configure -C $(BTR_BUILD_ARGS) >../$@ 2>&1 -$(BUILD_DIR): +$(BTR_BUILD_DIR): + mkdir -p $@ + +$(BTR_LOG_DIR): mkdir -p $@ -$(BRANCH_DIR)/configure: $(BRANCH_DIR)/buildconf $(CONFIGS) +$(BTR_BRANCH_DIR)/configure: $(BTR_BRANCH_DIR)/buildconf $(CONFIGS) $(SAY) "Building configure..." - cd $(BRANCH_DIR) && \ + cd $(BTR_BRANCH_DIR) && \ ./buildconf >/dev/null # vim: noet diff --git a/share/btr/common.sh b/share/btr/common.sh new file mode 100755 index 0000000..4c7fb74 --- /dev/null +++ b/share/btr/common.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +export DATE=$(date +%Y%m%d%H%M%S) +export CPUS=${CPUS:-$(nproc)} + +BTR_QUIET=false +BTR_VERBOSE=false +BTR_FORCEYES=false + +function error { + echo "$@" >&2 + exit 1 +} +export -f error + +function btr-banner { + echo "$(basename ${0:btr}) v0.4.0, (c) Michael Wallner " + if test "$BTR_BANNER" + then + echo "$BTR_BANNER" + fi +} +export -f btr-banner + +function btr-confirm { + local CONTINUE + if ! $BTR_FORCEYES + then + echo -n "$1 (y/N) " + read -r CONTINUE + case $CONTINUE in + y*|Y*) + echo + ;; + *) + exit -1 + ;; + esac + fi +} +export -f btr-confirm + +function btr-setup-rundir { + local default_rundir="${1:-/tmp/btr}" + + if test -z "$BTR_RUNDIR" + then + export BTR_RUNDIR="$default_rundir" + else + export BTR_RUNDIR=$(realpath "$BTR_RUNDIR") + fi + + mkdir -p "$BTR_RUNDIR" || error "Could not create directory '$BTR_RUNDIR'" +} +export -f btr-setup-rundir + +function btr-setup-verbosity { + local for_make=${1:-false} + + if $BTR_VERBOSE + then + BTR_QUIET_FLAG= + BTR_SILENT_FLAG= + BTR_VERBOSE_FLAG="-v" + SAY="echo; echo" + elif $BTR_QUIET + then + BTR_QUIET_FLAG="-q" + BTR_SILENT_FLAG="-s" + BTR_VERBOSE_FLAG= + SAY="true" + else + BTR_QUIET_FLAG= + BTR_SILENT_FLAG="-s" + BTR_VERBOSE_FLAG= + SAY="echo" + fi + + if $for_make + then + SAY="@$SAY" + fi + + export BTR_QUIET BTR_VERBOSE BTR_FORCEYES BTR_QUIET_FLAG BTR_SILENT_FLAG BTR_VERBOSE_FLAG SAY +} +export -f btr-setup-verbosity + +# vim: noet diff --git a/share/btr/report/irc.mk b/share/btr/report/irc.mk index 7360fa6..583562d 100644 --- a/share/btr/report/irc.mk +++ b/share/btr/report/irc.mk @@ -2,11 +2,11 @@ .SUFFIXES: all: - $(SAY) "Notifying IRC ($(REPORT_ARGS))" - CONFIG_URL=$$(curl -sSF sprunge="@$(CONFIG_REPORT)" sprunge.us); \ - BUILD_URL=$$(curl -sSF sprunge="@$(BUILD_REPORT)" sprunge.us); \ - TEST_URL=$$(curl -sSF sprunge="@$(TEST_REPORT)" sprunge.us); \ - $(BINDIR)/btr-irc-send "$(REPORT_ARGS)" "[btr] $(BUILD) $$(cat $(REPORT)) \ - -- Config: $$CONFIG_URL -- Build: $$BUILD_URL -- Test: $$TEST_URL"; + $(SAY) "Notifying IRC ($(BTR_REPORT_ARGS))" + BTR_CONFIG_URL=$$(curl -sSF sprunge="@$(BTR_CONFIG_REPORT)" sprunge.us); \ + BTR_BUILD_URL=$$(curl -sSF sprunge="@$(BTR_BUILD_REPORT)" sprunge.us); \ + BTR_TEST_URL=$$(curl -sSF sprunge="@$(BTR_TEST_REPORT)" sprunge.us); \ + $(BTR_BINDIR)/btr-irc-send "$(BTR_REPORT_ARGS)" "[btr] $(BTR_BUILD) $$(cat $(BTR_REPORT)) \ + -- Config: $$BTR_CONFIG_URL -- Build: $$BTR_BUILD_URL -- Test: $$BTR_TEST_URL"; # vim: noet diff --git a/share/btr/report/mail.mk b/share/btr/report/mail.mk index d16a646..76c6b8b 100644 --- a/share/btr/report/mail.mk +++ b/share/btr/report/mail.mk @@ -1,15 +1,15 @@ -REPORT_ARGS=$(USER) +BTR_REPORT_ARGS=$(USER) .PHONY: all .SUFFIXES: all: - $(SAY) "Mailing report to $(REPORT_ARGS)" - @printf "\nbtr %s %s\n\n-- \nbtr mail report\n" "$(BUILD)" "$$(cat $(REPORT))" | \ - mail -s "[btr] $(BUILD) $$(cat $(REPORT))" \ - -a $(CONFIG_REPORT) \ - -a $(BUILD_REPORT) \ - -a $(TEST_REPORT) \ - $(REPORT_ARGS) + $(SAY) "Mailing report to $(BTR_REPORT_ARGS)" + @printf "\nbtr %s %s\n\n-- \nbtr mail report\n" "$(BTR_BUILD)" "$$(cat $(BTR_REPORT))" | \ + mail -s "[btr] $(BTR_BUILD) $$(cat $(BTR_REPORT))" \ + -a $(BTR_CONFIG_REPORT) \ + -a $(BTR_BUILD_REPORT) \ + -a $(BTR_TEST_REPORT) \ + $(BTR_REPORT_ARGS) # vim: noet diff --git a/share/btr/report/notify-send.mk b/share/btr/report/notify-send.mk index cfc20cc..e913c3c 100644 --- a/share/btr/report/notify-send.mk +++ b/share/btr/report/notify-send.mk @@ -3,10 +3,10 @@ all: $(SAY) "Notifying $(USER) about the report" - CONFIG_URL=$$(curl -sSF sprunge="@$(CONFIG_REPORT)" sprunge.us); \ - BUILD_URL=$$(curl -sSF sprunge="@$(BUILD_REPORT)" sprunge.us); \ - TEST_URL=$$(curl -sSF sprunge="@$(TEST_REPORT)" sprunge.us); \ - notify-send $(REPORT_ARGS) "[btr] $(BUILD) $$(cat $(REPORT))" \ - "Config: $$CONFIG_URL -- Build: $$BUILD_URL -- Test:$$TEST_URL"; + BTR_CONFIG_URL=$$(curl -sSF sprunge="@$(BTR_CONFIG_REPORT)" sprunge.us); \ + BTR_BUILD_URL=$$(curl -sSF sprunge="@$(BTR_BUILD_REPORT)" sprunge.us); \ + BTR_TEST_URL=$$(curl -sSF sprunge="@$(BTR_TEST_REPORT)" sprunge.us); \ + notify-send $(BTR_REPORT_ARGS) "[btr] $(BTR_BUILD) $$(cat $(BTR_REPORT))" \ + "Config: $$BTR_CONFIG_URL -- Build: $$BTR_BUILD_URL -- Test: $$BTR_TEST_URL"; # vim: noet diff --git a/share/btr/report/twilio.mk b/share/btr/report/twilio.mk index 54ac53a..f0dd0bb 100644 --- a/share/btr/report/twilio.mk +++ b/share/btr/report/twilio.mk @@ -4,8 +4,8 @@ all: curl "https://api.twilio.com/2010-04-01/Accounts/$(TWILIO_ACCOUNT)/SMS/Messages.json" \ --data-urlencode "From=$(TWILIO_NUMBER)" \ - --data-urlencode "To=$(REPORT_NUMBER)" \ - --data-urlencode "Body=[btr] $(BUILD) $$(cat $(REPORT))" \ + --data-urlencode "To=$(BTR_REPORT_NUMBER)" \ + --data-urlencode "Body=[btr] $(BTR_BUILD) $$(cat $(BTR_REPORT))" \ -u $(TWILIO_ACCOUNT):$(TWILIO_TOKEN) # vim: noet diff --git a/share/btr/source/cvs.mk b/share/btr/source/cvs.mk index 839efa2..7682d2a 100644 --- a/share/btr/source/cvs.mk +++ b/share/btr/source/cvs.mk @@ -1,31 +1,31 @@ -SOURCE_CLEAN=false -CVSROOT=$(shell cut -d'\#' -f1 <<<$(SOURCE_ARGS)) -CVS_MOD=$(shell cut -d'\#' -f2 -s <<<$(SOURCE_ARGS)) +BTR_SOURCE_CLEAN=false +CVSROOT=$(shell cut -d'\#' -f1 <<<$(BTR_SOURCE_ARGS)) +CVS_MOD=$(shell cut -d'\#' -f2 -s <<<$(BTR_SOURCE_ARGS)) CVS_RSH=ssh export -ifeq ($(value QUIET_FLAG), -q) -override QUIET_FLAG = -Q +ifeq ($(value BTR_QUIET_FLAG), -q) +override BTR_QUIET_FLAG = -Q endif .PHONY: all clean login .SUFFIXES: -all: $(BRANCH_DIR) clean - $(SAY) "Updating $(BRANCH)..." - cd $(BRANCH_DIR) && \ - cvs $(QUIET_FLAG) -z3 update -RPd; +all: $(BTR_BRANCH_DIR) clean + $(SAY) "Updating $(BTR_BRANCH)..." + cd $(BTR_BRANCH_DIR) && \ + cvs $(BTR_QUIET_FLAG) -z3 update -RPd; -clean: $(BRANCH_DIR) - if $(SOURCE_CLEAN); \ +clean: $(BTR_BRANCH_DIR) + if $(BTR_SOURCE_CLEAN); \ then \ - cd $(BRANCH_DIR) && \ - cvs $(QUIET_FLAG) -z3 update -CRPd; \ + cd $(BTR_BRANCH_DIR) && \ + cvs $(BTR_QUIET_FLAG) -z3 update -CRPd; \ fi; -$(BRANCH_DIR): +$(BTR_BRANCH_DIR): $(SAY) "Performing checkout of $(CVS_MOD) from $(CVSROOT)..." - cvs $(QUIET_FLAG) checkout -RP -r $(BRANCH) -d $(BRANCH_DIR) $(CVS_MOD) + cvs $(BTR_QUIET_FLAG) checkout -RP -r $(BTR_BRANCH) -d $(BTR_BRANCH_DIR) $(CVS_MOD) # vim: noet diff --git a/share/btr/source/git.mk b/share/btr/source/git.mk index 3808590..02744cd 100644 --- a/share/btr/source/git.mk +++ b/share/btr/source/git.mk @@ -1,31 +1,31 @@ -SOURCE_CLEAN=false +BTR_SOURCE_CLEAN=false .PHONY: fetch all clean .SUFFIXES: -all: $(BRANCH_DIR) clean fetch - $(SAY) "Merging $(BRANCH) of $(REPO)..." - cd $(BRANCH_DIR) && \ - git merge $(QUIET_FLAG) --ff-only; +all: $(BTR_BRANCH_DIR) clean fetch + $(SAY) "Merging $(BTR_BRANCH) of $(BTR_REPO)..." + cd $(BTR_BRANCH_DIR) && \ + git merge $(BTR_QUIET_FLAG) --ff-only; -clean: $(BRANCH_DIR) - if $(SOURCE_CLEAN); \ +clean: $(BTR_BRANCH_DIR) + if $(BTR_SOURCE_CLEAN); \ then \ - cd $(BRANCH_DIR) && \ - git reset --hard $(QUIET_FLAGS); \ + cd $(BTR_BRANCH_DIR) && \ + git reset --hard $(BTR_QUIET_FLAGS); \ fi; -fetch: $(CLEAN_DIR) - $(SAY) "Fetching $(REPO)..." - cd $(CLEAN_DIR) && \ - git fetch $(QUIET_FLAG); +fetch: $(BTR_REPO_DIR) + $(SAY) "Fetching $(BTR_REPO)..." + cd $(BTR_REPO_DIR) && \ + git fetch $(BTR_QUIET_FLAG); -$(CLEAN_DIR): - $(SAY) "Cloning from $(SOURCE_ARGS)..." - git clone $(QUIET_FLAG) $(SOURCE_ARGS) $(CLEAN_DIR); +$(BTR_REPO_DIR): + $(SAY) "Cloning from $(BTR_SOURCE_ARGS)..." + git clone $(BTR_QUIET_FLAG) $(BTR_SOURCE_ARGS) $(BTR_REPO_DIR); -$(BRANCH_DIR): $(CLEAN_DIR) - $(SAY) "Creating workdir for $(BRANCH)" - git-new-workdir $(CLEAN_DIR) $(BRANCH_DIR) $(BRANCH) +$(BTR_BRANCH_DIR): $(BTR_REPO_DIR) + $(SAY) "Creating workdir for $(BTR_BRANCH)" + git-new-workdir $(BTR_REPO_DIR) $(BTR_BRANCH_DIR) $(BTR_BRANCH) # vim: noet diff --git a/share/btr/source/svn.mk b/share/btr/source/svn.mk index b18782e..f7edc6b 100644 --- a/share/btr/source/svn.mk +++ b/share/btr/source/svn.mk @@ -1,22 +1,22 @@ -SOURCE_CLEAN=false +BTR_SOURCE_CLEAN=false .PHONY: all clean .SUFFIXES: -all: $(BRANCH_DIR) clean - $(SAY) "Updating $(BRANCH)..." - cd $(BRANCH_DIR) && \ - svn update $(QUIET_FLAG); +all: $(BTR_BRANCH_DIR) clean + $(SAY) "Updating $(BTR_BRANCH)..." + cd $(BTR_BRANCH_DIR) && \ + svn update $(BTR_QUIET_FLAG); -clean: $(BRANCH_DIR) - if $(SOURCE_CLEAN); \ +clean: $(BTR_BRANCH_DIR) + if $(BTR_SOURCE_CLEAN); \ then \ - cd $(BRANCH_DIR) && \ - svn revert $(QUIET_FLAG); \ + cd $(BTR_BRANCH_DIR) && \ + svn revert $(BTR_QUIET_FLAG); \ fi; -$(BRANCH_DIR): - $(SAY) "Performing checkout from $(SOURCE_ARGS)..." - svn checkout $(QUIET_FLAG) $(SOURCE_ARGS)/$(BRANCH) $(BRANCH_DIR) +$(BTR_BRANCH_DIR): + $(SAY) "Performing checkout from $(BTR_SOURCE_ARGS)..." + svn checkout $(BTR_QUIET_FLAG) $(BTR_SOURCE_ARGS)/$(BTR_BRANCH) $(BTR_BRANCH_DIR) # vim: noet