Add -n and -s support.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Sep 2001 13:19:48 +0000 (13:19 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Sep 2001 13:19:48 +0000 (13:19 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@40 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/scons.py
src/scons/Builder.py
test/option-n.py
test/option-s.py

index 66932f69080de1275742e3e38b73d824c876042b..2649637f5e0085a1bbeea3ee47eef48dd4d3679c 100644 (file)
@@ -338,7 +338,10 @@ Option(func = opt_not_yet, future = 1,
        long = ['list-where'],
        help = "Don't build; list files and where defined.")
 
-Option(func = opt_not_yet,
+def opt_n(opt, arg):
+    scons.Builder.execute_actions = None
+
+Option(func = opt_n,
        short = 'n', long = ['no-exec', 'just-print', 'dry-run', 'recon'],
        help = "Don't build; just print commands.")
 
@@ -366,7 +369,10 @@ Option(func = opt_not_yet, future = 1,
        long = ['random'],
        help = "Build dependencies in random order.")
 
-Option(func = opt_not_yet,
+def opt_s(opt, arg):
+    scons.Builder.print_actions = None
+
+Option(func = opt_s,
        short = 's', long = ['silent', 'quiet'],
        help = "Don't print commands.")
 
index c11c9f38a9fb61d9d37beeea5b0cbbcb6fa6eef6..8b19bd52ffaa58e3527af5e6d630e29022b4880b 100644 (file)
@@ -51,6 +51,11 @@ class Builder:
 
 
 
+print_actions = 1;
+execute_actions = 1;
+
+
+
 def Action(act):
     """A factory for action objects."""
     if type(act) == types.FunctionType:
@@ -78,8 +83,10 @@ class CommandAction(ActionBase):
 
     def execute(self, **kw):
        cmd = self.command % kw
-       self.show(cmd)
-       os.system(cmd)
+       if print_actions:
+           self.show(cmd)
+       if execute_actions:
+           os.system(cmd)
 
 class FunctionAction(ActionBase):
     """Class for Python function actions."""
@@ -87,5 +94,7 @@ class FunctionAction(ActionBase):
        self.function = function
 
     def execute(self, **kw):
+       # if print_actions:
        # XXX:  WHAT SHOULD WE PRINT HERE?
-       self.function(kw)
+       if execute_actions:
+           self.function(kw)
index 12bacd83d6fe4f297f50acd61cc75e86fd10bd74..245f512a095d6d8fd4d593c02bf97a46de9e8395 100644 (file)
@@ -3,6 +3,7 @@
 __revision__ = "test/option-n.py __REVISION__ __DATE__ __DEVELOPER__"
 
 import TestCmd
+import os.path
 import string
 import sys
 
@@ -10,32 +11,68 @@ test = TestCmd.TestCmd(program = 'scons.py',
                        workdir = '',
                        interpreter = 'python')
 
-test.write('SConstruct', "")
+test.write('build.py', r"""
+import sys
+file = open(sys.argv[1], 'w')
+file.write("build.py: %s\n" % sys.argv[1])
+file.close()
+""")
+
+test.write('SConstruct', """
+MyBuild = Builder(name = "MyBuild",
+                 action = "python build.py %(target)s")
+env = Environment(BUILDERS = [MyBuild])
+env.MyBuild(target = 'f1.out', source = 'f1.in')
+env.MyBuild(target = 'f2.out', source = 'f2.in')
+""")
+
+args = 'f1.out f2.out'
+expect = "python build.py f1.out\npython build.py f2.out\n"
+
+test.run(chdir = '.', arguments = args)
 
-test.run(chdir = '.', arguments = '-n')
+test.fail_test(test.stdout() != expect)
+test.fail_test(test.stderr() != "")
+test.fail_test(not os.path.exists(test.workpath('f1.out')))
+test.fail_test(not os.path.exists(test.workpath('f2.out')))
 
-test.fail_test(test.stderr() !=
-               "Warning:  the -n option is not yet implemented\n")
+os.unlink(test.workpath('f1.out'))
+os.unlink(test.workpath('f2.out'))
 
-test.run(chdir = '.', arguments = '--no-exec')
+test.run(chdir = '.', arguments = '-n ' + args)
 
-test.fail_test(test.stderr() !=
-               "Warning:  the --no-exec option is not yet implemented\n")
+test.fail_test(test.stdout() != expect)
+test.fail_test(test.stderr() != "")
+test.fail_test(os.path.exists(test.workpath('f1.out')))
+test.fail_test(os.path.exists(test.workpath('f2.out')))
 
-test.run(chdir = '.', arguments = '--just-print')
+test.run(chdir = '.', arguments = '--no-exec ' + args)
 
-test.fail_test(test.stderr() !=
-               "Warning:  the --just-print option is not yet implemented\n")
+test.fail_test(test.stdout() != expect)
+test.fail_test(test.stderr() != "")
+test.fail_test(os.path.exists(test.workpath('f1.out')))
+test.fail_test(os.path.exists(test.workpath('f2.out')))
 
-test.run(chdir = '.', arguments = '--dry-run')
+test.run(chdir = '.', arguments = '--just-print ' + args)
 
-test.fail_test(test.stderr() !=
-               "Warning:  the --dry-run option is not yet implemented\n")
+test.fail_test(test.stdout() != expect)
+test.fail_test(test.stderr() != "")
+test.fail_test(os.path.exists(test.workpath('f1.out')))
+test.fail_test(os.path.exists(test.workpath('f2.out')))
 
-test.run(chdir = '.', arguments = '--recon')
+test.run(chdir = '.', arguments = '--dry-run ' + args)
 
-test.fail_test(test.stderr() !=
-               "Warning:  the --recon option is not yet implemented\n")
+test.fail_test(test.stdout() != expect)
+test.fail_test(test.stderr() != "")
+test.fail_test(os.path.exists(test.workpath('f1.out')))
+test.fail_test(os.path.exists(test.workpath('f2.out')))
+
+test.run(chdir = '.', arguments = '--recon ' + args)
+
+test.fail_test(test.stdout() != expect)
+test.fail_test(test.stderr() != "")
+test.fail_test(os.path.exists(test.workpath('f1.out')))
+test.fail_test(os.path.exists(test.workpath('f2.out')))
 
 test.pass_test()
+
index 9f5e20bc513ad707f776ddf56c6fbbc505659a6d..66d92c797e08b0c08e087fe928d135388a8b74b0 100644 (file)
@@ -3,6 +3,7 @@
 __revision__ = "test/option-s.py __REVISION__ __DATE__ __DEVELOPER__"
 
 import TestCmd
+import os.path
 import string
 import sys
 
@@ -10,22 +11,47 @@ test = TestCmd.TestCmd(program = 'scons.py',
                        workdir = '',
                        interpreter = 'python')
 
-test.write('SConstruct', "")
+test.write('build.py', r"""
+import sys
+file = open(sys.argv[1], 'w')
+file.write("build.py: %s\n" % sys.argv[1])
+file.close()
+""")
+
+test.write('SConstruct', """
+MyBuild = Builder(name = "MyBuild",
+                 action = "python build.py %(target)s")
+env = Environment(BUILDERS = [MyBuild])
+env.MyBuild(target = 'f1.out', source = 'f1.in')
+env.MyBuild(target = 'f2.out', source = 'f2.in')
+""")
+
+test.run(chdir = '.', arguments = '-s f1.out f2.out')
+
+test.fail_test(test.stdout() != "")
+test.fail_test(test.stderr() != "")
+test.fail_test(not os.path.exists(test.workpath('f1.out')))
+test.fail_test(not os.path.exists(test.workpath('f2.out')))
 
-test.run(chdir = '.', arguments = '-s')
+os.unlink(test.workpath('f1.out'))
+os.unlink(test.workpath('f2.out'))
 
-test.fail_test(test.stderr() !=
-               "Warning:  the -s option is not yet implemented\n")
+test.run(chdir = '.', arguments = '--silent f1.out f2.out')
 
-test.run(chdir = '.', arguments = '--silent')
+test.fail_test(test.stdout() != "")
+test.fail_test(test.stderr() != "")
+test.fail_test(not os.path.exists(test.workpath('f1.out')))
+test.fail_test(not os.path.exists(test.workpath('f2.out')))
 
-test.fail_test(test.stderr() !=
-               "Warning:  the --silent option is not yet implemented\n")
+os.unlink(test.workpath('f1.out'))
+os.unlink(test.workpath('f2.out'))
 
-test.run(chdir = '.', arguments = '--quiet')
+test.run(chdir = '.', arguments = '--quiet f1.out f2.out')
 
-test.fail_test(test.stderr() !=
-               "Warning:  the --quiet option is not yet implemented\n")
+test.fail_test(test.stdout() != "")
+test.fail_test(test.stderr() != "")
+test.fail_test(not os.path.exists(test.workpath('f1.out')))
+test.fail_test(not os.path.exists(test.workpath('f2.out')))
 
 test.pass_test()