Add -C support.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 10 Sep 2001 23:38:55 +0000 (23:38 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 10 Sep 2001 23:38:55 +0000 (23:38 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@38 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/options.sgml
src/scons.py
test/option--C.py

index b24c18fae5162b2e4008d13cbde32ec1deff740d..b88a58508b8df18cc40cb5fcea5a23a59aa7a29f 100644 (file)
         <filename>Sconstruct</filename> or
         <filename>sconstruct</filename> file, or doing anything
         else.  Multiple <option>-C</option> options are interpreted
-        relative to the previous one.  (This is nearly equivalent
-        to <literal>-f directory/SConstruct</literal>, except
-        that it will search for <filename>SConstruct</filename>,
+        relative to the previous one, and the right-most
+        <option>-C</option> option wins.  (This option is nearly
+        equivalent to <literal>-f directory/SConstruct</literal>,
+        except that it will search for <filename>SConstruct</filename>,
         <filename>Sconstruct</filename>, or
-        <filename>sconstruct</filename> in the directory.)
+        <filename>sconstruct</filename> in the specified directory.)
 
       </para>
     </listitem>
index f624fba5e62094b88afa32f0818fb1bc2a3f4086..66932f69080de1275742e3e38b73d824c876042b 100644 (file)
@@ -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.")
 
index db3402db1a52ed911932817307bce15b12d589fa..d1389bbbff1fb1512b5c02dcdd27f135973e8983 100644 (file)
@@ -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()