Skip to content

Commit

Permalink
builder.py: correctly set $3 to include the subdir path.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apenwarr committed Jan 18, 2011
1 parent f3ae4e4 commit c077d77
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
16 changes: 9 additions & 7 deletions builder.py
Expand Up @@ -15,7 +15,8 @@ def _default_do_files(filename):

def _possible_do_files(t):
dirname,filename = os.path.split(t)
yield os.path.join(vars.BASE, dirname), "%s.do" % filename, filename, ''
yield (os.path.join(vars.BASE, dirname), "%s.do" % filename,
'', filename, '')

# It's important to try every possibility in a directory before resorting
# to a parent directory. Think about nested projects: I don't want
Expand All @@ -30,19 +31,20 @@ def _possible_do_files(t):
basedir = join('/', dirbits[:i])
subdir = join('/', dirbits[i:])
for dofile,basename,ext in _default_do_files(filename):
yield basedir, dofile, os.path.join(subdir, basename), ext
yield (basedir, dofile,
subdir, os.path.join(subdir, basename), ext)


def _find_do_file(f):
for dodir,dofile,basename,ext in _possible_do_files(f.name):
for dodir,dofile,basedir,basename,ext in _possible_do_files(f.name):
dopath = os.path.join(dodir, dofile)
debug2('%s: %s:%s ?\n' % (f.name, dodir, dofile))
if os.path.exists(dopath):
f.add_dep('m', dopath)
return dodir,dofile,basename,ext
return dodir,dofile,basedir,basename,ext
else:
f.add_dep('c', dopath)
return None,None,None,None
return None,None,None,None,None


def _nice(t):
Expand Down Expand Up @@ -120,7 +122,7 @@ def _start_do(self):
sf.save()
return self._after2(0)
sf.zap_deps1()
(dodir, dofile, basename, ext) = _find_do_file(sf)
(dodir, dofile, basedir, basename, ext) = _find_do_file(sf)
if not dofile:
if os.path.exists(t):
sf.set_static()
Expand All @@ -139,7 +141,7 @@ def _start_do(self):
dofile,
basename, # target name (no extension)
ext, # extension (if any), including leading dot
os.path.basename(self.tmpname2) # randomized output file name
os.path.join(basedir, os.path.basename(self.tmpname2)) # temp output file name
]
if vars.VERBOSE: argv[1] += 'v'
if vars.XTRACE: argv[1] += 'x'
Expand Down
3 changes: 1 addition & 2 deletions t/defaults-nested/default.do
@@ -1,2 +1 @@
echo root $1 $2

echo root $1 $2 "$(dirname $3)"
10 changes: 5 additions & 5 deletions t/defaults-nested/test.do
Expand Up @@ -15,19 +15,19 @@ check()
fi
}

check file.x.y.z "root file.x.y.z"
check file.z "root file.z"
check file "root file"
check file.x.y.z "root file.x.y.z ."
check file.z "root file.z ."
check file "root file ."

check a/file.x.y.z "default.x.y.z file .x.y.z"
check a/file.y.z "default.z file.y .z"
check a/file.z "default.z file .z"
check a/file "root a/file"
check a/file "root a/file a"

check a/b/file.x.y.z "file file.x.y.z"
check a/b/file.y.z "default.y.z file .y.z"
check a/b/file.z "default.z b/file .z"
check a/b/file "root a/b/file"
check a/b/file "root a/b/file a/b"

check a/d/file.x.y.z "default file.x.y.z"
check a/d/file.y.z "default file.y.z"
Expand Down

0 comments on commit c077d77

Please sign in to comment.