orig[val] = None
self.scanner_map_delete(kw)
+ # allow Dirs and strings beginning with # for top-relative
+ # Note this uses the current env's fs (in self).
+ def _canonicalize(self, path):
+ if not SCons.Util.is_String(path): # typically a Dir
+ path = str(path)
+ if path[0] == '#':
+ path = str(self.fs.Dir(path))
+ return path
+
def AppendENVPath(self, name, newpath, envname = 'ENV',
sep = os.pathsep, delete_existing=1):
"""Append path elements to the path 'name' in the 'ENV'
if self._dict.has_key(envname) and self._dict[envname].has_key(name):
orig = self._dict[envname][name]
- nv = SCons.Util.AppendPath(orig, newpath, sep, delete_existing)
+ nv = SCons.Util.AppendPath(orig, newpath, sep, delete_existing,
+ canonicalize=self._canonicalize)
if not self._dict.has_key(envname):
self._dict[envname] = {}
if self._dict.has_key(envname) and self._dict[envname].has_key(name):
orig = self._dict[envname][name]
- nv = SCons.Util.PrependPath(orig, newpath, sep, delete_existing)
+ nv = SCons.Util.PrependPath(orig, newpath, sep, delete_existing,
+ canonicalize=self._canonicalize)
if not self._dict.has_key(envname):
self._dict[envname] = {}
assert(env1['ENV']['PATH'] == r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three')
assert(env1['MYENV']['MYPATH'] == r'C:\mydir\num\two;C:\mydir\num\three;C:\mydir\num\one')
+ test = TestCmd.TestCmd(workdir = '')
+ test.subdir('sub1', 'sub2')
+ p=env1['ENV']['PATH']
+ env1.AppendENVPath('PATH','#sub1', sep = ';')
+ env1.AppendENVPath('PATH',env1.fs.Dir('sub2'), sep = ';')
+ assert env1['ENV']['PATH'] == p + ';sub1;sub2', env1['ENV']['PATH']
+
def test_AppendUnique(self):
"""Test appending to unique values to construction variables
assert(env1['ENV']['PATH'] == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one')
assert(env1['MYENV']['MYPATH'] == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two')
- def test_PrependENVPath(self):
- """Test prepending to an ENV path."""
- env1 = self.TestEnvironment(ENV = {'PATH': r'C:\dir\num\one;C:\dir\num\two'},
- MYENV = {'MYPATH': r'C:\mydir\num\one;C:\mydir\num\two'})
- # have to include the pathsep here so that the test will work on UNIX too.
- env1.PrependENVPath('PATH',r'C:\dir\num\two',sep = ';')
- env1.PrependENVPath('PATH',r'C:\dir\num\three',sep = ';')
- env1.PrependENVPath('MYPATH',r'C:\mydir\num\three','MYENV',sep = ';')
- env1.PrependENVPath('MYPATH',r'C:\mydir\num\one','MYENV',sep = ';')
- assert(env1['ENV']['PATH'] == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one')
- assert(env1['MYENV']['MYPATH'] == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two')
+ test = TestCmd.TestCmd(workdir = '')
+ test.subdir('sub1', 'sub2')
+ p=env1['ENV']['PATH']
+ env1.PrependENVPath('PATH','#sub1', sep = ';')
+ env1.PrependENVPath('PATH',env1.fs.Dir('sub2'), sep = ';')
+ assert env1['ENV']['PATH'] == 'sub2;sub1;' + p, env1['ENV']['PATH']
def test_PrependUnique(self):
"""Test prepending unique values to construction variables
continue
return None
-def PrependPath(oldpath, newpath, sep = os.pathsep, delete_existing=1):
+def PrependPath(oldpath, newpath, sep = os.pathsep,
+ delete_existing=1, canonicalize=None):
"""This prepends newpath elements to the given oldpath. Will only
add any particular path once (leaving the first one it encounters
and ignoring the rest, to preserve path order), and will
If delete_existing is 0, then adding a path that exists will
not move it to the beginning; it will stay where it is in the
list.
+
+ If canonicalize is not None, it is applied to each element of
+ newpath before use.
"""
orig = oldpath
paths = string.split(paths, sep)
is_list = 0
- if is_List(newpath) or is_Tuple(newpath):
- newpaths = newpath
- else:
+ if is_String(newpath):
newpaths = string.split(newpath, sep)
+ elif not is_List(newpath) and not is_Tuple(newpath):
+ newpaths = [ newpath ] # might be a Dir
+ else:
+ newpaths = newpath
+
+ if canonicalize:
+ newpaths=map(canonicalize, newpaths)
if not delete_existing:
# First uniquify the old paths, making sure to
else:
return string.join(paths, sep)
-def AppendPath(oldpath, newpath, sep = os.pathsep, delete_existing=1):
+def AppendPath(oldpath, newpath, sep = os.pathsep,
+ delete_existing=1, canonicalize=None):
"""This appends new path elements to the given old path. Will
only add any particular path once (leaving the last one it
encounters and ignoring the rest, to preserve path order), and
If delete_existing is 0, then adding a path that exists
will not move it to the end; it will stay where it is in the list.
+
+ If canonicalize is not None, it is applied to each element of
+ newpath before use.
"""
orig = oldpath
paths = string.split(paths, sep)
is_list = 0
- if is_List(newpath) or is_Tuple(newpath):
- newpaths = newpath
- else:
+ if is_String(newpath):
newpaths = string.split(newpath, sep)
+ elif not is_List(newpath) and not is_Tuple(newpath):
+ newpaths = [ newpath ] # might be a Dir
+ else:
+ newpaths = newpath
+
+ if canonicalize:
+ newpaths=map(canonicalize, newpaths)
if not delete_existing:
# add old paths to result, then