Commits

Anonymous committed 51228c7

Add support for Default() targets.

Comments (0)

Files changed (2)

src/script/scons.py

 
 # Global variables
 
+default_targets = []
 local_help = None
 num_jobs = 1
 Scripts = []
     global Scripts
     Scripts.append(filename)
 
+def Default(*targets):
+    for t in targets:
+	for s in string.split(t):
+	    default_targets.append(s)
+
 def Help(text):
     global local_help
     if local_help:
 	PrintUsage()
 	sys.exit(0)
 
+    if not targets:
+	targets = default_targets
+
     taskmaster = Taskmaster(map(
     			lambda x: SCons.Node.FS.default_fs.File(x),
 			targets))
+#!/usr/bin/env python
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import os
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('one', 'two', 'three')
+
+test.write(['one', 'SConstruct'], """
+env = Environment()
+env.Program(target = 'foo', source = 'foo.c')
+env.Program(target = 'bar', source = 'bar.c')
+Default('foo')
+""")
+
+test.write(['two', 'SConstruct'], """
+env = Environment()
+env.Program(target = 'foo', source = 'foo.c')
+env.Program(target = 'bar', source = 'bar.c')
+Default('foo', 'bar')
+""")
+
+test.write(['three', 'SConstruct'], """
+env = Environment()
+env.Program(target = 'foo', source = 'foo.c')
+env.Program(target = 'bar', source = 'bar.c')
+Default('foo bar')
+""")
+
+for dir in ['one', 'two', 'three']:
+
+    foo_c = os.path.join(dir, 'foo.c')
+    bar_c = os.path.join(dir, 'bar.c')
+
+    test.write(foo_c, """
+int
+main(int argc, char *argv[])
+{
+	printf("%s\n");
+	exit (0);
+}
+""" % foo_c)
+
+    test.write(bar_c, """
+int
+main(int argc, char *argv[])
+{
+	printf("%s\n");
+	exit (0);
+}
+""" % bar_c)
+
+    test.run(chdir = dir)	# no arguments, use the Default
+
+test.run(program = test.workpath('one', 'foo'), stdout = "one/foo.c\n")
+test.fail_test(os.path.exists(test.workpath('one', 'bar')))
+
+test.run(program = test.workpath('two', 'foo'), stdout = "two/foo.c\n")
+test.run(program = test.workpath('two', 'bar'), stdout = "two/bar.c\n")
+
+test.run(program = test.workpath('three', 'foo'), stdout = "three/foo.c\n")
+test.run(program = test.workpath('three', 'bar'), stdout = "three/bar.c\n")
+
+test.pass_test()