From f63429682eca0f75ba22c2e01f155bb8d986bd85 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Thu, 27 Mar 2003 17:41:13 +0000 Subject: Fix a side effect of chdir to SConscript directory. --- src/engine/SCons/Script/SConscript.py | 8 ++- test/Repository/SConscript.py | 110 ++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 45 deletions(-) diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 0fe0d64..df86853 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -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) diff --git a/test/Repository/SConscript.py b/test/Repository/SConscript.py index 0d979f6..14a7c54 100644 --- a/test/Repository/SConscript.py +++ b/test/Repository/SConscript.py @@ -24,6 +24,10 @@ __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() -- cgit v0.12