diff options
| author | Steven Knight <knight@baldmt.com> | 2003-02-26 17:40:22 (GMT) |
|---|---|---|
| committer | Steven Knight <knight@baldmt.com> | 2003-02-26 17:40:22 (GMT) |
| commit | c98c5391f5afa134589db88ebe986368a1b6097f (patch) | |
| tree | 1a7e0f06222b16f346e09b1dcfc185e470fbd3e5 /src/engine/SCons/Node/FS.py | |
| parent | 8a816e6362b715a238183ae25551dbb6df7cddc3 (diff) | |
| download | SCons-c98c5391f5afa134589db88ebe986368a1b6097f.zip SCons-c98c5391f5afa134589db88ebe986368a1b6097f.tar.gz SCons-c98c5391f5afa134589db88ebe986368a1b6097f.tar.bz2 | |
Fix str(Node.FS) in an SConscript file, and add a separate src_dir argument to SConscript(). (Charles Crain)
Diffstat (limited to 'src/engine/SCons/Node/FS.py')
| -rw-r--r-- | src/engine/SCons/Node/FS.py | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 8d5a45f..a6dd7ae 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -168,6 +168,9 @@ class ParentOfRoot: def get_dir(self): return None + def recurse_get_path(self, dir, path_elems): + return path_elems + def src_builder(self): return None @@ -201,6 +204,7 @@ class Entry(SCons.Node.Node): self.name = name self.fs = fs + self.relpath = {} assert directory, "A directory must be provided" @@ -222,8 +226,8 @@ class Entry(SCons.Node.Node): def __str__(self): """A FS node's string representation is its path name.""" if self.duplicate or self.has_builder(): - return self.path - return self.srcnode().path + return self.get_path() + return self.srcnode().get_path() def get_contents(self): """Fetch the contents of the entry. @@ -297,6 +301,32 @@ class Entry(SCons.Node.Node): self._srcnode = self return self._srcnode + def recurse_get_path(self, dir, path_elems): + """Recursively build a path relative to a supplied directory + node.""" + if self != dir: + path_elems.append(self.name) + path_elems = self.dir.recurse_get_path(dir, path_elems) + return path_elems + + def get_path(self, dir=None): + """Return path relative to the current working directory of the + FS object that owns us.""" + if not dir: + dir = self.fs.getcwd() + try: + return self.relpath[dir] + except KeyError: + if self == dir: + # Special case, return "." as the path + ret = '.' + else: + path_elems = self.recurse_get_path(dir, []) + path_elems.reverse() + ret = string.join(path_elems, os.sep) + self.relpath[dir] = ret + return ret + def set_src_builder(self, builder): """Set the source code builder for this node.""" self.sbuilder = builder @@ -474,12 +504,16 @@ class FS: directory = self._cwd return (os.path.normpath(name), directory) - def chdir(self, dir): + def chdir(self, dir, change_os_dir=0): """Change the current working directory for lookups. + If change_os_dir is true, we will also change the "real" cwd + to match. """ self.__setTopLevelDir() if not dir is None: self._cwd = dir + if change_os_dir: + os.chdir(dir.abspath) def Entry(self, name, directory = None, create = 1, klass=None): """Lookup or create a generic Entry node with the specified name. @@ -863,11 +897,11 @@ class File(Entry): def get_contents(self): if not self.rexists(): return '' - return open(self.rstr(), "rb").read() + return open(self.rfile().abspath, "rb").read() def get_timestamp(self): if self.rexists(): - return os.path.getmtime(self.rstr()) + return os.path.getmtime(self.rfile().abspath) else: return 0 |
