From 4243f31e1b332f02992e70bc70fea4c62d21271e Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 15 Nov 2010 20:39:34 -0800 Subject: [PATCH] Add minimal/do, a stripped-down redo implementation in 977 bytes of sh. This could be good for distributing with your packages, so that people who don't have redo installed can at least build it. Also, we could use it for building redo itself. Will surely need to get slightly bigger as I inevitably discover I've forgotten a critical feature. --- clean.do | 1 - minimal/do | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ redo.py | 1 + runtests.do | 2 +- t/bellow.do | 2 +- t/hello.c | 0 t/hello.do | 2 +- t/yellow.do | 2 +- test.do | 4 +--- 9 files changed, 60 insertions(+), 8 deletions(-) create mode 100755 minimal/do mode change 100644 => 100755 t/hello.c diff --git a/clean.do b/clean.do index b519b35..1125a69 100644 --- a/clean.do +++ b/clean.do @@ -1,3 +1,2 @@ rm -f t/hello t/[by]ellow t/*.o *~ .*~ t/*~ t/.*~ *.pyc t/CC t/LD rm -rf .redo t/.redo - diff --git a/minimal/do b/minimal/do new file mode 100755 index 0000000..b42f66d --- /dev/null +++ b/minimal/do @@ -0,0 +1,54 @@ +#!/bin/sh +# +# A minimal alternative to djb redo that doesn't support incremental builds. +# For the full version, visit http://github.com/apenwarr/redo +# +export REDO="$(dirname "$0")/$(basename "$0")" +IFS=" +" + +if [ -z "$DO_BUILT" ]; then + export DO_BUILT="$PWD/.do_built" + if [ -e "$DO_BUILT" ]; then + echo "Removing previously built files..." >&2 + sort "$DO_BUILT" | uniq | tee "$DO_BUILT.new" | xargs rm -f + mv "$DO_BUILT.new" "$DO_BUILT" + fi +fi + + +_do() +{ + TARGET="$1" + DOFILE="$1.do" + if [ ! -e "$TARGET" ]; then + printf '\033[32mdo \033[1m%s\033[m\n' "$PWD/$TARGET" >&2 + echo "$PWD/$TARGET" >>"$DO_BUILT" + set "$TARGET" FIXME "$TARGET.tmp" + ( . "$PWD/$DOFILE" >"$TARGET.tmp" ) && + mv "$TARGET.tmp" "$TARGET" + else + echo "$1 exists." >&2 + fi +} + + +redo() +{ + for i in "$@"; do + D="$(dirname "$i")" + B="$(basename "$i")" + ( cd "$D" && _do "$B" ) + done +} + + +alias redo-ifchange="redo" +alias redo-ifcreate=":" +set -e + +if [ -n "$*" ]; then + redo "$@" +else + redo all +fi diff --git a/redo.py b/redo.py index 9cc2c25..89afa85 100755 --- a/redo.py +++ b/redo.py @@ -30,6 +30,7 @@ if not os.environ.get('REDO_BASE', ''): break os.environ['REDO_BASE'] = base os.environ['REDO_STARTDIR'] = os.getcwd() + os.environ['REDO'] = os.path.abspath(sys.argv[0]) # FIXME: just wiping out all the locks is kind of cheating. But we # only do this from the toplevel redo process, so unless the user diff --git a/runtests.do b/runtests.do index 579dcfd..e6c5a13 100644 --- a/runtests.do +++ b/runtests.do @@ -1,4 +1,4 @@ -. wvtest.sh +. ./wvtest.sh redo t/all WVSTART "t/runtests" diff --git a/t/bellow.do b/t/bellow.do index fa98f55..a308c5c 100644 --- a/t/bellow.do +++ b/t/bellow.do @@ -1,3 +1,3 @@ redo-ifchange LD yellow.o -./LD bellow yellow.o +./LD "$3" yellow.o ./sleep 2 diff --git a/t/hello.c b/t/hello.c old mode 100644 new mode 100755 diff --git a/t/hello.do b/t/hello.do index 93794ee..c1bb472 100644 --- a/t/hello.do +++ b/t/hello.do @@ -1,3 +1,3 @@ redo-ifchange LD hello.o ./sleep 1 -./LD hello hello.o +./LD "$3" hello.o diff --git a/t/yellow.do b/t/yellow.do index dbcf36b..752818d 100644 --- a/t/yellow.do +++ b/t/yellow.do @@ -1,3 +1,3 @@ redo-ifchange LD yellow.o ./sleep 1.5 -./LD yellow yellow.o +./LD "$3" yellow.o diff --git a/test.do b/test.do index 9c0ada5..5feb053 100644 --- a/test.do +++ b/test.do @@ -1,4 +1,2 @@ redo-ifchange t/all -wvtestrun redo runtests >&2 - - +./wvtestrun "$REDO" runtests >&2