summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Script/Main.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2007-02-11 05:02:05 (GMT)
committerSteven Knight <knight@baldmt.com>2007-02-11 05:02:05 (GMT)
commitd2e8806a0e2a65208f6097f106c61ffc58b35701 (patch)
tree107c065697f6b6bb61356d82f4876df7f0eb378c /src/engine/SCons/Script/Main.py
parent5e36dc2af323114c1358bc669546cd34694932c3 (diff)
downloadSCons-d2e8806a0e2a65208f6097f106c61ffc58b35701.zip
SCons-d2e8806a0e2a65208f6097f106c61ffc58b35701.tar.gz
SCons-d2e8806a0e2a65208f6097f106c61ffc58b35701.tar.bz2
Merged revisions 1784-1824 via svnmerge from
http://scons.tigris.org/svn/scons/branches/core ........ r1786 | stevenknight | 2007-01-25 15:29:15 -0600 (Thu, 25 Jan 2007) | 1 line 0.96.D555 - Doc string updates for TaskMaster to better describe the architecture. Get rid of some no-longer-used code. ........ r1787 | stevenknight | 2007-01-25 23:24:31 -0600 (Thu, 25 Jan 2007) | 1 line 0.96.D556 - Packaging changes to support building packages in an arbitrary directory. ........ r1788 | stevenknight | 2007-01-30 20:35:39 -0600 (Tue, 30 Jan 2007) | 1 line 0.96.D557 - Make the Scanner.Base class able to handle Scanner.Selector functionality (i.e., a dictionary to select other scanners) and prepare to deprecate Scanner.Selector and Scanner.Scanner() in the future. ........ r1789 | stevenknight | 2007-01-30 20:45:23 -0600 (Tue, 30 Jan 2007) | 1 line 0.96.D558 - Add support for a site-scons subdirectory. (Gary Oberbrunner) ........ r1790 | stevenknight | 2007-01-31 00:36:20 -0600 (Wed, 31 Jan 2007) | 1 line 0.96.D559 - Clean up various module imports and other pychecker-detected problems. ........ r1791 | stevenknight | 2007-01-31 11:51:04 -0600 (Wed, 31 Jan 2007) | 1 line 0.96.D560 - Fix detection of Java anonymous classes if a newline precedes the opening brace. (Leanid Nazdrynau) ........ r1792 | stevenknight | 2007-02-02 11:57:59 -0600 (Fri, 02 Feb 2007) | 1 line 0.96.D561 - Add a --bootstrap_src option to bootstrap.py; search the bootstrap.py directory by default. (Greg Noel) ........ r1793 | stevenknight | 2007-02-02 18:04:52 -0600 (Fri, 02 Feb 2007) | 1 line 0.96.D562 - Don't check the build/*/gentoo directories for copyright strings. ........ r1794 | stevenknight | 2007-02-02 18:12:43 -0600 (Fri, 02 Feb 2007) | 1 line 0.96.D563 - Fix pychecker clean-ups on later Python versions. ........ r1795 | stevenknight | 2007-02-02 18:38:47 -0600 (Fri, 02 Feb 2007) | 1 line 0.96.D564 - Add a NoCache() function to allow marking targets as not being suitable for propagating/ to (or retrieving from) CacheDir(). (Dave Vitek) ........ r1796 | stevenknight | 2007-02-02 20:08:33 -0600 (Fri, 02 Feb 2007) | 1 line 0.96.D565 - Add a --tree= option, to make the interface to dumping dependency graphs a little clearner, and give it a 'prune' option to avoid repeating the dependency walk for Nodes we've already visited. ........ r1797 | stevenknight | 2007-02-03 20:37:25 -0600 (Sat, 03 Feb 2007) | 1 line 0.96.D566 - Packaging fix: don't add '#' to the beginning of a build_dir name if it's already an absolute path. ........ r1798 | stevenknight | 2007-02-03 20:53:42 -0600 (Sat, 03 Feb 2007) | 1 line 0.96.D567 - Add backwards-compatibility for set() types, and restore the line that used them in the compatibility _subprocess.py module. ........ r1799 | stevenknight | 2007-02-05 10:30:28 -0600 (Mon, 05 Feb 2007) | 1 line 0.96.D568 - Capture outline and build configuration for a possible future Developer's Guide. ........ r1800 | stevenknight | 2007-02-05 11:03:37 -0600 (Mon, 05 Feb 2007) | 1 line 0.96.D569 - Exclude the new developer guide MANIFEST from Copyright string checks. ........ r1801 | stevenknight | 2007-02-05 11:16:04 -0600 (Mon, 05 Feb 2007) | 1 line 0.96.D570 - Track fix in upstream subprocess.py. (Ralf W. Grosse-Kunstleve) ........ r1802 | stevenknight | 2007-02-05 20:05:59 -0600 (Mon, 05 Feb 2007) | 1 line 0.96.D571 - Change the Windows installer to register scons.bat as an 'App Path', so the directory doesn't need to be added to %PATH%. ........ r1803 | stevenknight | 2007-02-05 21:33:01 -0600 (Mon, 05 Feb 2007) | 1 line 0.96.D572 - Prepare SConf for use with the subprocess module by refactoring the Unbuffered class. ........ r1804 | stevenknight | 2007-02-05 22:37:09 -0600 (Mon, 05 Feb 2007) | 1 line 0.96.D573 - Get rid of left-over Node.Node.{pre,post}_actions attributes. ........ r1805 | stevenknight | 2007-02-06 12:04:14 -0600 (Tue, 06 Feb 2007) | 1 line 0.96.D574 - Remove leftover print in the test/CacheDir/NoCache.py test. ........ r1806 | stevenknight | 2007-02-06 17:11:03 -0600 (Tue, 06 Feb 2007) | 1 line 0.96.D575 - Support the ability to evaluate a ${} construction variable to select the spawner function. ........ r1809 | stevenknight | 2007-02-07 00:30:10 -0600 (Wed, 07 Feb 2007) | 1 line 0.96.D576 - Documentation fixes and updates. ........ r1810 | stevenknight | 2007-02-07 15:51:20 -0600 (Wed, 07 Feb 2007) | 1 line 0.96.D577 - Don't expect a bootstrap.py runtest.py file to be generated when swig -noproxy is used. ........ r1811 | stevenknight | 2007-02-07 16:55:06 -0600 (Wed, 07 Feb 2007) | 1 line 0.96.D578 - Make --srcdir a synonym for -Y/--repository. ........ r1812 | stevenknight | 2007-02-07 23:46:22 -0600 (Wed, 07 Feb 2007) | 1 line 0.96.D579 - More doc updates: PathAccept, #include+Repository double-quote limitation. ........ r1817 | stevenknight | 2007-02-08 12:46:42 -0600 (Thu, 08 Feb 2007) | 1 line 0.96.D580 - Fix use of toolpath with BuildDir. ........ r1818 | stevenknight | 2007-02-08 12:59:23 -0600 (Thu, 08 Feb 2007) | 1 line 0.96.D581 - Enable build of the text version of the User's Guide. ........ r1819 | stevenknight | 2007-02-08 14:21:31 -0600 (Thu, 08 Feb 2007) | 1 line 0.96.D582 - Fix handling of Java inner classes with JARCHDIR. ........ r1820 | stevenknight | 2007-02-08 14:39:33 -0600 (Thu, 08 Feb 2007) | 1 line 0.96.D583 - Add linking with -lm to the dmd.py Tool smart linker. (Anonymous) ........ r1821 | stevenknight | 2007-02-08 17:26:29 -0600 (Thu, 08 Feb 2007) | 1 line 0.96.D584 - Fix ParseConfig() when *FLAGS variables have been replaced with strings. ........ r1822 | stevenknight | 2007-02-09 12:21:17 -0600 (Fri, 09 Feb 2007) | 1 line 0.96.D585 - Fix installation of file names beginning with #. (Dave Weber) ........ r1823 | stevenknight | 2007-02-09 14:14:47 -0600 (Fri, 09 Feb 2007) | 1 line 0.96.D586 - Post-review improvements to recent toolpath and MergeFlags() changes. (Gary Oberbrunner, Greg Noel) ........ r1824 | stevenknight | 2007-02-10 00:53:13 -0600 (Sat, 10 Feb 2007) | 1 line 0.96.D587 - Commonize flags initialization between the c and c++ Tools. ........
Diffstat (limited to 'src/engine/SCons/Script/Main.py')
-rw-r--r--src/engine/SCons/Script/Main.py156
1 files changed, 118 insertions, 38 deletions
diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py
index 96f1526..6a0ad81 100644
--- a/src/engine/SCons/Script/Main.py
+++ b/src/engine/SCons/Script/Main.py
@@ -36,6 +36,8 @@ it goes here.
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
import os
import os.path
import random
@@ -62,6 +64,7 @@ import SCons.Node
import SCons.Node.FS
from SCons.Optik import OptionParser, SUPPRESS_HELP, OptionValueError
import SCons.SConf
+import SCons.Script
import SCons.Sig
import SCons.Taskmaster
import SCons.Util
@@ -180,15 +183,8 @@ class BuildTask(SCons.Taskmaster.Task):
def postprocess(self):
if self.top:
t = self.targets[0]
- if print_tree:
- print
- SCons.Util.print_tree(t, get_all_children)
- if print_stree:
- print
- SCons.Util.print_tree(t, get_all_children, showtags=2)
- if print_dtree:
- print
- SCons.Util.print_tree(t, get_derived_children)
+ for tp in tree_printers:
+ tp.display(t)
if print_includes:
tree = t.render_include_tree()
if tree:
@@ -291,18 +287,37 @@ class QuestionTask(SCons.Taskmaster.Task):
def executed(self):
pass
+
+class TreePrinter:
+ def __init__(self, derived=False, prune=False, status=False):
+ self.derived = derived
+ self.prune = prune
+ self.status = status
+ def get_all_children(self, node):
+ return node.all_children()
+ def get_derived_children(self, node):
+ children = node.all_children(None)
+ return filter(lambda x: x.has_builder(), children)
+ def display(self, t):
+ if self.derived:
+ func = self.get_derived_children
+ else:
+ func = self.get_all_children
+ s = self.status and 2 or 0
+ SCons.Util.print_tree(t, func, prune=self.prune, showtags=s)
+
+
# Global variables
+tree_printers = []
+
keep_going_on_error = 0
-print_dtree = 0
print_explanations = 0
print_includes = 0
print_objects = 0
print_memoizer = 0
print_stacktrace = 0
-print_stree = 0
print_time = 0
-print_tree = 0
ignore_errors = 0
sconscript_time = 0
command_time = 0
@@ -390,12 +405,6 @@ memory_stats = MemStats()
# utility functions
-def get_all_children(node): return node.all_children()
-
-def get_derived_children(node):
- children = node.all_children(None)
- return filter(lambda x: x.has_builder(), children)
-
def _scons_syntax_error(e):
"""Handle syntax errors. Print out a message and show where the error
occurred.
@@ -538,10 +547,10 @@ def _SConstruct_exists(dirname=''):
def _set_globals(options):
global keep_going_on_error, ignore_errors
- global count_stats, print_dtree
+ global count_stats
global print_explanations, print_includes, print_memoizer
- global print_objects, print_stacktrace, print_stree
- global print_time, print_tree
+ global print_objects, print_stacktrace, print_time
+ global tree_printers
global memory_stats
keep_going_on_error = options.keep_going
@@ -555,7 +564,7 @@ def _set_globals(options):
if "count" in debug_values:
count_stats.enable(sys.stdout)
if "dtree" in debug_values:
- print_dtree = 1
+ tree_printers.append(TreePrinter(derived=True))
if "explain" in debug_values:
print_explanations = 1
if "findlibs" in debug_values:
@@ -573,11 +582,11 @@ def _set_globals(options):
if "stacktrace" in debug_values:
print_stacktrace = 1
if "stree" in debug_values:
- print_stree = 1
+ tree_printers.append(TreePrinter(status=True))
if "time" in debug_values:
print_time = 1
if "tree" in debug_values:
- print_tree = 1
+ tree_printers.append(TreePrinter())
ignore_errors = options.ignore_errors
def _create_path(plist):
@@ -589,6 +598,47 @@ def _create_path(plist):
path = path + '/' + d
return path
+def _load_site_scons_dir(topdir, site_dir_name=None):
+ """Load the site_scons dir under topdir.
+ Adds site_scons to sys.path, imports site_scons/site_init.py,
+ and adds site_scons/site_tools to default toolpath."""
+ if site_dir_name:
+ err_if_not_found = True # user specified: err if missing
+ else:
+ site_dir_name = "site_scons"
+ err_if_not_found = False
+
+ site_dir = os.path.join(topdir.path, site_dir_name)
+ if not os.path.exists(site_dir):
+ if err_if_not_found:
+ raise SCons.Errors.UserError, "site dir %s not found."%site_dir
+ return
+
+ site_init_filename = "site_init.py"
+ site_init_modname = "site_init"
+ site_tools_dirname = "site_tools"
+ sys.path = [site_dir] + sys.path
+ site_init_file = os.path.join(site_dir, site_init_filename)
+ site_tools_dir = os.path.join(site_dir, site_tools_dirname)
+ if os.path.exists(site_init_file):
+ import imp
+ try:
+ fp, pathname, description = imp.find_module(site_init_modname,
+ [site_dir])
+ try:
+ imp.load_module(site_init_modname, fp, pathname, description)
+ finally:
+ if fp:
+ fp.close()
+ except ImportError, e:
+ sys.stderr.write("Can't import site init file '%s': %s\n"%(site_init_file, e))
+ raise
+ except Exception, e:
+ sys.stderr.write("Site init file '%s' raised exception: %s\n"%(site_init_file, e))
+ raise
+ if os.path.exists(site_tools_dir):
+ SCons.Tool.DefaultToolpath.append(os.path.abspath(site_tools_dir))
+
def version_string(label, module):
fmt = "\t%s: v%s.%s, %s, by %s on %s\n"
return fmt % (label,
@@ -676,7 +726,9 @@ class OptParser(OptionParser):
"pdb", "presub", "stacktrace", "stree",
"time", "tree"]
- deprecated_debug_options = [ "nomemoizer", ]
+ deprecated_debug_options = {
+ "nomemoizer" : ' and has no effect',
+ }
def opt_debug(option, opt, value, parser, debug_options=debug_options, deprecated_debug_options=deprecated_debug_options):
if value in debug_options:
@@ -686,8 +738,9 @@ class OptParser(OptionParser):
except AttributeError:
parser.values.debug = []
parser.values.debug.append(value)
- elif value in deprecated_debug_options:
- w = "The --debug=%s option is deprecated and has no effect." % value
+ elif value in deprecated_debug_options.keys():
+ msg = deprecated_debug_options[value]
+ w = "The --debug=%s option is deprecated%s." % (value, msg)
delayed_warnings.append((SCons.Warnings.DeprecatedWarning, w))
else:
raise OptionValueError("Warning: %s is not a valid debug type" % value)
@@ -773,6 +826,10 @@ class OptParser(OptionParser):
'--recon', action="store_true", dest='noexec',
default=0, help="Don't build; just print commands.")
+ self.add_option('--no-site-dir', action="store_true",
+ dest='no_site_dir', default=0,
+ help="Don't search or use the usual site_scons dir.")
+
self.add_option('--profile', action="store",
dest="profile_file", metavar="FILE",
help="Profile SCons and put results in FILE.")
@@ -790,10 +847,36 @@ class OptParser(OptionParser):
self.add_option('-s', '--silent', '--quiet', action="store_true",
default=0, help="Don't print commands.")
+ self.add_option('--site-dir', action="store",
+ dest='site_dir', metavar="DIR",
+ help="Use DIR instead of the usual site_scons dir.")
+
self.add_option('--taskmastertrace', action="store",
dest="taskmastertrace_file", metavar="FILE",
help="Trace Node evaluation to FILE.")
+ tree_options = ["all", "derived", "prune", "status"]
+
+ def opt_tree(option, opt, value, parser, tree_options=tree_options):
+ tp = TreePrinter()
+ for o in string.split(value, ','):
+ if o == 'all':
+ tp.derived = False
+ elif o == 'derived':
+ tp.derived = True
+ elif o == 'prune':
+ tp.prune = True
+ elif o == 'status':
+ tp.status = True
+ else:
+ raise OptionValueError("Warning: %s is not a valid --tree option" % o)
+ tree_printers.append(tp)
+
+ self.add_option('--tree', action="callback", type="string",
+ callback=opt_tree, nargs=1, metavar="OPTIONS",
+ help="Print a dependency tree in various formats: "
+ "%s." % string.join(tree_options, ", "))
+
self.add_option('-u', '--up', '--search-up', action="store_const",
dest="climb_up", default=0, const=1,
help="Search up directory tree for SConstruct, "
@@ -811,7 +894,8 @@ class OptParser(OptionParser):
metavar="WARNING-SPEC",
help="Enable or disable warnings.")
- self.add_option('-Y', '--repository', nargs=1, action="append",
+ self.add_option('-Y', '--repository', '--srcdir',
+ nargs=1, action="append",
help="Search REPOSITORY for source and target files.")
self.add_option('-e', '--environment-overrides', action="callback",
@@ -1076,6 +1160,11 @@ def _main(args, parser):
if options.cache_show:
fs.cache_show = 1
+ if options.site_dir:
+ _load_site_scons_dir(d, options.site_dir)
+ elif not options.no_site_dir:
+ _load_site_scons_dir(d)
+
if options.include_dir:
sys.path = options.include_dir + sys.path
@@ -1092,16 +1181,7 @@ def _main(args, parser):
SCons.Script._Add_Targets(targets)
SCons.Script._Add_Arguments(xmit_args)
- class Unbuffered:
- def __init__(self, file):
- self.file = file
- def write(self, arg):
- self.file.write(arg)
- self.file.flush()
- def __getattr__(self, attr):
- return getattr(self.file, attr)
-
- sys.stdout = Unbuffered(sys.stdout)
+ sys.stdout = SCons.Util.Unbuffered(sys.stdout)
memory_stats.append('before reading SConscript files:')
count_stats.append(('pre-', 'read'))