Fix a side effect of chdir to SConscript directory.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 27 Mar 2003 17:41:13 +0000 (17:41 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 27 Mar 2003 17:41:13 +0000 (17:41 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@625 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Script/SConscript.py
test/Repository/SConscript.py

index 0fe0d64df77036d346e65dd7197ee82afae3ce55..df86853d14c5ddb679cc4f8ee2e2a271283beb5c 100644 (file)
@@ -265,7 +265,13 @@ def SConscript(*ls, **kw):
             frame = stack.pop()
             default_fs.chdir(frame.prev_dir)
             if old_dir:
-                default_fs.chdir(old_dir, change_os_dir=sconscript_chdir)
+                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)
 
             results.append(frame.retval)
 
index 0d979f6c3ee17548289f6ab5dabfcebe2c69e970..14a7c54d01c552c2cb7975a149e9c186a9403f95 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+"""
+Test how we handle SConscript calls when using a Repository.
+"""
+
 import sys
 import TestSCons
 
@@ -37,68 +41,86 @@ test = TestSCons.TestSCons()
 #
 test.subdir('work',
             ['work', 'src'],
-            'repository',
-            ['repository', 'src'])
+            'rep1',
+            ['rep1', 'src'],
+            'rep2',
+            ['rep2', 'build'],
+            ['rep2', 'src'],
+            ['rep2', 'src', 'sub'])
 
 #
-workpath_repository = test.workpath('repository')
-work_src_foo = test.workpath('work', 'src', 'foo' + _exe)
+workpath_rep1 = test.workpath('rep1')
+workpath_rep2 = test.workpath('rep2')
 
 #
 test.write(['work', 'SConstruct'], """
 Repository(r'%s')
 SConscript('src/SConscript')
-""" % workpath_repository)
-
-test.write(['repository', 'src', 'SConscript'], """
-env = Environment()
-env.Program(target = 'foo', source = ['aaa.c', 'bbb.c', 'main.c'])
+""" % workpath_rep1)
+
+test.write(['rep1', 'src', 'SConscript'], """\
+def cat(env, source, target):
+    target = str(target[0])
+    source = map(str, source)
+    f = open(target, "wb")
+    for src in source:
+        f.write(open(src, "rb").read())
+    f.close()
+env = Environment(BUILDERS={'Cat':Builder(action=cat)})
+env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
 """)
 
-test.write(['repository', 'src', 'aaa.c'], r"""
-void
-aaa(void)
-{
-       printf("repository/src/aaa.c\n");
-}
+test.write(['rep1', 'src', 'aaa.in'], "rep1/src/aaa.in\n")
+test.write(['rep1', 'src', 'bbb.in'], "rep1/src/bbb.in\n")
+test.write(['rep1', 'src', 'ccc.in'], "rep1/src/ccc.in\n")
+
+# Make the rep1 non-writable,
+# so we'll detect if we try to write into it accidentally.
+test.writable('rep1', 0)
+
+test.run(chdir = 'work', arguments = ".")
+
+test.fail_test(test.read(['work', 'src', 'foo']) != """\
+rep1/src/aaa.in
+rep1/src/bbb.in
+rep1/src/ccc.in
 """)
 
-test.write(['repository', 'src', 'bbb.c'], r"""
-void
-bbb(void)
-{
-       printf("repository/src/bbb.c\n");
-}
+test.up_to_date(chdir = 'work', arguments = ".")
+
+#
+test.write(['rep2', 'build', 'SConstruct'], """
+Repository(r'%s')
+SConscript('src/SConscript')
+""" % workpath_rep2)
+
+test.write(['rep2', 'src', 'SConscript'], """\
+def cat(env, source, target):
+    target = str(target[0])
+    source = map(str, source)
+    f = open(target, "wb")
+    for src in source:
+        f.write(open(src, "rb").read())
+    f.close()
+env = Environment(BUILDERS={'Cat':Builder(action=cat)})
+env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
+SConscript('sub/SConscript')
 """)
 
-test.write(['repository', 'src', 'main.c'], r"""
-extern void aaa(void);
-extern void bbb(void);
-
-int
-main(int argc, char *argv[])
-{
-       argv[argc++] = "--";
-       aaa();
-       bbb();
-       printf("repository/src/main.c\n");
-       exit (0);
-}
+test.write(['rep2', 'src', 'sub', 'SConscript'], """\
 """)
 
-# Make the repository non-writable,
-# so we'll detect if we try to write into it accidentally.
-test.writable('repository', 0)
+test.write(['rep2', 'src', 'aaa.in'], "rep2/src/aaa.in\n")
+test.write(['rep2', 'src', 'bbb.in'], "rep2/src/bbb.in\n")
+test.write(['rep2', 'src', 'ccc.in'], "rep2/src/ccc.in\n")
 
-test.run(chdir = 'work', arguments = ".")
+test.run(chdir = 'rep2/build', arguments = ".")
 
-test.run(program = work_src_foo, stdout =
-"""repository/src/aaa.c
-repository/src/bbb.c
-repository/src/main.c
+test.fail_test(test.read(['rep2', 'build', 'src', 'foo']) != """\
+rep2/src/aaa.in
+rep2/src/bbb.in
+rep2/src/ccc.in
 """)
 
-test.up_to_date(chdir = 'work', arguments = ".")
-
 #
 test.pass_test()