From fb5275938d911e757d35c5084f299c039e238cd9 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 1 Jan 2011 03:42:35 -0800 Subject: [PATCH] minimal/do: use ".did" stamp files instead of empty target files. If all.do runs and creates no output, we shouldn't create a file called 'all', but we should remember that 'all' has been run successfully. We do this by creating 'all.did' during the build. Since minimal/do always just wipes everything out every time it runs, we can safely remove the .did files after minimal/do terminates, so this doesn't clutter things too much in normal use. This fixes some edge cases, particularly that 'minimal/do clean' no longer leaves stupid files named "clean" lying around, and the redo-sh directory can now be rebuilt correctly since we rebuild it as long as redo-sh.did doesn't exist. (We don't want to "rm -rf redo-sh" because it makes me nervous.) --- clean.do | 2 +- minimal/do | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clean.do b/clean.do index ec75b2a..938703b 100644 --- a/clean.do +++ b/clean.do @@ -1,3 +1,4 @@ +rm -rf t/.redo redo-sh if [ -e .do_built ]; then while read x; do rm -f "$x" @@ -6,5 +7,4 @@ fi [ -z "$DO_BUILT" ] && rm -rf .do_built .do_built.dir redo t/clean Documentation/clean rm -f *~ .*~ */*~ */.*~ *.pyc install.wrapper -rm -rf t/.redo redo-sh find . -name '*.tmp' -exec rm -fv {} \; diff --git a/minimal/do b/minimal/do index 9120704..44045ef 100755 --- a/minimal/do +++ b/minimal/do @@ -15,12 +15,14 @@ _dirsplit() _dirsplit "$0" export REDO=$(cd "${dir:-.}" && echo "$PWD/$base") +DO_TOP= if [ -z "$DO_BUILT" ]; then + DO_TOP=1 export DO_BUILT=$PWD/.do_built if [ -e "$DO_BUILT" ]; then echo "Removing previously built files..." >&2 sort -u "$DO_BUILT" | tee "$DO_BUILT.new" | - while read f; do rm -f "$f" 2>/dev/null; done + while read f; do rm -f "$f" "$f.did" 2>/dev/null; done mv "$DO_BUILT.new" "$DO_BUILT" fi DO_PATH=$DO_BUILT.dir @@ -55,7 +57,7 @@ _run_dofile() export DO_DEPTH="$DO_DEPTH " export REDO_TARGET=$PWD/$TARGET set -e - . "$PWD/$DOFILE" >"$TARGET.tmp" + . "$PWD/$DOFILE" >"$TARGET.tmp2" } @@ -63,7 +65,7 @@ _do() { DIR=$1 TARGET=$2 - if [ ! -e "$TARGET" ]; then + if [ ! -e "$TARGET" ] || [ -e "$TARGET/." -a ! -e "$TARGET.did" ]; then printf '\033[32mdo %s\033[1m%s\033[m\n' \ "$DO_DEPTH" "$DIR$TARGET" >&2 echo "$PWD/$TARGET" >>"$DO_BUILT" @@ -75,6 +77,7 @@ _do() echo "do: $TARGET: no .do file" >&2 return 1 fi + : >>"$TARGET.did" ( _run_dofile "$BASE" "$EXT" "$TARGET.tmp" ) RV=$? if [ $RV != 0 ]; then @@ -82,8 +85,10 @@ _do() "$DIR$TARGET: got exit code $RV" >&2 return $RV fi - mv "$TARGET.tmp" "$TARGET" 2>/dev/null - : >>"$TARGET" + mv "$TARGET.tmp" "$TARGET" 2>/dev/null || + ! test -s "$TARGET.tmp2" || + mv "$TARGET.tmp2" "$TARGET" 2>/dev/null + rm -f "$TARGET.tmp2" else echo "do $DO_DEPTH$TARGET exists." >&2 fi @@ -105,3 +110,8 @@ if [ -n "$*" ]; then else redo all fi + +if [ -n "$DO_TOP" ]; then + echo "Removing stamp files..." >&2 + while read f; do rm -f "$f.did" 2>/dev/null; done <"$DO_BUILT" +fi