Support for default.*.do rules.
I *think* this was the last missing part from djb's spec. Certainly it's an important one for any real project.
This commit is contained in:
parent
b25e79f353
commit
c1f09f564b
11 changed files with 75 additions and 16 deletions
3
clean.do
3
clean.do
|
|
@ -1,2 +1,3 @@
|
|||
rm -f t/hello t/[by]ellow t/*.o *~ .*~ t/*~ t/.*~ *.pyc t/CC t/LD
|
||||
redo t/clean
|
||||
rm -f t/hello t/[by]ellow t/*.o *~ .*~ */*~ */.*~ *.pyc t/CC t/LD
|
||||
rm -rf .redo t/.redo
|
||||
|
|
|
|||
43
redo.py
43
redo.py
|
|
@ -42,6 +42,7 @@ if not os.environ.get('REDO_BASE', ''):
|
|||
for f in glob.glob('%s/.redo/lock^*' % base):
|
||||
os.unlink(f)
|
||||
|
||||
|
||||
import vars
|
||||
from helpers import *
|
||||
|
||||
|
|
@ -52,14 +53,26 @@ class BuildLocked(Exception):
|
|||
pass
|
||||
|
||||
|
||||
def _possible_do_files(t):
|
||||
yield "%s.do" % t, t, ''
|
||||
dirname,filename = os.path.split(t)
|
||||
l = filename.split('.')
|
||||
l[0] = os.path.join(dirname, l[0])
|
||||
for i in range(1,len(l)+1):
|
||||
basename = '.'.join(l[:i])
|
||||
ext = '.'.join(l[i:])
|
||||
if ext: ext = '.' + ext
|
||||
yield "default%s.do" % ext, basename, ext
|
||||
|
||||
|
||||
def find_do_file(t):
|
||||
dofile = '%s.do' % t
|
||||
for dofile,basename,ext in _possible_do_files(t):
|
||||
if os.path.exists(dofile):
|
||||
add_dep(t, 'm', dofile)
|
||||
return dofile
|
||||
return dofile,basename,ext
|
||||
else:
|
||||
add_dep(t, 'c', dofile)
|
||||
return None
|
||||
return None,None,None
|
||||
|
||||
|
||||
def stamp(t):
|
||||
|
|
@ -86,23 +99,33 @@ def _preexec(t):
|
|||
|
||||
|
||||
def _build(t):
|
||||
unlink(sname('dep', t))
|
||||
open(sname('dep', t), 'w').close()
|
||||
dofile = find_do_file(t)
|
||||
if not dofile:
|
||||
if os.path.exists(t): # an existing source file
|
||||
if os.path.exists(t) and not os.path.exists(sname('gen', t)):
|
||||
# an existing source file that is not marked as a generated file.
|
||||
# This step is mentioned by djb in his notes. It turns out to be
|
||||
# important to prevent infinite recursion. For example, a rule
|
||||
# called default.o.do could be used to try to produce hello.c.o,
|
||||
# which is stupid since hello.c is a static file.
|
||||
stamp(t)
|
||||
return # success
|
||||
else:
|
||||
unlink(sname('dep', t))
|
||||
open(sname('dep', t), 'w').close()
|
||||
open(sname('gen', t), 'w').close() # it's definitely a generated file
|
||||
(dofile, basename, ext) = find_do_file(t)
|
||||
if not dofile:
|
||||
raise BuildError('no rule to make %r' % t)
|
||||
stamp(dofile)
|
||||
unlink(t)
|
||||
tmpname = '%s.redo.tmp' % t
|
||||
unlink(tmpname)
|
||||
f = open(tmpname, 'w+')
|
||||
|
||||
# this will run in the dofile's directory, so use only basenames here
|
||||
argv = ['sh', '-e',
|
||||
os.path.basename(dofile),
|
||||
os.path.basename(t), 'FIXME', os.path.basename(tmpname)]
|
||||
os.path.basename(basename), # target name (extension removed)
|
||||
ext, # extension (if any), including leading dot
|
||||
os.path.basename(tmpname) # randomized output file name
|
||||
]
|
||||
if vars.VERBOSE:
|
||||
argv[1] += 'v'
|
||||
log('%s\n' % relpath(t, vars.STARTDIR))
|
||||
|
|
|
|||
6
t/.gitignore
vendored
Normal file
6
t/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
c
|
||||
c.c
|
||||
c.c.c
|
||||
c.c.c.b
|
||||
c.c.c.b.b
|
||||
d
|
||||
2
t/all.do
2
t/all.do
|
|
@ -1,2 +1,2 @@
|
|||
redo-ifchange hello yellow bellow
|
||||
redo-ifchange hello yellow bellow c d
|
||||
|
||||
|
|
|
|||
1
t/c.c.c.b.b.a
Normal file
1
t/c.c.c.b.b.a
Normal file
|
|
@ -0,0 +1 @@
|
|||
chicken
|
||||
3
t/c.do
Normal file
3
t/c.do
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
redo-ifchange $1$2.c
|
||||
echo c.do
|
||||
cat $1$2.c
|
||||
3
t/clean.do
Normal file
3
t/clean.do
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
rm -f c c.c c.c.c c.c.c.b c.c.c.b.b d
|
||||
|
||||
|
||||
10
t/default.b.do
Normal file
10
t/default.b.do
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
if [ -e "$1$2.a" -o -e "default$2.a" ]; then
|
||||
redo-ifchange "$1$2.a"
|
||||
echo a-to-b
|
||||
cat "$1$2.a"
|
||||
else
|
||||
redo-ifchange "$1$2.b"
|
||||
echo b-to-b
|
||||
cat "$1$2.b"
|
||||
fi
|
||||
./sleep 1.1
|
||||
4
t/default.c.c.do
Normal file
4
t/default.c.c.do
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
redo-ifchange $1$2.b
|
||||
echo b-to-cc
|
||||
cat $1$2.b
|
||||
./sleep 1.2
|
||||
4
t/default.c.do
Normal file
4
t/default.c.do
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
redo-ifchange $1$2.c
|
||||
echo c-to-c
|
||||
cat $1$2.c
|
||||
./sleep 1.3
|
||||
4
t/default.do
Normal file
4
t/default.do
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
redo-ifchange c
|
||||
echo default-rule
|
||||
cat c
|
||||
./sleep 1.4
|
||||
Loading…
Add table
Add a link
Reference in a new issue