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.
This commit is contained in:
Avery Pennarun 2011-02-23 01:24:48 -08:00
commit 94c254de77
12 changed files with 47 additions and 51 deletions

View file

@ -5,21 +5,22 @@ redo t/always1
cd t cd t
[ "$(wc -l <always1.log)" -eq 1 ] || exit 11 [ "$(wc -l <always1.log)" -eq 1 ] || exit 11
# This shouldn't rebuild, but because other people might be running flush-cache.py # This shouldn't rebuild, but because other people might be running
# in parallel with us, we can't be 100% sure it won't. So don't test it. # flush-cache in parallel with us, we can't be 100% sure it won't. So don't
# test it.
#redo-ifchange always1 #redo-ifchange always1
#[ "$(wc -l <always1.log)" -eq 1 ] || exit 21 #[ "$(wc -l <always1.log)" -eq 1 ] || exit 21
./flush-cache.py ./flush-cache
redo-ifchange always1 redo-ifchange always1
. ./skip-if-minimal-do.sh . ./skip-if-minimal-do.sh
[ "$(wc -l <always1.log)" -eq 2 ] || exit 31 [ "$(wc -l <always1.log)" -eq 2 ] || exit 31
./flush-cache.py ./flush-cache
redo-ifchange always1 redo-ifchange always1
[ "$(wc -l <always1.log)" -eq 3 ] || exit 41 [ "$(wc -l <always1.log)" -eq 3 ] || exit 41
cd .. cd ..
./t/flush-cache.py ./t/flush-cache
redo-ifchange t/always1 redo-ifchange t/always1
[ "$(wc -l <t/always1.log)" -eq 4 ] || exit 51 [ "$(wc -l <t/always1.log)" -eq 4 ] || exit 51

View file

@ -4,15 +4,15 @@ rm -f chdir1
redo chdir2 redo chdir2
redo chdir3 redo chdir3
./flush-cache.py ./flush-cache
redo-ifchange chdir3 redo-ifchange chdir3
rm -f chdir1 rm -f chdir1
./flush-cache.py ./flush-cache
redo-ifchange chdir3 redo-ifchange chdir3
[ -e chdir1 ] || exit 77 [ -e chdir1 ] || exit 77
rm -f chdir1 rm -f chdir1
./flush-cache.py ./flush-cache
redo-ifchange chdir3 redo-ifchange chdir3
[ -e chdir1 ] || exit 78 [ -e chdir1 ] || exit 78

View file

@ -1,10 +1,10 @@
rm -f *.out *.log rm -f *.out *.log
../../flush-cache.py ../../flush-cache
redo-ifchange 1.out 2.out redo-ifchange 1.out 2.out
[ "$(cat 1.log | wc -l)" -eq 1 ] || exit 55 [ "$(cat 1.log | wc -l)" -eq 1 ] || exit 55
[ "$(cat 2.log | wc -l)" -eq 1 ] || exit 56 [ "$(cat 2.log | wc -l)" -eq 1 ] || exit 56
../../flush-cache.py ../../flush-cache
touch 1.in touch 1.in
redo-ifchange 1.out 2.out redo-ifchange 1.out 2.out
[ "$(cat 2.log | wc -l)" -eq 1 ] || exit 58 [ "$(cat 2.log | wc -l)" -eq 1 ] || exit 58

View file

@ -1,11 +1,11 @@
rm -f log dir1/log dir1/stinky rm -f log dir1/log dir1/stinky
touch t1.do touch t1.do
../../flush-cache.py ../../flush-cache
redo t1 redo t1
touch t1.do touch t1.do
../../flush-cache.py ../../flush-cache
redo t1 redo t1
../../flush-cache.py ../../flush-cache
redo-ifchange t1 redo-ifchange t1
C1="$(wc -l <dir1/log)" C1="$(wc -l <dir1/log)"
C2="$(wc -l <log)" C2="$(wc -l <log)"

View file

@ -3,7 +3,7 @@ rm -f static.log
redo static1 static2 redo static1 static2
touch static.in touch static.in
../flush-cache.py ../flush-cache
redo-ifchange static1 static2 redo-ifchange static1 static2
COUNT=$(wc -l <static.log) COUNT=$(wc -l <static.log)

View file

@ -1,19 +1,19 @@
rm -f genfile2 genfile2.do genfile.log rm -f genfile2 genfile2.do genfile.log
echo echo hello >genfile2.do echo echo hello >genfile2.do
../flush-cache.py ../flush-cache
redo genfile1 redo genfile1
# this will cause a rebuild: # this will cause a rebuild:
# genfile1 depends on genfile2 depends on genfile2.do # genfile1 depends on genfile2 depends on genfile2.do
rm -f genfile2.do rm -f genfile2.do
../flush-cache.py ../flush-cache
redo-ifchange genfile1 redo-ifchange genfile1
# but genfile2.do was gone last time, so genfile2 no longer depends on it. # but genfile2.do was gone last time, so genfile2 no longer depends on it.
# thus, it can be considered up-to-date. Prior versions of redo had a bug # thus, it can be considered up-to-date. Prior versions of redo had a bug
# where the dependency on genfile2.do was never dropped. # where the dependency on genfile2.do was never dropped.
../flush-cache.py ../flush-cache
redo-ifchange genfile1 redo-ifchange genfile1
COUNT=$(wc -l <genfile.log) COUNT=$(wc -l <genfile.log)

View file

@ -6,7 +6,7 @@ if [ -e t1a ]; then
else else
BEFORE= BEFORE=
fi fi
../flush-cache.py ../flush-cache
redo-ifchange t1a # it definitely had to rebuild because t1dep changed redo-ifchange t1a # it definitely had to rebuild because t1dep changed
AFTER="$(cat t1a)" AFTER="$(cat t1a)"
if [ "$BEFORE" = "$AFTER" ]; then if [ "$BEFORE" = "$AFTER" ]; then

16
t/flush-cache Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
import sys, os, sqlite3
if "DO_BUILT" in os.environ:
sys.exit(0)
sys.stderr.write("Flushing redo cache...\n")
db_file = os.path.join(os.environ["REDO_BASE"], ".redo/db.sqlite3")
db = sqlite3.connect(db_file, timeout=5000)
db.executescript("pragma synchronous = off;"
"update Files set checked_runid=checked_runid-1, "
" changed_runid=changed_runid-1, "
" failed_runid=failed_runid-1;")
db.commit()

View file

@ -1,21 +0,0 @@
#!/usr/bin/env python
import os, os.path, sqlite3, sys
if "DO_BUILT" in os.environ:
sys.exit(0)
print >>sys.stderr, "Flushing redo cache..."
db_file = os.path.join(os.environ["REDO_BASE"], ".redo", "db.sqlite3")
db_con = sqlite3.connect(db_file, timeout=5000)
db_con.executescript("pragma synchronous = off;"
"update Files set checked_runid=checked_runid-1, "
" changed_runid=changed_runid-1, "
" failed_runid=failed_runid-1;")
db_con.commit()
db_con.close()

View file

@ -10,11 +10,11 @@ for d in 1 2; do
[ "$(wc -l <ifcreate$d.log)" -eq 1 ] || exit ${d}1 [ "$(wc -l <ifcreate$d.log)" -eq 1 ] || exit ${d}1
redo-ifchange ifcreate$d redo-ifchange ifcreate$d
[ "$(wc -l <ifcreate$d.log)" -eq 1 ] || exit ${d}2 [ "$(wc -l <ifcreate$d.log)" -eq 1 ] || exit ${d}2
./flush-cache.py ./flush-cache
touch ifcreate$d.dep touch ifcreate$d.dep
redo-ifchange ifcreate$d redo-ifchange ifcreate$d
[ "$(wc -l <ifcreate$d.log)" -eq 2 ] || exit ${d}3 [ "$(wc -l <ifcreate$d.log)" -eq 2 ] || exit ${d}3
./flush-cache.py ./flush-cache
rm ifcreate$d.dep rm ifcreate$d.dep
redo-ifchange ifcreate$d redo-ifchange ifcreate$d
[ "$(wc -l <ifcreate$d.log)" -eq 3 ] || exit ${d}4 [ "$(wc -l <ifcreate$d.log)" -eq 3 ] || exit ${d}4

View file

@ -2,7 +2,7 @@
rm -f makedir.log rm -f makedir.log
redo makedir redo makedir
touch makedir/outfile touch makedir/outfile
./flush-cache.py ./flush-cache
redo-ifchange makedir redo-ifchange makedir
COUNT=$(wc -l <makedir.log) COUNT=$(wc -l <makedir.log)
[ "$COUNT" -eq 1 ] || exit 99 [ "$COUNT" -eq 1 ] || exit 99

View file

@ -1,32 +1,32 @@
rm -f stampy usestamp usestamp2 stampy.log usestamp.log usestamp2.log rm -f stampy usestamp usestamp2 stampy.log usestamp.log usestamp2.log
echo one >inp echo one >inp
../flush-cache.py ../flush-cache
redo stampy redo stampy
[ "$(wc -l <stampy.log)" -eq 1 ] || exit 11 [ "$(wc -l <stampy.log)" -eq 1 ] || exit 11
# stampy already exists, so we won't generate it a second time, even though # stampy already exists, so we won't generate it a second time, even though
# usestamp depends on it. # usestamp depends on it.
../flush-cache.py ../flush-cache
redo-ifchange usestamp redo-ifchange usestamp
[ "$(wc -l <stampy.log)" -eq 1 ] || exit 21 [ "$(wc -l <stampy.log)" -eq 1 ] || exit 21
[ "$(wc -l <usestamp.log)" -eq 1 ] || exit 12 [ "$(wc -l <usestamp.log)" -eq 1 ] || exit 12
../flush-cache.py ../flush-cache
redo stampy redo stampy
. ../skip-if-minimal-do.sh . ../skip-if-minimal-do.sh
[ "$(wc -l <stampy.log)" -eq 2 ] || exit 31 [ "$(wc -l <stampy.log)" -eq 2 ] || exit 31
[ "$(wc -l <usestamp.log)" -eq 1 ] || exit 32 [ "$(wc -l <usestamp.log)" -eq 1 ] || exit 32
# same as above: stampy is already up-to-date, so it won't be redone. # same as above: stampy is already up-to-date, so it won't be redone.
../flush-cache.py ../flush-cache
redo-ifchange usestamp redo-ifchange usestamp
[ "$(wc -l <stampy.log)" -eq 2 ] || exit 41 [ "$(wc -l <stampy.log)" -eq 2 ] || exit 41
[ "$(wc -l <usestamp.log)" -eq 1 ] || exit 42 [ "$(wc -l <usestamp.log)" -eq 1 ] || exit 42
# stampy depends on bob, so we'll have to rebuild stampy automatically. But # stampy depends on bob, so we'll have to rebuild stampy automatically. But
# stampy's checksum will still be identical. # stampy's checksum will still be identical.
../flush-cache.py ../flush-cache
redo bob redo bob
redo-ifchange usestamp redo-ifchange usestamp
[ "$(wc -l <stampy.log)" -eq 3 ] || exit 43 [ "$(wc -l <stampy.log)" -eq 3 ] || exit 43
@ -34,13 +34,13 @@ redo-ifchange usestamp
# Make sure the previous step correctly marked stampy and usestamp as up-to-date # Make sure the previous step correctly marked stampy and usestamp as up-to-date
# even though *neither* of them is newer than bob. # even though *neither* of them is newer than bob.
../flush-cache.py ../flush-cache
redo-ifchange usestamp redo-ifchange usestamp
[ "$(wc -l <stampy.log)" -eq 3 ] || exit 45 [ "$(wc -l <stampy.log)" -eq 3 ] || exit 45
[ "$(wc -l <usestamp.log)" -eq 1 ] || exit 46 [ "$(wc -l <usestamp.log)" -eq 1 ] || exit 46
# now we're changing the contents of stampy. # now we're changing the contents of stampy.
../flush-cache.py ../flush-cache
echo two >inp echo two >inp
redo stampy redo stampy
[ "$(wc -l <stampy.log)" -eq 4 ] || exit 51 [ "$(wc -l <stampy.log)" -eq 4 ] || exit 51
@ -53,7 +53,7 @@ redo-ifchange usestamp usestamp2
# when we delete the file and it gets regenerated identically, it's as good as # when we delete the file and it gets regenerated identically, it's as good as
# never having been deleted. So usestamp won't need to change. # never having been deleted. So usestamp won't need to change.
../flush-cache.py ../flush-cache
rm -f stampy rm -f stampy
redo-ifchange usestamp usestamp2 redo-ifchange usestamp usestamp2
[ "$(wc -l <stampy.log)" -eq 5 ] || exit 71 [ "$(wc -l <stampy.log)" -eq 5 ] || exit 71
@ -61,7 +61,7 @@ redo-ifchange usestamp usestamp2
[ "$(wc -l <usestamp2.log)" -eq 1 ] || exit 73 [ "$(wc -l <usestamp2.log)" -eq 1 ] || exit 73
# this simple test used to cause a deadlock. # this simple test used to cause a deadlock.
../flush-cache.py ../flush-cache
rm -f stampy rm -f stampy
redo-ifchange stampy redo-ifchange stampy
[ "$(wc -l <stampy.log)" -eq 6 ] || exit 74 [ "$(wc -l <stampy.log)" -eq 6 ] || exit 74