<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>
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.")
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()