summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Script/Main.py
diff options
context:
space:
mode:
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'))