Add a getcwd() method to Node.FS so we can wrap up a delayed call to setting the...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 19 Dec 2001 19:10:20 +0000 (19:10 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 19 Dec 2001 19:10:20 +0000 (19:10 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@165 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Node/__init__.py

index c7551afc5716ab80e18753aff598192609a8706c..d22162953abfaa83fa9359814526f32f851cc4ac 100644 (file)
@@ -180,7 +180,7 @@ class BuilderBase:
                                 self.node_factory)
 
        for t in tlist:
-            t.cwd = SCons.Node.FS.default_fs.cwd       # XXX
+            t.cwd = SCons.Node.FS.default_fs.getcwd()  # XXX
            t.builder_set(self)
            t.env_set(env)
            t.add_source(slist)
index 6a7fcc895ff49c280ff91c10e10dfe89a3e18875..5cc06acfbbfab38e27e7b910c0374185ea3c764c 100644 (file)
@@ -143,7 +143,7 @@ class FS:
             self.Top.path = '.'
             self.Top.srcpath = '.'
             self.Top.path_ = os.path.join('.', '')
-            self.cwd = self.Top
+            self._cwd = self.Top
         
     def __hash__(self):
         self.__setTopLevelDir()
@@ -155,6 +155,10 @@ class FS:
             other.__setTopLevelDir()
        return cmp(self.__dict__, other.__dict__)
 
+    def getcwd(self):
+        self.__setTopLevelDir()
+       return self._cwd
+
     def __doLookup(self, fsclass, name, directory=None):
         """This method differs from the File and Dir factory methods in
         one important way: the meaning of the directory parameter.
@@ -228,7 +232,7 @@ class FS:
             directory = self.Top
             name = os.path.join(os.path.normpath('./'), name[1:])
         elif not directory:
-            directory = self.cwd
+            directory = self._cwd
         return (name, directory)
 
     def chdir(self, dir):
@@ -236,7 +240,7 @@ class FS:
         """
         self.__setTopLevelDir()
         if not dir is None:
-            self.cwd = dir
+            self._cwd = dir
 
     def Entry(self, name, directory = None):
         """Lookup or create a generic Entry node with the specified name.
index 6851e5ec91521bc64371b812392361e81e1c34db..f97627e89f93f5dbeae3713f5f296df56cd8979e 100644 (file)
@@ -416,6 +416,14 @@ class FSTestCase(unittest.TestCase):
         val[e] = 'e'
         for k, v in val.items():
              assert k == os.path.normpath("hash/" + v)
+
+       # Test getcwd()
+        fs = SCons.Node.FS.FS()
+       assert str(fs.getcwd()) == ".", str(fs.getcwd())
+       fs.chdir(fs.Dir('subdir'))
+       assert str(fs.getcwd()) == "subdir", str(fs.getcwd())
+       fs.chdir(fs.Dir('../..'))
+       assert str(fs.getcwd()) == test.workdir, str(fs.getcwd())
         
         #XXX test exists()
 
index 0682c7f10fbaaa25138277a3e62b9cd689225953..b81f911c29923fb44fa5e25db7664c10e104091b 100644 (file)
@@ -118,7 +118,7 @@ class Node:
             def get_contents(self):
                 env = self.node.env.Dictionary()
                 try:
-                    dir = self.node.cwd
+                    dir = self.node.getcwd()
                 except AttributeError:
                     dir = None
                 return self.node.builder.get_contents(env = env, dir = dir)