From 3e9f7e859d335a3e67e30fc89a264694cfe5f67b Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 10 Sep 2001 23:38:55 +0000 Subject: [PATCH] Add -C support. git-svn-id: http://scons.tigris.org/svn/scons/trunk@38 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/options.sgml | 9 +++++---- src/scons.py | 8 +++++++- test/option--C.py | 48 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/doc/man/options.sgml b/doc/man/options.sgml index b24c18fa..b88a5850 100644 --- a/doc/man/options.sgml +++ b/doc/man/options.sgml @@ -111,11 +111,12 @@ Sconstruct or sconstruct file, or doing anything else. Multiple options are interpreted - relative to the previous one. (This is nearly equivalent - to -f directory/SConstruct, except - that it will search for SConstruct, + relative to the previous one, and the right-most + option wins. (This option is nearly + equivalent to -f directory/SConstruct, + except that it will search for SConstruct, Sconstruct, or - sconstruct in the directory.) + sconstruct in the specified directory.) diff --git a/src/scons.py b/src/scons.py index f624fba5..66932f69 100644 --- a/src/scons.py +++ b/src/scons.py @@ -248,7 +248,13 @@ Option(func = opt_not_yet, future = 1, long = ['cache-show'], help = "Print what would have built Cached targets.") -Option(func = opt_not_yet, +def opt_C(opt, arg): + try: + os.chdir(arg) + except: + sys.stderr.write("Could not change directory to 'arg'\n") + +Option(func = opt_C, short = 'C', long = ['directory'], arg = 'DIRECTORY', help = "Change to DIRECTORY before doing anything.") diff --git a/test/option--C.py b/test/option--C.py index db3402db..d1389bbb 100644 --- a/test/option--C.py +++ b/test/option--C.py @@ -10,17 +10,51 @@ test = TestCmd.TestCmd(program = 'scons.py', workdir = '', interpreter = 'python') -test.write('SConstruct', "") +wpath = test.workpath() +wpath_sub = test.workpath('sub') +wpath_sub_dir = test.workpath('sub', 'dir') -test.run(chdir = '.', arguments = '-C foo') +test.subdir('sub', ['sub', 'dir']) -test.fail_test(test.stderr() != - "Warning: the -C option is not yet implemented\n") +test.write('SConstruct', """ +import os +print "SConstruct", os.getcwd() +""") -test.run(chdir = '.', arguments = '--directory=foo') +test.write(['sub', 'SConstruct'], """ +import os +print "sub/SConstruct", os.getcwd() +""") -test.fail_test(test.stderr() != - "Warning: the --directory option is not yet implemented\n") +test.write(['sub', 'dir', 'SConstruct'], """ +import os +print "sub/dir/SConstruct", os.getcwd() +""") + +test.run(chdir = '.', arguments = '-C sub') + +test.fail_test(test.stdout() != "sub/SConstruct %s\n" % wpath_sub) +test.fail_test(test.stderr() != "") + +test.run(chdir = '.', arguments = '-C sub -C dir') + +test.fail_test(test.stdout() != "sub/dir/SConstruct %s\n" % wpath_sub_dir) +test.fail_test(test.stderr() != "") + +test.run(chdir = '.') + +test.fail_test(test.stdout() != "SConstruct %s\n" % wpath) +test.fail_test(test.stderr() != "") + +test.run(chdir = '.', arguments = '--directory=sub/dir') + +test.fail_test(test.stdout() != "sub/dir/SConstruct %s\n" % wpath_sub_dir) +test.fail_test(test.stderr() != "") + +test.run(chdir = '.', arguments = '-C %s -C %s' % (wpath_sub_dir, wpath_sub)) + +test.fail_test(test.stdout() != "sub/SConstruct %s\n" % wpath_sub) +test.fail_test(test.stderr() != "") test.pass_test() -- 2.26.2