Commit graph

138 commits

Author SHA1 Message Date
Avery Pennarun
e9e24bb450 t/shelltest.od: another test for ${x#y} behaviour.
If y contains a * character, it's a case-esac style wildcard unless it's in
"" or '', which tells it to match a literal *.  But in dash/busybox, the ''
quoting doesn't actually work, only "" does.

Since there's a workaround - just always use "" quoting - it's not that
fatal.  If the "" quoting doesn't work, then we'll make it fail.
2011-04-02 16:30:14 -07:00
Avery Pennarun
03763177ff shelltest.od: a few more/better tests and clarification comments. 2011-04-02 15:41:52 -07:00
Avery Pennarun
92c3e7c5af Test for previous override fix. 2011-03-30 23:35:20 -04:00
Avery Pennarun
fb20652d04 Test for precenting state.relpath fix. 2011-03-27 15:25:11 -04:00
Avery Pennarun
49228ce01c Add a test for the preceding fix (nonexistent directories). 2011-03-22 23:02:12 -07:00
Avery Pennarun
07af5d83f9 redo: only default to 'all' in the toplevel instance of redo.
We already did this in minimal/do, and redo-ifchange already did this, but
plain redo didn't.  This made constructs like:

	for d in *.x; do
		echo "${d%.x}"
	done | xargs redo

dangerous, because if there were no matching files, we'd try to 'redo all'.
2011-03-10 21:10:15 -08:00
Avery Pennarun
d26ec22d88 Test for previous atime/ctime fix. 2011-03-10 14:37:07 -08:00
Avery Pennarun
d5e6951111 t/curse/Makefile: delete.
I don't remember why it was there, but we clearly don't use it anymore.
2011-03-10 14:36:45 -08:00
Avery Pennarun
989eb6804b minimal/do: fix a typo: DO_BUILD -> DO_BUILT
...and remove the "disable-if-minimal-do" from the test that would have
caught this bug.

Reported by Ulrik Sverdrup.
2011-03-06 21:38:34 -08:00
Avery Pennarun
164e213582 Test for previous PREFIX fix to minimal/do. 2011-03-05 19:03:34 -08:00
Avery Pennarun
c1a1f32445 MacOS: "-e filename/." returns true even for non-directories.
This has something to do with resource forks.  So use "-d filename/."
instead, which returns false if filename is not a directory.
2011-03-05 19:03:30 -08:00
Avery Pennarun
ee32a965d8 shelltest.od: test that $1/$2/$3 are set correctly in "." scripts.
dash seems to fail this one, and it's not pretty.
2011-02-28 22:07:21 -08:00
Avery Pennarun
32f584cb1c shelltest: detect the ". of empty script" shell problem. 2011-02-28 22:06:57 -08:00
Avery Pennarun
cfc3f44d64 minimal/do: 'redo-ifchange' with no parameters shouldn't try to build all.
It should just build nothing.  Because sometimes you want to do something
like:
	redo-ifchange $(find -name '*.c')

And the find doesn't return any results.  This is consistent with what real
redo does.

Added a test to confirm that it works.
2011-02-26 18:01:31 -08:00
Avery Pennarun
94c254de77 Rename flush-cache.py to flush-cache, and rearrange the code a bit.
It was working fine, but the style wasn't exactly the way I like it, because
I'm unnecessarily picky. :)

Also, removed the file extension since we should probably learn from the
fact that it's already been rewritten once from one language to another.
Who knows, maybe it will be again someday.
2011-02-23 01:27:41 -08:00
Joseph Garvin
d039aad57b Fix tests when the sqlite3 command line utility isn't installed.
We know the user already has to have python, so use its bindings.
2011-02-23 01:22:04 -08:00
Avery Pennarun
a2bce72255 Simplify autodependency examples.
Turns out we don't need sed to process the output of gcc -MD.  We can just
do this:

	read DEPS <filename.deps

The 'read' command in sh actually handles backslashes correctly, so we don't
have to sed them out after all.  And then a simple ${DEPS#*:} removes the
"target:" prefix from the dependency line, and we're done!
2011-02-21 04:00:53 -08:00
Tim Allen
e27aaf01e7 Make redo read byte-strings from the database.
By default, the database redo uses to store file state returns filenames
as Unicode strings, and if redo tries to run a build-script whose
fully-qualified path contains non-ASCII characters then redo crashes
when trying to promote the path to a Unicode string.

This patch ensures that the database always returns byte-strings, not
Unicode strings. That way, the fully-qualified path and the target name
are both byte-strings and can be joined without issue.

(Fixes a bug reported by Zoran Zaric.)
2011-02-14 18:48:33 -08:00
Avery Pennarun
71316cc99a shelltest.od: abort correctly if 'cd ~' fails.
It seems 'set -e' doesn't quite work, in some shells, in that case.

Eric Kow wrote:
> I saw this warning, by the way:
> redo      t/shelltest
>   warning: 94
> cd: 271: can't cd to /opt/redo-0.05/t/space
> rmdir: failed to remove pace home dir': No such file or directory
>   warning: 111
2011-01-19 13:54:51 -08:00
Avery Pennarun
c077d77285 builder.py: correctly set $3 to include the subdir path.
If we're using a .do file from a parent directory, we should set $3 using
the same path prefix as $1.  We were previously using just the basename,
which mostly works (since we would rename it to $1$2 eventually anyway) but
is not quite right, and you can't safely rename files across filesystems, so
it could theoretically cause problems.

Also improved t/defaults-nested to test for this behaviour.

Reported by Eric Kow.
2011-01-18 00:48:52 -08:00
Avery Pennarun
474f2e71fe shelltest: confirm that 'local' is definitely available.
Supposedly it's not POSIX, but every shell I have seems to support it, so
let's just reject any that don't.  And like magic, anybody using redo can
now count on the 'local' builtin working.
2011-01-18 00:48:51 -08:00
Avery Pennarun
5dbbfd4288 shelltest: die if 'cd ~' can't handle spaces in $HOME.
This fails on ash, dash, and busybox sh (for now).  But it's kind of
important since $HOME often has spaces on Win32.  I hope dash will be fixed
relatively soon.

I downgraded it to a warning since on Unix, this probably isn't a problem.
2011-01-18 00:48:51 -08:00
Jimmy
4a296d676c t/defaults-nested/clean fails on MacOS X.
It seems on OSX find behaves differently (probably from linux):

jtang@exia:~/develop/redo $ make clean
./redo clean
redo  clean
redo    t/clean
redo      t/example/clean
redo      t/curse/clean
redo      t/deps/clean
redo        t/deps/basic/clean
redo        t/deps/dirtest/clean
redo      t/space dir/clean
redo      t/stamp/clean
redo      t/defaults-flat/clean
redo      t/defaults-nested/clean
find: illegal option -- n
find: illegal option -- a
find: illegal option -- m
find: illegal option -- e
find: *~: No such file or directory
redo      t/defaults-nested/clean: exit code 1
redo    t/clean: exit code 1
redo  clean: exit code 1
make: *** [clean] Error 1

This fixes it for me.
2011-01-18 00:48:51 -08:00
Avery Pennarun
4c06332ea1 builder.py: we weren't stamping .do files correctly if dodir!='.'.
The result was that t/deps/dirtest was actually failing in some cases.  But
it wasn't failing quite reliably enough, because the failing test was
dirtest/dir1/all, which has the same name as some other 'all' files,
confusing the issue.  Renamed dirtest/dir1/all.do to dirtest/dir1/go.do instead.

Reported by Prakhar Goel and Berke Durak.
2011-01-18 00:48:51 -08:00
Avery Pennarun
e98696caef Merge branch 'master' into search-parent-dirs
* master:
  Fixed markdown errors in README - code samples now correctly formatted.
  Fix use of config.sh in example
  log.py, minimal/do: don't use ansi colour codes if $TERM is blank or 'dumb'
  Use named constants for terminal control codes.
  redo-sh: keep testing even after finding a 'good' shell.
  redo-sh.do: hide warning output from 'which' in some shells.
  redo-sh.do: wrap long lines.
  Handle .do files that start with "#!/" to specify an explicit interpreter.
  minimal/do: don't print an error on exit if we don't build anything.
  bash completions: also mark 'do' as a completable command.
  bash completions: work correctly when $cur is an empty string.
  bash completions: call redo-targets for a more complete list.
  bash completions: work correctly with subdirs, ie. 'redo t/<tab>'
  Sample bash completion rules for redo targets.
  minimal/do: faster deletion of stamp files.
  minimal/do: delete .tmp files if a build fails.
  minimal/do: use ".did" stamp files instead of empty target files.
  minimal/do: use posix shell features instead of dirname/basename.
  Automatically select a good shell instead of relying on /bin/sh.

Conflicts:
	t/clean.do
2011-01-15 16:00:12 -08:00
Ryan Kuester
6819010401 Fix use of config.sh in example 2011-01-10 22:32:39 -06:00
Avery Pennarun
eea3f5446a redo-sh: keep testing even after finding a 'good' shell.
Otherwise we miss out on seeing the results from additional tests.
2011-01-02 12:00:37 -08:00
Avery Pennarun
f641e52e3b Handle .do files that start with "#!/" to specify an explicit interpreter.
Now you can have your .do files interpreted by whatever interpreter you
want.
2011-01-01 22:10:14 -08:00
Avery Pennarun
fb388b3dde Automatically select a good shell instead of relying on /bin/sh.
This includes a fairly detailed test of various known shell bugs from the
autoconf docs.

The idea here is that if redo works on your system, you should be able to
rely on a *good* shell to run your .do files; you shouldn't have to work
around zillions of bugs like autoconf does.
2010-12-21 04:44:39 -08:00
Avery Pennarun
0dcc3f61b6 Search parent directories for default*.do.
Previously, we would only search for default*.do in the same directory in
the target; now we search parent directories as well.

Let's say we're in a/b/ and trying to build foo.o.  If we find
../../default.o.do, then we'll run

	cd ../..; sh default.o.do a/b/foo .o $TMPNAME

In other words, we still always chdir to the same directory as the .do file.
But now $1 might have a path in it, not just a basename.
2010-12-19 05:58:49 -08:00
Avery Pennarun
e207b723b4 Move some of the tests from t/ into t/defaults-flat.
This lets us move t/default.do out of the way; it was confusing otherwise.
2010-12-19 04:54:44 -08:00
Avery Pennarun
95680ed7ef Switch to using a separate lockfile per target.
The previous method, using fcntl byterange locks, was very efficient and
avoided unnecessarily filesystem metadata churn (ie. creating/deleting
inodes).  Unfortunately, MacOS X (at least version 10.6.5) apparently has a
race condition in its fcntl locking that makes it unusably unreliable
(http://apenwarr.ca/log/?m=201012#13).

My tests indicate that if you only ever lock a *single* byterange on a file,
the race condition doesn't cause a problem.  So let's just use one lockfile
per target.  Now "redo -j20 test" passes for me on both MacOS and Linux.

This doesn't measurably affect the speed on Linux, at least, in my tests.

The bad news: it's hard to safely *delete* those lockfiles when we're done
with them, so they tend to accumulate in the .redo dir.
2010-12-14 02:44:29 -08:00
Avery Pennarun
8f9453a55d Fix tests on MacOS.
This comes down to the lack of a 'seq' command (what?!) and the fact that
BSD "wc -l" returns extra whitespace, while the GNU version doesn't.  We
should be using numeric comparisons instead of string comparisons, and then
it's ok.
2010-12-12 05:38:30 -08:00
Avery Pennarun
f16f0147b1 Add a redo-ifcreate test.
Turns out we weren't testing this one at all, which is a shame, because it
totally didn't work.
2010-12-11 23:50:12 -08:00
Avery Pennarun
e6f95521ae redo-always/redo-ifcreate/redo-stamp: work inside chdir().
If someone cd's to another directory and then runs redo-always, we weren't
adding to the right target.
2010-12-11 23:42:45 -08:00
Avery Pennarun
b9987433c9 Disable the tests that don't work with minimal/do.
...only when running under minimal/do, of course.

The tests in question mostly fail because they're testing particular
dependency-related behaviour, and minimal/do doesn't support dependencies,
so naturally it doesn't work.
2010-12-11 21:06:12 -08:00
Avery Pennarun
0da5c7c082 Add a redo-always command: it adds an "always dirty" dependency to your target.
This is mostly useless except when combined with redo-stamp... I think.
2010-12-11 07:02:45 -08:00
Avery Pennarun
1d26d99e0c Fix a deadlock with redo-oob.
If a checksummed target A used to exist but is now missing, and we tried to
redo-ifchange that exact file, we would unnecessarily run 'redo-oob A A';
that is, we have to build A in order to determine if A needs to be built.

The sub-targets of redo-oob aren't run with REDO_UNLOCKED, so this would
deadlock instantly.

Add an assertion to redo-oob to ensure we never try to redo-ifchange the
primary target (thus converting the deadlock into an exception).  And skip
doing redo-oob when the target is already the same as the thing we have to
check.
2010-12-11 06:16:32 -08:00
Avery Pennarun
e7f7119f2e If a checksummed file is deleted, we should still use redo-oob.
We were giving up and rebuilding the toplevel object, which did eventually
rebuild our checksummed file, but then the file turned out to be identical
to what it was before, so that nobody *else* who depended on it ended up
getting rebuilt.  So the results were indeterminate.

Now we treat it as if its dirtiness is unknown, so we build it using
redo-oob before building any of its dependencies.
2010-12-11 05:54:39 -08:00
Avery Pennarun
f702417ef3 The second half of redo-stamp: out-of-order building.
If a depends on b depends on c, and c is dirty but b uses redo-stamp
checksums, then 'redo-ifchange a' is indeterminate: we won't know if we need
to run a.do unless we first build b, but the script that *normally* runs
'redo-ifchange b' is a.do, and we don't want to run that yet, because we
don't know for sure if b is dirty, and we shouldn't build a unless one of
its dependencies is dirty.  Eek!

Luckily, there's a safe solution.  If we *know* a is dirty - eg. because
a.do or one of its children has definitely changed - then we can just run
a.do immediately and there's no problem, even if b is indeterminate, because
we were going to run a.do anyhow.

If a's dependencies are *not* definitely dirty, and all we have is
indeterminate ones like b, then that means a's build process *hasn't
changed*, which means its tree of dependencies still includes b, which means
we can deduce that if we *did* run a.do, it would end up running b.do.

Since we know that anyhow, we can safely just run b.do, which will either
b.set_checked() or b.set_changed().  Once that's done, we can re-parse a's
dependencies and this time conclusively tell if it needs to be redone or
not.  Even if it does, b is already up-to-date, so the 'redo-ifchange b'
line in a.do will be fast.

...now take all the above and do it recursively to handle nested
dependencies, etc, and you're done.
2010-12-11 05:54:39 -08:00
Avery Pennarun
1355ade7c7 Correctly handle a checksummed file that depends on a non-checksummed file.
We were rebuilding the checksummed file every time because redo-ifchange was
incorrectly assuming that a child's changed_runid that's greater than my
changed_runid means I'm dirty.  But if my checked_runid is >= the child's
checked_runid, then I'm clean, because my checksum didn't change.

Clear as mud?
2010-12-11 05:54:39 -08:00
Avery Pennarun
22617d335c Half-support for using file checksums instead of stamps.
A new redo-stamp program takes whatever you give it as stdin and uses it to
calculate a checksum for the current target.  If that checksum is the same
as last time, then we consider the target to be unchanged, and we set
checked_runid and stamp, but leave changed_runid alone.  That will make
future callers of redo-ifchange see this target as unmodified.

However, this is only "half" support because by the time we run the .do
script that calls redo-stamp, it's too late; the caller is a dependant of
the stamped program, which is already being rebuilt, even if redo-stamp
turns out to say that this target is unchanged.

The other half is coming up.
2010-12-11 05:54:37 -08:00
Avery Pennarun
59201dd7a0 $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.
2010-12-11 00:29:04 -08:00
Avery Pennarun
f6d11d5411 If a user manually changes a generated file, don't ever overwrite it.
That way the user can modify an auto-generated 'compile' script, for
example, and it'll stay modified.

If they delete the file, we can then generate it for them again.

Also, we have to warn whenever we're doing this, or people might think it's
a bug.
2010-12-10 22:43:11 -08:00
Avery Pennarun
0126f6be1e Don't wipe the timestamp when a target fails to redo.
It's really a separate condition.  And since we're not removing the target
*file* in case of error - we update it atomically, and keeping it is better
than losing it - there's no reason to wipe the timestamp in that case
either.

However, we do need to know that the build failed, so that anybody else
(especially in a parallel build) who looks at that target knows that it
died.  So add a separate flag just for that.
2010-12-10 22:41:11 -08:00
Avery Pennarun
b86a32d33d flush-cache.sh: for speed, disable sqlite's synchronous mode. 2010-12-10 00:50:52 -08:00
Avery Pennarun
9e36106642 sqlite3: configure the timeout explicitly.
In flush-cache.sh, we have to do this, because the sqlite3 command-line tool
sets it to zero.  Inevitably during parallel testing, it'll end up
contending for a lock, and we really want it to wait a bit.

In state.py, it's not as important since the default is nonzero.  But
python-sqlite3's default of 5 seconds makes me a little too nervous; I can
imagine a disk write waiting for more than 5 seconds sometime.  So let's use
60 instead.
2010-12-10 00:50:52 -08:00
Avery Pennarun
a62bd50d44 Switch state.py to use sqlite3 instead of filesystem-based stamps.
It passes all tests when run serialized, but still gives weird errors
(OperationalError: database is locked) when run with -j5.  sqlite3 shouldn't
be barfing just because the database is locked, since the default timeout is
5 seconds, and it's dying *way* faster than that.
2010-12-10 00:50:52 -08:00
Avery Pennarun
8dad223225 flush-cache: run it as a separate program, not using 'source'
That way it doesn't clutter up 'redo -x' as much.
2010-12-10 00:50:52 -08:00
Avery Pennarun
0979a6e666 t/passfailtest.do: just return exit codes, don't print messages.
The exit code numbers are useful enough, and the messages are the sort of
thing that might turn into lies eventually.
2010-12-06 03:12:02 -08:00