diff options
author | Steven Knight <knight@baldmt.com> | 2005-05-14 14:32:44 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-05-14 14:32:44 (GMT) |
commit | 29aa03f7d41976f71cbe16090abf42b1364bb0c8 (patch) | |
tree | 479378732781cf8c06a2fbc935c149b4313eee6d /src/engine/SCons/Node | |
parent | f82f4ce830289473187299db9962f819ed74c877 (diff) | |
download | SCons-29aa03f7d41976f71cbe16090abf42b1364bb0c8.zip SCons-29aa03f7d41976f71cbe16090abf42b1364bb0c8.tar.gz SCons-29aa03f7d41976f71cbe16090abf42b1364bb0c8.tar.bz2 |
Move pre- and post-actions lists from Node to Executor so expansions of ${TARGETS[1:]} work, and the actions aren't executed multiple times.
Diffstat (limited to 'src/engine/SCons/Node')
-rw-r--r-- | src/engine/SCons/Node/FS.py | 7 | ||||
-rw-r--r-- | src/engine/SCons/Node/FSTests.py | 16 | ||||
-rw-r--r-- | src/engine/SCons/Node/NodeTests.py | 49 | ||||
-rw-r--r-- | src/engine/SCons/Node/__init__.py | 20 |
4 files changed, 23 insertions, 69 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index f2234f7..5ae14fc 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -1058,11 +1058,16 @@ class Dir(Base): self.entries['.'] = self self.entries['..'] = self.dir self.cwd = self - self.builder = get_MkdirBuilder() self.searched = 0 self._sconsign = None self.build_dirs = [] + # Don't just reset the executor, replace its action list, + # because it might have some pre-or post-actions that need to + # be preserved. + self.builder = get_MkdirBuilder() + self.get_executor().set_action_list(self.builder.action) + def disambiguate(self): return self diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 8626185..6978a03 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -307,6 +307,7 @@ class BuildDirTestCase(unittest.TestCase): try: dir_made = [] d9.builder = Builder(fs.Dir, action=MkdirAction(dir_made)) + d9.reset_executor() f9.exists() expect = os.path.join('build', 'var2', 'new_dir') assert dir_made[0].path == expect, dir_made[0].path @@ -895,6 +896,7 @@ class FSTestCase(_tempdirTestCase): assert not built_it d1.add_source([SCons.Node.Node()]) # XXX FAKE SUBCLASS ATTRIBUTE d1.builder_set(Builder(fs.File)) + d1.reset_executor() d1.env_set(Environment()) d1.build() assert built_it @@ -903,6 +905,7 @@ class FSTestCase(_tempdirTestCase): assert not built_it f1.add_source([SCons.Node.Node()]) # XXX FAKE SUBCLASS ATTRIBUTE f1.builder_set(Builder(fs.File)) + f1.reset_executor() f1.env_set(Environment()) f1.build() assert built_it @@ -1343,6 +1346,18 @@ class FSTestCase(_tempdirTestCase): class DirTestCase(_tempdirTestCase): + def test__morph(self): + """Test handling of actions when morphing an Entry into a Dir""" + test = self.test + e = self.fs.Entry('eee') + x = e.get_executor() + x.add_pre_action('pre') + x.add_post_action('post') + e.must_be_a_Dir() + a = x.get_action_list() + assert a[0] == 'pre', a + assert a[2] == 'post', a + def test_entry_exists_on_disk(self): """Test the Dir.entry_exists_on_disk() method """ @@ -2179,6 +2194,7 @@ class prepareTestCase(unittest.TestCase): dir_made = [] new_dir = fs.Dir("new_dir") new_dir.builder = Builder(fs.Dir, action=MkdirAction(dir_made)) + new_dir.reset_executor() xyz = fs.File(os.path.join("new_dir", "xyz")) xyz.set_state(SCons.Node.up_to_date) diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index 67ac05f..70b9672 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -106,24 +106,6 @@ class MyListAction(MyActionBase): def __call__(self, target, source, env, errfunc): for A in self.list: A(target, source, env, errfunc) - -class MyNonGlobalAction(MyActionBase): - def __init__(self): - self.order = 0 - self.built_it = None - self.built_target = None - self.built_source = None - - def __call__(self, target, source, env, errfunc): - # Okay, so not ENTIRELY non-global... - global built_order - self.built_it = 1 - self.built_target = target - self.built_source = source - self.built_args = env - built_order = built_order + 1 - self.order = built_order - return 0 class Environment: def __init__(self, **kw): @@ -310,37 +292,6 @@ class NodeTestCase(unittest.TestCase): assert built_args["on"] == 3, built_args assert built_args["off"] == 4, built_args - built_it = None - built_order = 0 - node = MyNode("xxx") - node.builder_set(Builder()) - node.env_set(Environment()) - node.sources = ["yyy", "zzz"] - pre1 = MyNonGlobalAction() - pre2 = MyNonGlobalAction() - post1 = MyNonGlobalAction() - post2 = MyNonGlobalAction() - node.add_pre_action(pre1) - node.add_pre_action(pre2) - node.add_post_action(post1) - node.add_post_action(post2) - node.build() - assert built_it - assert pre1.built_it - assert pre2.built_it - assert post1.built_it - assert post2.built_it - assert pre1.order == 1, pre1.order - assert pre2.order == 2, pre1.order - # The action of the builder itself is order 3... - assert post1.order == 4, pre1.order - assert post2.order == 5, pre1.order - - for act in [ pre1, pre2, post1, post2 ]: - assert type(act.built_target[0]) == type(MyNode("bar")), type(act.built_target[0]) - assert str(act.built_target[0]) == "xxx", str(act.built_target[0]) - assert act.built_source == ["yyy", "zzz"], act.built_source - def test_get_build_scanner_path(self): """Test the get_build_scanner_path() method""" n = SCons.Node.Node() diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index f9390ea..4a1faaa 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -179,12 +179,8 @@ class Node: try: act = self.builder.action except AttributeError: - executor = SCons.Executor.Null() + executor = SCons.Executor.Null(targets=[self]) else: - if self.pre_actions: - act = self.pre_actions + act - if self.post_actions: - act = act + self.post_actions executor = SCons.Executor.Executor(act, self.env or self.builder.env, [self.builder.overrides], @@ -833,20 +829,6 @@ class Node: the command interpreter literally.""" return 1 - def add_pre_action(self, act): - """Adds an Action performed on this Node only before - building it.""" - self.pre_actions.append(act) - # executor must be recomputed to include new pre-actions - self.reset_executor() - - def add_post_action(self, act): - """Adds and Action performed on this Node only after - building it.""" - self.post_actions.append(act) - # executor must be recomputed to include new pre-actions - self.reset_executor() - def render_include_tree(self): """ Return a text representation, suitable for displaying to the |