$3 and stdout no longer refer to the same file.

This is slightly inelegant, as the old style
	echo foo
	echo blah
	chmod a+x $3

doesn't work anymore; the stuff you wrote to stdout didn't end up in $3.
You can rewrite it as:
	exec >$3
	echo foo
	echo blah
	chmod a+x $3

Anyway, it's better this way, because now we can tell the difference between
a zero-length $3 and a nonexistent one.  A .do script can thus produce
either one and we'll either delete the target or move the empty $3 to
replace it, whichever is right.

As a bonus, this simplifies our detection of whether you did something weird
with overlapping changes to stdout and $3.
This commit is contained in:
Avery Pennarun 2010-12-11 00:29:04 -08:00
commit 59201dd7a0
9 changed files with 54 additions and 29 deletions

5
t/.gitignore vendored
View file

@ -11,3 +11,8 @@ test2.args
/makedir
/makedir.log
/chdir1
/silence
/silence.do
/touch1
/touch1.do
/deltest2

View file

@ -1,3 +1,4 @@
exec >$3
cat <<-EOF
gcc -Wall -o /dev/fd/1 -c "\$1"
EOF

View file

@ -1,3 +1,4 @@
exec >$3
cat <<-EOF
OUT="\$1"
shift

View file

@ -1,4 +1,5 @@
redo example/clean curse/clean deps/clean "space dir/clean"
rm -f c c.c c.c.c c.c.c.b c.c.c.b.b d mode1 makedir.log chdir1
rm -f hello [by]ellow *.o *~ .*~ CC LD passfail
rm -rf makedir
rm -f c c.c c.c.c c.c.c.b c.c.c.b.b d mode1 makedir.log chdir1 \
hello [by]ellow *.o *~ .*~ CC LD passfail silence silence.do \
touch1 touch1.do
rm -rf makedir

View file

@ -1,5 +1,6 @@
redo-ifchange config.sh
. ./config.sh
exec >$3
cat <<-EOF
redo-ifchange \$1.c
gcc -MD -MF \$3.deps.tmp -o \$3 -c \$1.c

7
t/silencetest.do Normal file
View file

@ -0,0 +1,7 @@
echo 'echo hello' >silence.do
redo silence
[ -e silence ] || exit 55
echo 'true' >silence.do
redo silence
[ ! -e silence ] || exit 66
rm -f silence.do

View file

@ -1,4 +1,5 @@
redo-ifchange all
./hello >&2
redo deltest deltest2 test.args test2.args passfailtest chdirtest \
curse/test deps/test "space dir/test" modetest makedir2
curse/test deps/test "space dir/test" modetest makedir2 \
silencetest touchtest

9
t/touchtest.do Normal file
View file

@ -0,0 +1,9 @@
echo 'echo hello' >touch1.do
redo touch1
[ -e touch1 ] || exit 55
rm -f touch1
echo 'touch $3' >touch1.do
redo touch1
[ -e touch1 ] || exit 66
[ -z "$(cat touch1)" ] || exit 77
rm -f touch1.do