diff options
author | Gary Oberbrunner <garyo@oberbrunner.com> | 2009-01-01 13:18:06 (GMT) |
---|---|---|
committer | Gary Oberbrunner <garyo@oberbrunner.com> | 2009-01-01 13:18:06 (GMT) |
commit | e40b2b0ff3c82d704867a99662ebaad0597f0990 (patch) | |
tree | 9ae7dedcbcc3b5da01aaa084c59421f5b40d9f37 | |
parent | cc05c121706797a7708d135ce20ff40039111fa7 (diff) | |
download | SCons-e40b2b0ff3c82d704867a99662ebaad0597f0990.zip SCons-e40b2b0ff3c82d704867a99662ebaad0597f0990.tar.gz SCons-e40b2b0ff3c82d704867a99662ebaad0597f0990.tar.bz2 |
Fix bug 2193: http://scons.tigris.org/issues/show_bug.cgi?id=2193
Ap/PrependENVPath now accept paths starting with # and Dirs. Added
optional _canonicalize arg to SCons.Util.Ap/PrependPath, and pass an
implementation of that into them from Environment.Ap/PrependENVPath.
Can't just always do the canonicalization in SCons.Util because there
is no env there to get the fs to convert a #-prefixed path to the
proper path.
-rw-r--r-- | src/engine/SCons/Environment.py | 15 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 24 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 34 |
3 files changed, 52 insertions, 21 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 2304f2f..c2a7c76 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -1198,6 +1198,15 @@ class Base(SubstitutionEnvironment): 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' @@ -1214,7 +1223,8 @@ class Base(SubstitutionEnvironment): 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] = {} @@ -1569,7 +1579,8 @@ class Base(SubstitutionEnvironment): 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] = {} diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index f3210b8..0ea9dda 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -1613,6 +1613,13 @@ def exists(env): 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 @@ -2259,17 +2266,12 @@ f5: \ 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 diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index bbd985d..b47e262 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -839,7 +839,8 @@ else: 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 @@ -856,6 +857,9 @@ def PrependPath(oldpath, newpath, sep = os.pathsep, delete_existing=1): 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 @@ -865,10 +869,15 @@ def PrependPath(oldpath, newpath, sep = os.pathsep, delete_existing=1): 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 @@ -912,7 +921,8 @@ def PrependPath(oldpath, newpath, sep = os.pathsep, delete_existing=1): 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 @@ -928,6 +938,9 @@ def AppendPath(oldpath, newpath, sep = os.pathsep, delete_existing=1): 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 @@ -937,10 +950,15 @@ def AppendPath(oldpath, newpath, sep = os.pathsep, delete_existing=1): 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 |