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.
This commit is contained in:
Avery Pennarun 2010-11-15 20:39:34 -08:00
commit 4243f31e1b
9 changed files with 60 additions and 8 deletions

View file

@ -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

54
minimal/do Executable file
View file

@ -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

View file

@ -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

View file

@ -1,4 +1,4 @@
. wvtest.sh
. ./wvtest.sh
redo t/all
WVSTART "t/runtests"

View file

@ -1,3 +1,3 @@
redo-ifchange LD yellow.o
./LD bellow yellow.o
./LD "$3" yellow.o
./sleep 2

0
t/hello.c Normal file → Executable file
View file

View file

@ -1,3 +1,3 @@
redo-ifchange LD hello.o
./sleep 1
./LD hello hello.o
./LD "$3" hello.o

View file

@ -1,3 +1,3 @@
redo-ifchange LD yellow.o
./sleep 1.5
./LD yellow yellow.o
./LD "$3" yellow.o

View file

@ -1,4 +1,2 @@
redo-ifchange t/all
wvtestrun redo runtests >&2
./wvtestrun "$REDO" runtests >&2