summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2005-06-02 18:43:40 (GMT)
committerSteven Knight <knight@baldmt.com>2005-06-02 18:43:40 (GMT)
commit08db2bcf45cc262fb87acac1b008e74a86418349 (patch)
treef611b619ffaa98316f08b217dd044507d60e9b2c /src
parent8281e43014e93d8a8e674902410ba42e38355405 (diff)
downloadSCons-08db2bcf45cc262fb87acac1b008e74a86418349.zip
SCons-08db2bcf45cc262fb87acac1b008e74a86418349.tar.gz
SCons-08db2bcf45cc262fb87acac1b008e74a86418349.tar.bz2
More efficient Builder.src_suffixes() calculation and matching.
Diffstat (limited to 'src')
-rw-r--r--src/CHANGES.txt2
-rw-r--r--src/engine/SCons/Builder.py41
-rw-r--r--src/engine/SCons/BuilderTests.py55
3 files changed, 71 insertions, 27 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 6765364..8abf25b 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -289,6 +289,8 @@ RELEASE 0.97 - XXX
looks at the counts and profiles of the underlying function calls,
not the Memoizer wrappers.
+ - Print various --debug= stats even if we exit early (e.g. using -h).
+
From Wayne Lee:
- Avoid "maximum recursion limit" errors when removing $(-$) pairs
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py
index 57fbe3e..9083985 100644
--- a/src/engine/SCons/Builder.py
+++ b/src/engine/SCons/Builder.py
@@ -383,7 +383,6 @@ class BuilderBase:
self.prefix = prefix
if SCons.Util.is_Dict(suffix):
suffix = CallableSelector(suffix)
- self.suffix = suffix
self.env = env
self.single_source = single_source
if overrides.has_key('overrides'):
@@ -399,6 +398,7 @@ class BuilderBase:
del overrides['scanner']
self.overrides = overrides
+ self.set_suffix(suffix)
self.set_src_suffix(src_suffix)
self.target_factory = target_factory
@@ -614,24 +614,29 @@ class BuilderBase:
prefix = prefix(env, sources)
return env.subst(prefix)
+ def set_suffix(self, suffix):
+ if not callable(suffix):
+ suffix = self.adjust_suffix(suffix)
+ self.suffix = suffix
+
def get_suffix(self, env, sources=[]):
suffix = self.suffix
if callable(suffix):
suffix = suffix(env, sources)
- else:
- suffix = self.adjust_suffix(suffix)
return env.subst(suffix)
def src_suffixes(self, env):
- return map(lambda x, s=self, e=env: e.subst(s.adjust_suffix(x)),
- self.src_suffix)
+ "__cacheable__"
+ return map(lambda x, s=self, e=env: e.subst(x), self.src_suffix)
def set_src_suffix(self, src_suffix):
if not src_suffix:
src_suffix = []
elif not SCons.Util.is_List(src_suffix):
src_suffix = [ src_suffix ]
- self.src_suffix = src_suffix
+ adjust = lambda suf, s=self: \
+ callable(suf) and suf or s.adjust_suffix(suf)
+ self.src_suffix = map(adjust, src_suffix)
def get_src_suffix(self, env):
"""Get the first src_suffix in the list of src_suffixes."""
@@ -745,19 +750,23 @@ class MultiStepBuilder(BuilderBase):
src_suffixes = self.src_suffixes(env)
- def match_src_suffix(node, src_suffixes=src_suffixes):
- # This reaches directly into the Node.name attribute (instead
- # of using an accessor function) for performance reasons.
- return filter(lambda s, n=node.name:
- n[-len(s):] == s,
- src_suffixes)
+ lengths_dict = {}
+ for l in map(len, src_suffixes):
+ lengths_dict[l] = None
+ lengths = lengths_dict.keys()
+
+ def match_src_suffix(node, src_suffixes=src_suffixes, lengths=lengths):
+ node_suffixes = map(lambda l, n=node: n.name[-l:], lengths)
+ for suf in src_suffixes:
+ if suf in node_suffixes:
+ return suf
+ return None
for snode in slist:
- name = snode.name
- match = match_src_suffix(snode)
- if match:
+ match_suffix = match_src_suffix(snode)
+ if match_suffix:
try:
- bld = sdict[match[0]]
+ bld = sdict[match_suffix]
except KeyError:
final_sources.append(snode)
else:
diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py
index 6ad5785..3c98e27 100644
--- a/src/engine/SCons/BuilderTests.py
+++ b/src/engine/SCons/BuilderTests.py
@@ -536,6 +536,22 @@ class BuilderTestCase(unittest.TestCase):
tgt = builder(my_env, target = None, source = 'f6.zzz')[0]
assert tgt.path == 'emit-f6', tgt.path
+ def test_set_suffix(self):
+ """Test the set_suffix() method"""
+ b = SCons.Builder.Builder(action='')
+ env = Environment(XSUFFIX = '.x')
+
+ s = b.get_suffix(env)
+ assert s == '', s
+
+ b.set_suffix('.foo')
+ s = b.get_suffix(env)
+ assert s == '.foo', s
+
+ b.set_suffix('$XSUFFIX')
+ s = b.get_suffix(env)
+ assert s == '.x', s
+
def test_src_suffix(self):
"""Test Builder creation with a specified source file suffix
@@ -1079,8 +1095,8 @@ class BuilderTestCase(unittest.TestCase):
forms of component specifications."""
builder = SCons.Builder.Builder()
-
env = Environment(BUILDERS={'Bld':builder})
+
r = builder.get_name(env)
assert r == 'Bld', r
r = builder.get_prefix(env)
@@ -1095,23 +1111,34 @@ class BuilderTestCase(unittest.TestCase):
assert r == ['foo'], r
# src_suffix can be a single string or a list of strings
+ # src_suffixes() caches its return value, so we use a new
+ # Builder each time we do any of these tests
- builder.set_src_suffix('.foo')
- r = builder.get_src_suffix(env)
+ bld = SCons.Builder.Builder()
+ env = Environment(BUILDERS={'Bld':bld})
+
+ bld.set_src_suffix('.foo')
+ r = bld.get_src_suffix(env)
assert r == '.foo', r
- r = builder.src_suffixes(env)
+ r = bld.src_suffixes(env)
assert r == ['.foo'], r
- builder.set_src_suffix(['.foo', '.bar'])
- r = builder.get_src_suffix(env)
+ bld = SCons.Builder.Builder()
+ env = Environment(BUILDERS={'Bld':bld})
+
+ bld.set_src_suffix(['.foo', '.bar'])
+ r = bld.get_src_suffix(env)
assert r == '.foo', r
- r = builder.src_suffixes(env)
+ r = bld.src_suffixes(env)
assert r == ['.foo', '.bar'], r
- builder.set_src_suffix(['.bar', '.foo'])
- r = builder.get_src_suffix(env)
+ bld = SCons.Builder.Builder()
+ env = Environment(BUILDERS={'Bld':bld})
+
+ bld.set_src_suffix(['.bar', '.foo'])
+ r = bld.get_src_suffix(env)
assert r == '.bar', r
- r = builder.src_suffixes(env)
+ r = bld.src_suffixes(env)
assert r == ['.bar', '.foo'], r
# adjust_suffix normalizes the suffix, adding a `.' if needed
@@ -1184,8 +1211,8 @@ class BuilderTestCase(unittest.TestCase):
assert r == '.D', r
builder = SCons.Builder.Builder(prefix='A_', suffix={}, action={})
-
env = Environment(BUILDERS={'Bld':builder})
+
r = builder.get_name(env)
assert r == 'Bld', r
r = builder.get_prefix(env)
@@ -1201,7 +1228,10 @@ class BuilderTestCase(unittest.TestCase):
# whose keys are the source suffix. The add_action()
# specifies a new source suffix/action binding.
+ builder = SCons.Builder.Builder(prefix='A_', suffix={}, action={})
+ env = Environment(BUILDERS={'Bld':builder})
builder.add_action('.src_sfx1', 'FOO')
+
r = builder.get_name(env)
assert r == 'Bld', r
r = builder.get_prefix(env)
@@ -1215,6 +1245,9 @@ class BuilderTestCase(unittest.TestCase):
r = builder.src_suffixes(env)
assert r == ['.src_sfx1'], r
+ builder = SCons.Builder.Builder(prefix='A_', suffix={}, action={})
+ env = Environment(BUILDERS={'Bld':builder})
+ builder.add_action('.src_sfx1', 'FOO')
builder.add_action('.src_sfx2', 'BAR')
r = builder.get_name(env)