diff options
author | Steven Knight <knight@baldmt.com> | 2005-03-06 18:00:40 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-03-06 18:00:40 (GMT) |
commit | 0793d1606ebcc056d6f945af189c2c7f7b88ef5f (patch) | |
tree | e8d52a1a0b095da503f7f3366f0f1ca662016e17 /src | |
parent | fe741836cacf824a8e81253c9058970ccff56400 (diff) | |
download | SCons-0793d1606ebcc056d6f945af189c2c7f7b88ef5f.zip SCons-0793d1606ebcc056d6f945af189c2c7f7b88ef5f.tar.gz SCons-0793d1606ebcc056d6f945af189c2c7f7b88ef5f.tar.bz2 |
Checkpoint refactorings to remove CommandGenerator and ToolSpec classes.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SCons/Action.py | 27 | ||||
-rw-r--r-- | src/engine/SCons/ActionTests.py | 14 | ||||
-rw-r--r-- | src/engine/SCons/Builder.py | 15 | ||||
-rw-r--r-- | src/engine/SCons/Tool/__init__.py | 84 | ||||
-rw-r--r-- | src/engine/SCons/Tool/mingw.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/Tool/mwld.py | 2 | ||||
-rw-r--r-- | src/test_setup.py | 8 |
7 files changed, 73 insertions, 79 deletions
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 077ddfb..3b0230c 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -143,20 +143,6 @@ def _actionAppend(act1, act2): else: return ListAction([ a1, a2 ]) -class CommandGenerator: - """ - Wraps a command generator function so the Action() factory - function can tell a generator function from a function action. - """ - def __init__(self, generator): - self.generator = generator - - def __add__(self, other): - return _actionAppend(self, other) - - def __radd__(self, other): - return _actionAppend(other, self) - def _do_create_action(act, *args, **kw): """This is the actual "implementation" for the Action factory method, below. This handles the @@ -172,10 +158,17 @@ def _do_create_action(act, *args, **kw): return act if SCons.Util.is_List(act): return apply(CommandAction, (act,)+args, kw) - if isinstance(act, CommandGenerator): - return apply(CommandGeneratorAction, (act.generator,)+args, kw) if callable(act): - return apply(FunctionAction, (act,)+args, kw) + try: + gen = kw['generator'] + del kw['generator'] + except KeyError: + gen = 0 + if gen: + action_type = CommandGeneratorAction + else: + action_type = FunctionAction + return apply(action_type, (act,)+args, kw) if SCons.Util.is_String(act): var=SCons.Util.get_environment_var(act) if var: diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 36117a4..3790c8c 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -281,13 +281,11 @@ class ActionTestCase(unittest.TestCase): pass def bar(): pass - cg = SCons.Action.CommandGenerator(foo) - - a1 = SCons.Action.Action(cg) + a1 = SCons.Action.Action(foo, generator=1) assert isinstance(a1, SCons.Action.CommandGeneratorAction), a1 assert a1.generator is foo, a1.generator - a2 = SCons.Action.Action(cg, strfunction=bar) + a2 = SCons.Action.Action(foo, strfunction=bar, generator=1) assert isinstance(a2, SCons.Action.CommandGeneratorAction), a2 assert a2.generator is foo, a2.generator @@ -578,7 +576,7 @@ class _ActionActionTestCase(unittest.TestCase): def gen(target, source, env, for_signature): return 'generat' + env.get('GEN', 'or') - a = SCons.Action.Action(SCons.Action.CommandGenerator(gen)) + a = SCons.Action.Action(gen, generator=1) s = a.presub_lines(env) assert s == ["generator"], s s = a.presub_lines(Environment(GEN = 'ed')) @@ -597,7 +595,7 @@ class _ActionActionTestCase(unittest.TestCase): # containing all the Actions. def bar(): return None - baz = SCons.Action.CommandGenerator(bar) + baz = SCons.Action.Action(bar, generator=1) act1 = SCons.Action.Action('foo bar') act2 = SCons.Action.Action([ 'foo', bar ]) @@ -1419,7 +1417,7 @@ class ListActionTestCase(unittest.TestCase): pass def g(target,source,env,for_signature): return 'generated %s %s' % (target[0], source[0]) - g = SCons.Action.CommandGenerator(g) + g = SCons.Action.Action(g, generator=1) a = SCons.Action.ListAction([f, g, "XXX", f]) s = a.genstring(['foo.x'], ['bar.y'], Environment()) assert s == "f(target, source, env)\ngenerated foo.x bar.y\nXXX\nf(target, source, env)", s @@ -1464,7 +1462,7 @@ class ListActionTestCase(unittest.TestCase): s.foo=1 return "y" a = SCons.Action.ListAction(["x", - SCons.Action.CommandGenerator(gen), + SCons.Action.Action(gen, generator=1), "z"]) c = a.get_contents(target=[], source=[], env=Environment(s = self)) assert self.foo==1, self.foo diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 8d99a32..a20757e 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -243,12 +243,15 @@ def Builder(**kw): if kw.has_key('generator'): if kw.has_key('action'): raise UserError, "You must not specify both an action and a generator." - kw['action'] = SCons.Action.CommandGenerator(kw['generator']) + kw['action'] = SCons.Action.CommandGeneratorAction(kw['generator']) del kw['generator'] - elif kw.has_key('action') and SCons.Util.is_Dict(kw['action']): - composite = DictCmdGenerator(kw['action']) - kw['action'] = SCons.Action.CommandGenerator(composite) - kw['src_suffix'] = composite.src_suffixes() + elif kw.has_key('action'): + if SCons.Util.is_Dict(kw['action']): + composite = DictCmdGenerator(kw['action']) + kw['action'] = SCons.Action.CommandGeneratorAction(composite) + kw['src_suffix'] = composite.src_suffixes() + else: + kw['action'] = SCons.Action.Action(kw['action']) if kw.has_key('emitter'): emitter = kw['emitter'] @@ -397,7 +400,7 @@ class BuilderBase: is_explicit = 1, **overrides): if __debug__: logInstanceCreation(self, 'Builder.BuilderBase') - self.action = SCons.Action.Action(action) + self.action = action self.multi = multi if SCons.Util.is_Dict(prefix): prefix = CallableSelector(prefix) diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index d9b1c30..b4e8ad5 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -68,12 +68,52 @@ for suffix in CSuffixes: for suffix in DSuffixes: SourceFileScanner.add_scanner(suffix, DScanner) -class ToolSpec: - def __init__(self, name, **kw): +class Tool: + def __init__(self, name, toolpath=[], **kw): self.name = name + self.toolpath = toolpath # remember these so we can merge them into the call self.init_kw = kw + module = self._tool_module() + self.generate = module.generate + self.exists = module.exists + + def _tool_module(self): + oldpythonpath = sys.path + sys.path = self.toolpath + sys.path + + try: + try: + file, path, desc = imp.find_module(self.name, self.toolpath) + try: + return imp.load_module(self.name, file, path, desc) + finally: + if file: + file.close() + except ImportError, e: + pass + finally: + sys.path = oldpythonpath + + full_name = 'SCons.Tool.' + self.name + try: + return sys.modules[full_name] + except KeyError: + try: + smpath = sys.modules['SCons.Tool'].__path__ + file, path, desc = imp.find_module(self.name, smpath) + try: + module = imp.load_module(full_name, file, path, desc) + setattr(SCons.Tool, self.name, module) + return module + finally: + if file: + file.close() + except ImportError, e: + m = "No tool named '%s': %s" % (self.name, e) + raise SCons.Errors.UserError, m + def __call__(self, env, *args, **kw): if self.init_kw is not None: # Merge call kws into init kws; @@ -89,46 +129,6 @@ class ToolSpec: def __str__(self): return self.name - -def Tool(name, toolpath=[], **kw): - "Select a canned Tool specification, optionally searching in toolpath." - - oldpythonpath = sys.path - sys.path = toolpath + sys.path - - try: - try: - file, path, desc = imp.find_module(name, toolpath) - try: - module = imp.load_module(name, file, path, desc) - spec = apply(ToolSpec, (name,), kw) - spec.generate = module.generate - spec.exists = module.exists - return spec - finally: - if file: - file.close() - except ImportError, e: - pass - finally: - sys.path = oldpythonpath - - - full_name = 'SCons.Tool.' + name - if not sys.modules.has_key(full_name): - try: - file, path, desc = imp.find_module(name, - sys.modules['SCons.Tool'].__path__) - mod = imp.load_module(full_name, file, path, desc) - setattr(SCons.Tool, name, mod) - except ImportError, e: - raise SCons.Errors.UserError, "No tool named '%s': %s" % (name, e) - if file: - file.close() - spec = apply(ToolSpec, (name,), kw) - spec.generate = sys.modules[full_name].generate - spec.exists = sys.modules[full_name].exists - return spec def createProgBuilder(env): """This is a utility function that creates the Program diff --git a/src/engine/SCons/Tool/mingw.py b/src/engine/SCons/Tool/mingw.py index 78cffde..1fd1530 100644 --- a/src/engine/SCons/Tool/mingw.py +++ b/src/engine/SCons/Tool/mingw.py @@ -94,7 +94,7 @@ def shlib_emitter(target, source, env): return (target, source) -shlib_action = SCons.Action.CommandGenerator(shlib_generator) +shlib_action = SCons.Action.Action(shlib_generator, generator=1) res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') diff --git a/src/engine/SCons/Tool/mwld.py b/src/engine/SCons/Tool/mwld.py index 5e90a9c..e2b1827 100644 --- a/src/engine/SCons/Tool/mwld.py +++ b/src/engine/SCons/Tool/mwld.py @@ -98,4 +98,4 @@ def shlib_emitter(target, source, env): return target, source -shlib_action = SCons.Action.CommandGenerator(shlib_generator) +shlib_action = SCons.Action.Action(shlib_generator, generator=1) diff --git a/src/test_setup.py b/src/test_setup.py index ab5b651..73b6588 100644 --- a/src/test_setup.py +++ b/src/test_setup.py @@ -107,6 +107,10 @@ try: except KeyError: cwd = os.getcwd() +test = MyTestSCons() + +test.subdir(test.root) + tar_gz = os.path.join(cwd, 'build', 'dist', '%s.tar.gz' % scons_version) if not os.path.isfile(tar_gz): @@ -114,10 +118,6 @@ if not os.path.isfile(tar_gz): print "Cannot test package installation." test.no_result(1) -test = MyTestSCons() - -test.subdir(test.root) - # Unpack the .tar.gz file. This should create the scons_version/ # subdirectory from which we execute the setup.py script therein. os.system("gunzip -c %s | tar xf -" % tar_gz) |