Fix a bug when BuildDir(duplicate=0) is used with multiple SConscript files. (Charles...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 30 Mar 2003 16:55:46 +0000 (16:55 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 30 Mar 2003 16:55:46 +0000 (16:55 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@630 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Script/SConscript.py
src/engine/SCons/Tool/Perforce.py

index 542eefded80648bbe5503c97607be98e24c139d5..8aa67dd3235f96c3d86b0fcf43687765e74d773e 100644 (file)
 
 RELEASE 0.13 - XXX
 
+  From Charles Crain:
+
+  - Fix a bug when BuildDir(duplicate=0) is used and SConscript
+    files are called from within other SConscript files.
+
+  - Support (older) versions of Perforce which don't set the Windows
+    registry.
+
 
 
 RELEASE 0.12 - Thu, 27 Mar 2003 23:52:09 -0600
index 0afc3d8b8fc372d5d648f7cd3a9627680ef24550..f380f7eed523656fd232001f8a7be7f8031d06de 100644 (file)
@@ -557,10 +557,15 @@ class FS:
         to match.
         """
         self.__setTopLevelDir()
-        if not dir is None:
-            self._cwd = dir
-            if change_os_dir:
-                os.chdir(dir.abspath)
+        curr=self._cwd
+        try:
+            if not dir is None:
+                self._cwd = dir
+                if change_os_dir:
+                    os.chdir(dir.abspath)
+        except:
+            self._cwd = curr
+            raise
 
     def Entry(self, name, directory = None, create = 1, klass=None):
         """Lookup or create a generic Entry node with the specified name.
@@ -640,6 +645,13 @@ class FS:
             n = self.__doLookup(clazz, name, d)
             if n.exists():
                 return n
+            if isinstance(n, Dir):
+                # If n is a Directory that has Repositories directly
+                # attached to it, then any of those is a valid Repository
+                # path.  Return the first one that exists.
+                reps = filter(lambda x: x.exists(), n.getRepositories())
+                if len(reps):
+                    return reps[0]
             d = n.get_dir()
             name = n.name
             # Search repositories of all directories that this file is under.
index 0bba0ed2ff305dba0d6bcf1d9f7a63b622e9d48d..7836a1337d10726379ce0b65c419d66dfad1cc45 100644 (file)
@@ -378,6 +378,14 @@ class BuildDirTestCase(unittest.TestCase):
             test.unlink( "src/foo" )
             test.unlink( "build/foo" )
 
+        # Test against a former bug.  Make sure we can get a repository
+        # path for the build directory itself!
+        fs=SCons.Node.FS.FS(test.workpath('work'))
+        test.subdir('work')
+        fs.BuildDir('build/var3', 'src', duplicate=0)
+        d1 = fs.Dir('build/var3')
+        assert d1.rdir() == fs.Dir('src'), str(d1.rdir())
+
         # verify the link creation attempts in file_link()
         class LinkSimulator :
             """A class to intercept os.[sym]link() calls and track them."""
index df86853d14c5ddb679cc4f8ee2e2a271283beb5c..c0d82ce69b189d127d1880e3af6875f36856c072 100644 (file)
@@ -191,7 +191,6 @@ def SConscript(*ls, **kw):
     results = []
     for fn in files:
         stack.append(Frame(exports))
-        old_dir = None
         old_sys_path = sys.path
         try:
             if fn == "-":
@@ -202,7 +201,6 @@ def SConscript(*ls, **kw):
                 else:
                     f = default_fs.File(str(fn))
                 _file_ = None
-                old_dir = default_fs.getcwd()
 
                 # Change directory to the top of the source
                 # tree to make sure the os's cwd and the cwd of
@@ -242,6 +240,7 @@ def SConscript(*ls, **kw):
                         # default_fs.chdir(), because we still need to
                         # interpret the stuff within the SConscript file
                         # relative to where we are logically.
+                        default_fs.chdir(ldir, change_os_dir=0)
                         os.chdir(f.rfile().dir.abspath)
 
                     # Append the SConscript directory to the beginning
@@ -263,15 +262,14 @@ def SConscript(*ls, **kw):
         finally:
             sys.path = old_sys_path
             frame = stack.pop()
-            default_fs.chdir(frame.prev_dir)
-            if old_dir:
-                try:
-                    default_fs.chdir(old_dir, change_os_dir=sconscript_chdir)
-                except OSError:
-                    # There was no local directory, so chdir to the
-                    # Repository directory.  Like above, we do this
-                    # directly.
-                    os.chdir(old_dir.rdir().abspath)
+            try:
+                default_fs.chdir(frame.prev_dir, change_os_dir=sconscript_chdir)
+            except OSError:
+                # There was no local directory, so chdir to the
+                # Repository directory.  Like above, we do this
+                # directly.
+                default_fs.chdir(frame.prev_dir, change_os_dir=0)
+                os.chdir(frame.prev_dir.rdir().abspath)
 
             results.append(frame.retval)
 
index 7c1a2a7ddeae5240aee69b084acd5af94551c517..2f9fb88c491ca6f0afb646ba39f61c1fe66e85b0 100644 (file)
@@ -79,10 +79,15 @@ def generate(env, platform):
 
     if SCons.Util.can_read_reg:
         # If we can read the registry, add the path to Perforce to our environment.
-        k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
-                                  'Software\\Perforce\\environment')
-        val, tok = SCons.Util.RegQueryValueEx(k, 'P4INSTROOT')
-        addPathIfNotExists(environ, 'PATH', val)
+        try:
+            k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
+                                      'Software\\Perforce\\environment')
+            val, tok = SCons.Util.RegQueryValueEx(k, 'P4INSTROOT')
+            addPathIfNotExists(environ, 'PATH', val)
+        except SCons.Util.RegError:
+            # Can't detect where Perforce is, hope the user has it set in the
+            # PATH.
+            pass
 
 def exists(env):
     return env.Detect('p4')