From 21f88094d5b80d543b3a36b6947f511e1ca88223 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 31 Dec 2011 02:45:38 -0500 Subject: [PATCH] Change definitions of $1,$2,$3 to match djb's redo. If you use "redo --old-args", it will switch back to the old (apenwarr-style) arguments for now, to give you time to update your .do scripts. This option will go away eventually. Note: minimal/do doesn't understand the --old-args option. If you're using minimal/do in your project, keep using the old one until you update your use of $1/$2, and then update to the new one. apenwarr-style default.o.do: $1 foo $2 .o $3 whatever.tmp djb-style default.o.do: $1 foo.o $2 foo $3 whatever.tmp apenwarr-style foo.o.do: $1 foo.o $2 "" $3 whatever.tmp djb-style foo.o.do: $1 foo.o $2 foo.o (I think?) $3 whatever.tmp --- Documentation/default.1.do | 2 +- Documentation/default.md.tmp.do | 4 +-- Documentation/md-to-man.do | 4 +-- Documentation/redo-ifchange.md | 8 +++--- Documentation/redo.md | 14 +++++++-- README.md | 43 ++++++++++++---------------- _all.do | 5 ++++ builder.py | 10 +++++-- minimal/do | 2 +- redo.py | 3 ++ t/curse/default.n1.do | 2 +- t/curse/default.n2.do | 6 ++-- t/default.args.do | 4 +-- t/defaults-flat/c.do | 4 +-- t/defaults-flat/default.b.do | 10 +++---- t/defaults-flat/default.c.c.do | 4 +-- t/defaults-flat/default.c.do | 4 +-- t/defaults-nested/a/b/default.y.z.do | 2 +- t/defaults-nested/a/b/file.x.y.z.do | 2 +- t/defaults-nested/a/d/default.do | 2 +- t/defaults-nested/a/default.x.y.z.do | 2 +- t/defaults-nested/a/default.z.do | 2 +- t/defaults-nested/default.do | 2 +- t/deps/basic/default.out.do | 4 +-- t/example/CC.do | 4 +-- t/test2.args.do | 2 +- vars.py | 1 + 27 files changed, 84 insertions(+), 68 deletions(-) diff --git a/Documentation/default.1.do b/Documentation/default.1.do index 1d66fb4..b2c9875 100644 --- a/Documentation/default.1.do +++ b/Documentation/default.1.do @@ -1,2 +1,2 @@ -redo-ifchange md-to-man $1.md.tmp +redo-ifchange md-to-man $2.md.tmp . ./md-to-man $1 $2 $3 diff --git a/Documentation/default.md.tmp.do b/Documentation/default.md.tmp.do index cc0ca4b..4c4bbca 100644 --- a/Documentation/default.md.tmp.do +++ b/Documentation/default.md.tmp.do @@ -1,3 +1,3 @@ -redo-ifchange ../version/vars $1.md +redo-ifchange ../version/vars $2.md . ../version/vars -sed -e "s/%VERSION%/$TAG/" -e "s/%DATE%/$DATE/" $1.md +sed -e "s/%VERSION%/$TAG/" -e "s/%DATE%/$DATE/" $2.md diff --git a/Documentation/md-to-man.do b/Documentation/md-to-man.do index 979f1ef..2b08acf 100644 --- a/Documentation/md-to-man.do +++ b/Documentation/md-to-man.do @@ -1,8 +1,8 @@ redo-ifchange md2man.py if ./md2man.py /dev/null; then - echo './md2man.py $1.md.tmp' + echo './md2man.py $2.md.tmp' else echo "Warning: md2man.py missing modules; can't generate manpages." >&2 echo "Warning: try this: sudo easy_install markdown BeautifulSoup" >&2 - echo 'echo Skipping: $1.1 >&2' + echo 'echo Skipping: $2.1 >&2' fi diff --git a/Documentation/redo-ifchange.md b/Documentation/redo-ifchange.md index 81722b0..5c8dcd0 100644 --- a/Documentation/redo-ifchange.md +++ b/Documentation/redo-ifchange.md @@ -48,10 +48,10 @@ of .h files it depends on. You can pass this information along to redo-ifchange, so if any of those headers are changed or deleted, your .c file will be rebuilt: - redo-ifchange $1.c - gcc -o $3 -c $1.c \ - -MMD -MF $1.deps - read DEPS <$1.deps + redo-ifchange $2.c + gcc -o $3 -c $2.c \ + -MMD -MF $2.deps + read DEPS <$2.deps redo-ifchange ${DEPS#*:} This is much less confusing than the equivalent diff --git a/Documentation/redo.md b/Documentation/redo.md index 2250249..30ba040 100644 --- a/Documentation/redo.md +++ b/Documentation/redo.md @@ -104,6 +104,14 @@ dependencies. output message. This makes it easier to figure out which sub-instance of redo is doing what. +--old-args +: old versions of redo provided different definitions of + the $1 and $2 parameters to .do scripts. The new + version is compatible with djb's original + specification. This option goes back to the old + definitions so you can use .do scripts you haven't yet + converted to the new style. + # DISCUSSION @@ -156,8 +164,8 @@ redo does not have this problem.) The three arguments passed to the .do script are: -- $1: the basename of the target (eg. mytarget.a.b) -- $2: the extension of the target, if any (eg. .c.d) +- $1: the target name (eg. mytarget.a.b) +- $2: the basename of the target, minus its extension (eg. mytarget) - $3: a temporary filename that the .do script should write its output to. @@ -165,7 +173,7 @@ Instead of using $3, the .do script may also write the produced data to stdout. If the .do file is in the same directory as the target, $1 -and $3 are guaranteed to be simple filenames (with no path +is guaranteed to be a simple filename (with no path component). If the .do file is in a parent directory of the target, $1 and $3 will be relative paths (ie. will contain slashes). diff --git a/README.md b/README.md index 3796b35..ee2312c 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,9 @@ The easiest way to show it is with an example. Create a file called default.o.do: - redo-ifchange $1.c - gcc -MD -MF $1.d -c -o $3 $1.c - read DEPS <$1.d + redo-ifchange $2.c + gcc -MD -MF $2.d -c -o $3 $2.c + read DEPS <$2.d redo-ifchange ${DEPS#*:} Create a file called myprog.do: @@ -293,34 +293,30 @@ To activate it, you can add a line like this to your .bashrc: # What are the three parameters ($1, $2, $3) to a .do file? -FIXME: -These definitions might change. It turns out that -djb's original definitions differ from these and we should -probably change ours in order to maintain compatibility. -(In his version, $1 is always the name of the target, and -$2 is the target with the extension removed.) +NOTE: These definitions have changed since the earliest +(pre-0.10) versions of redo. The new definitions match +what djb's original redo implementation did. -$1 is the name of the target, with the extension removed, -if any. +$1 is the name of the target file. -$2 is the extension of the target, including the leading -dot. +$2 is the basename of the target, minus the extension, if +any. $3 is the name of a temporary file that will be renamed to the target filename atomically if your .do file returns a zero (success) exit code. In a file called `chicken.a.b.c.do` that builds a file called -`chicken.a.b.c`, $1 is `chicken.a.b.c`, $2 is blank, and $3 is a +`chicken.a.b.c`, $1 and $2 are `chicken.a.b.c`, and $3 is a temporary name like `chicken.a.b.c.tmp`. You might have expected -$1 to be just `chicken`, but that's not possible, because +$2 to be just `chicken`, but that's not possible, because redo doesn't know which portion of the filename is the "extension." Is it `.c`, `.b.c`, or `.a.b.c`? .do files starting with `default.` are special; they can build any target ending with the given extension. So let's say we have a file named `default.c.do` building a file -called `chicken.a.b.c`. $1 is `chicken.a.b`, $2 is `.c`, +called `chicken.a.b.c`. $1 is `chicken.a.b.c`, $2 is `chicken.a.b`, and $3 is a temporary name like `chicken.a.b.c.tmp`. You should use $1 and $2 only in constructing input @@ -333,11 +329,8 @@ to stdout instead of $3 if you want.) For example, you could compile a .c file into a .o file like this, from a script named `default.o.do`: - redo-ifchange $1.c - gcc -o $3 -c $1.c - -Note that $2, the output file's .o extension, is rarely useful -since you always know what it is. + redo-ifchange $2.c + gcc -o $3 -c $2.c # Why not named variables like $FILE, $EXT, $OUT instead of $1, $2, $3? @@ -762,7 +755,7 @@ So we haven't thought about this enough yet. Note that it's *okay* for a .do file to produce targets other than the advertised one; you just have to be careful. You could have a default.javac.do that runs 'javac -$1.java', and then have your program depend on a bunch of .javac +$2.java', and then have your program depend on a bunch of .javac files. Just be careful not to depend on the .class files themselves, since redo won't know how to regenerate them. @@ -848,12 +841,12 @@ create a file called `compile.do`: redo-ifchange config.sh . ./config.sh - echo "gcc -c -o \$3 $1.c $CFLAGS" >$3 + echo "gcc -c -o \$3 $2.c $CFLAGS" >$3 chmod a+x $3 Then, your `default.o.do` can simply look like this: - redo-ifchange compile $1.c + redo-ifchange compile $2.c ./compile $1 $2 $3 This is not only elegant, it's useful too. With make, you have to always @@ -884,7 +877,7 @@ look something like this: redo-ifchange config.sh . ./config.sh cat <<-EOF - [ -e "\$1.cc" ] && EXT=.cc || EXT=.c + [ -e "\$2.cc" ] && EXT=.cc || EXT=.c gcc -o "\$3" -c "\$1\$EXT" -Wall $CFLAGS EOF chmod a+x "$3" diff --git a/_all.do b/_all.do index f1d9513..6167bd0 100644 --- a/_all.do +++ b/_all.do @@ -1,2 +1,7 @@ +if [ "$1,$2" != "_all,_all" ]; then + echo "ERROR: old-style redo args detected: don't use --old-args." >&2 + exit 1 +fi + redo-ifchange redo-sh redo-ifchange version/all Documentation/all diff --git a/builder.py b/builder.py index fdd28e6..3b33912 100644 --- a/builder.py +++ b/builder.py @@ -141,10 +141,16 @@ class BuildJob: close_on_exec(ffd, True) self.f = os.fdopen(ffd, 'w+') # this will run in the dofile's directory, so use only basenames here + if vars.OLD_ARGS: + arg1 = basename # target name (no extension) + arg2 = ext # extension (if any), including leading dot + else: + arg1 = basename + ext # target name (including extension) + arg2 = basename # target name (without extension) argv = ['sh', '-e', dofile, - basename, # target name (no extension) - ext, # extension (if any), including leading dot + arg1, + arg2, # temp output file name state.relpath(os.path.abspath(self.tmpname2), dodir), ] diff --git a/minimal/do b/minimal/do index f08e002..d84c442 100755 --- a/minimal/do +++ b/minimal/do @@ -121,7 +121,7 @@ _do() fi [ ! -e "$DO_BUILT" ] || [ ! -d "$(dirname "$target")" ] || : >>"$target.did" - ( _run_dofile "$base" "$ext" "$tmp.tmp" ) + ( _run_dofile "$target" "$base" "$tmp.tmp" ) rv=$? if [ $rv != 0 ]; then printf "do: %s%s\n" "$DO_DEPTH" \ diff --git a/redo.py b/redo.py index f1ab93e..1298d0e 100755 --- a/redo.py +++ b/redo.py @@ -15,6 +15,7 @@ shuffle randomize the build order to find dependency bugs debug-locks print messages about file locking (useful for debugging) debug-pids print process ids as part of log messages (useful for debugging) version print the current version and exit +old-args use old-style definitions of $1,$2,$3 (deprecated) """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) @@ -39,6 +40,8 @@ if opt.debug_locks: os.environ['REDO_DEBUG_LOCKS'] = '1' if opt.debug_pids: os.environ['REDO_DEBUG_PIDS'] = '1' +if opt.old_args: + os.environ['REDO_OLD_ARGS'] = '1' import vars_init vars_init.init(targets) diff --git a/t/curse/default.n1.do b/t/curse/default.n1.do index 118f26c..8aa430f 100644 --- a/t/curse/default.n1.do +++ b/t/curse/default.n1.do @@ -1,3 +1,3 @@ DEPS=$(./seq 100 | sed 's/$/.n2/') redo-ifchange $DEPS -echo n1-$1 +echo n1-$2 diff --git a/t/curse/default.n2.do b/t/curse/default.n2.do index 2ab2dc5..10166d7 100644 --- a/t/curse/default.n2.do +++ b/t/curse/default.n2.do @@ -1,6 +1,6 @@ -echo n2-$1 -echo $1 >>$1.count -echo $1 >>in.countall +echo n2-$2 +echo $2 >>$2.count +echo $2 >>in.countall # we deliberately use 'redo' here instead of redo-ifchange, because this *heavily* # stresses redo's locking when building in parallel. We end up with 100 diff --git a/t/default.args.do b/t/default.args.do index 5309b61..a79a7da 100644 --- a/t/default.args.do +++ b/t/default.args.do @@ -1,3 +1,3 @@ -[ "$1" = "test" ] -[ "$2" = ".args" ] +[ "$1" = "test.args" ] +[ "$2" = "test" ] [ "$3" != "test.args" ] diff --git a/t/defaults-flat/c.do b/t/defaults-flat/c.do index 05fe36f..3d6bd11 100644 --- a/t/defaults-flat/c.do +++ b/t/defaults-flat/c.do @@ -1,3 +1,3 @@ -redo-ifchange $1$2.c +redo-ifchange $1.c echo c.do -cat $1$2.c +cat $1.c diff --git a/t/defaults-flat/default.b.do b/t/defaults-flat/default.b.do index fd14711..b8c9b1e 100644 --- a/t/defaults-flat/default.b.do +++ b/t/defaults-flat/default.b.do @@ -1,10 +1,10 @@ -if [ -e "$1$2.a" -o -e "default$2.a" ]; then - redo-ifchange "$1$2.a" +if [ -e "$1.a" -o -e "default${1#$2}.a" ]; then + redo-ifchange "$1.a" echo a-to-b - cat "$1$2.a" + cat "$1.a" else - redo-ifchange "$1$2.b" + redo-ifchange "$1.b" echo b-to-b - cat "$1$2.b" + cat "$1.b" fi ../sleep 1.1 diff --git a/t/defaults-flat/default.c.c.do b/t/defaults-flat/default.c.c.do index 4b4d226..12798b4 100644 --- a/t/defaults-flat/default.c.c.do +++ b/t/defaults-flat/default.c.c.do @@ -1,4 +1,4 @@ -redo-ifchange $1$2.b +redo-ifchange $1.b echo b-to-cc -cat $1$2.b +cat $1.b ../sleep 1.2 diff --git a/t/defaults-flat/default.c.do b/t/defaults-flat/default.c.do index 275f12a..9fc8bd7 100644 --- a/t/defaults-flat/default.c.do +++ b/t/defaults-flat/default.c.do @@ -1,4 +1,4 @@ -redo-ifchange $1$2.c +redo-ifchange $1.c echo c-to-c -cat $1$2.c +cat $1.c ../sleep 1.3 diff --git a/t/defaults-nested/a/b/default.y.z.do b/t/defaults-nested/a/b/default.y.z.do index 648b3bb..089cc26 100644 --- a/t/defaults-nested/a/b/default.y.z.do +++ b/t/defaults-nested/a/b/default.y.z.do @@ -1 +1 @@ -echo default.y.z $1 $2 +echo default.y.z $2 ${1#$2} diff --git a/t/defaults-nested/a/b/file.x.y.z.do b/t/defaults-nested/a/b/file.x.y.z.do index d11e86a..88c5d06 100644 --- a/t/defaults-nested/a/b/file.x.y.z.do +++ b/t/defaults-nested/a/b/file.x.y.z.do @@ -1 +1 @@ -echo file $1 $2 +echo file $2 ${1#$2} diff --git a/t/defaults-nested/a/d/default.do b/t/defaults-nested/a/d/default.do index 162e667..4c10de0 100644 --- a/t/defaults-nested/a/d/default.do +++ b/t/defaults-nested/a/d/default.do @@ -1 +1 @@ -echo default $1 $2 +echo default $2 ${1#$2} diff --git a/t/defaults-nested/a/default.x.y.z.do b/t/defaults-nested/a/default.x.y.z.do index 3b0398e..d23f78e 100644 --- a/t/defaults-nested/a/default.x.y.z.do +++ b/t/defaults-nested/a/default.x.y.z.do @@ -1,2 +1,2 @@ -echo default.x.y.z $1 $2 +echo default.x.y.z $2 ${1#$2} diff --git a/t/defaults-nested/a/default.z.do b/t/defaults-nested/a/default.z.do index 02b313a..2e01a30 100644 --- a/t/defaults-nested/a/default.z.do +++ b/t/defaults-nested/a/default.z.do @@ -1 +1 @@ -echo default.z $1 $2 +echo default.z $2 ${1#$2} diff --git a/t/defaults-nested/default.do b/t/defaults-nested/default.do index d6deb3f..dd206f9 100644 --- a/t/defaults-nested/default.do +++ b/t/defaults-nested/default.do @@ -1 +1 @@ -echo root $1 $2 "$(dirname $3)" +echo root $2 ${1#$2} "$(dirname $3)" diff --git a/t/deps/basic/default.out.do b/t/deps/basic/default.out.do index cd73106..3393269 100644 --- a/t/deps/basic/default.out.do +++ b/t/deps/basic/default.out.do @@ -1,3 +1,3 @@ -redo-ifchange $1.in +redo-ifchange $2.in echo $$ -echo $$ >>$1.log +echo $$ >>$2.log diff --git a/t/example/CC.do b/t/example/CC.do index c62bd31..ebb9103 100644 --- a/t/example/CC.do +++ b/t/example/CC.do @@ -2,8 +2,8 @@ redo-ifchange config.sh . ./config.sh exec >$3 cat <<-EOF - redo-ifchange \$1.c - gcc $CFLAGS -MD -MF \$3.deps -o \$3 -c \$1.c + redo-ifchange \$2.c + gcc $CFLAGS -MD -MF \$3.deps -o \$3 -c \$2.c read DEPS <\$3.deps rm -f \$3.deps redo-ifchange \${DEPS#*:} diff --git a/t/test2.args.do b/t/test2.args.do index c96d759..1f136fb 100644 --- a/t/test2.args.do +++ b/t/test2.args.do @@ -1,3 +1,3 @@ [ "$1" = "test2.args" ] -[ "$2" = "" ] +[ "$2" = "test2.args" ] [ "$3" != "test2.args" ] diff --git a/vars.py b/vars.py index 77156ee..d81ca78 100644 --- a/vars.py +++ b/vars.py @@ -13,6 +13,7 @@ DEPTH = os.environ.get('REDO_DEPTH', '') DEBUG = atoi(os.environ.get('REDO_DEBUG', '')) DEBUG_LOCKS = os.environ.get('REDO_DEBUG_LOCKS', '') and 1 or 0 DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0 +OLD_ARGS = os.environ.get('REDO_OLD_ARGS', '') and 1 or 0 VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0 XTRACE = os.environ.get('REDO_XTRACE', '') and 1 or 0 KEEP_GOING = os.environ.get('REDO_KEEP_GOING', '') and 1 or 0