Anonymous avatar Anonymous committed f361dad

Add -n and -s support.

Comments (0)

Files changed (4)

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

src/scons/Builder.py

 
 
 
+print_actions = 1;
+execute_actions = 1;
+
+
+
 def Action(act):
     """A factory for action objects."""
     if type(act) == types.FunctionType:
 
     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."""
 	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)
 __revision__ = "test/option-n.py __REVISION__ __DATE__ __DEVELOPER__"
 
 import TestCmd
+import os.path
 import string
 import sys
 
                        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.run(chdir = '.', arguments = '-n')
+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.fail_test(test.stderr() !=
-		"Warning:  the -n option is not yet implemented\n")
+args = 'f1.out f2.out'
+expect = "python build.py f1.out\npython build.py f2.out\n"
 
-test.run(chdir = '.', arguments = '--no-exec')
+test.run(chdir = '.', arguments = 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(not os.path.exists(test.workpath('f1.out')))
+test.fail_test(not os.path.exists(test.workpath('f2.out')))
 
-test.run(chdir = '.', arguments = '--just-print')
+os.unlink(test.workpath('f1.out'))
+os.unlink(test.workpath('f2.out'))
 
-test.fail_test(test.stderr() !=
-		"Warning:  the --just-print option is not yet implemented\n")
+test.run(chdir = '.', arguments = '-n ' + args)
 
-test.run(chdir = '.', arguments = '--dry-run')
+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.fail_test(test.stderr() !=
-		"Warning:  the --dry-run option is not yet implemented\n")
+test.run(chdir = '.', arguments = '--no-exec ' + args)
 
-test.run(chdir = '.', arguments = '--recon')
+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.fail_test(test.stderr() !=
-		"Warning:  the --recon option is not yet implemented\n")
+test.run(chdir = '.', arguments = '--just-print ' + 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.run(chdir = '.', arguments = '--dry-run ' + 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.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()
- 
+
 __revision__ = "test/option-s.py __REVISION__ __DATE__ __DEVELOPER__"
 
 import TestCmd
+import os.path
 import string
 import sys
 
                        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.run(chdir = '.', arguments = '-s')
+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.fail_test(test.stderr() !=
-		"Warning:  the -s option is not yet implemented\n")
+test.run(chdir = '.', arguments = '-s 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 = '--silent 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')))
+
+os.unlink(test.workpath('f1.out'))
+os.unlink(test.workpath('f2.out'))
+
+test.run(chdir = '.', arguments = '--quiet 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.pass_test()
  
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.