From 7d89522233802f83ffa728bc0b55785faf580d32 Mon Sep 17 00:00:00 2001 From: Dirk Baechle Date: Wed, 4 Feb 2015 22:07:45 +0100 Subject: - a few simple refactorings and optimizations --- src/engine/SCons/Action.py | 34 ++++++++++++++++------------------ src/engine/SCons/ActionTests.py | 2 -- src/engine/SCons/Builder.py | 4 +--- src/engine/SCons/Executor.py | 19 ++++++++++--------- src/engine/SCons/Node/FS.py | 12 +----------- 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 1c746be..eecea11 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -99,8 +99,6 @@ way for wrapping up the functions. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import SCons.compat - import dis import os # compat layer imports "cPickle" for us if it's available. @@ -112,7 +110,6 @@ import subprocess import SCons.Debug from SCons.Debug import logInstanceCreation import SCons.Errors -import SCons.Executor import SCons.Util import SCons.Subst @@ -357,21 +354,6 @@ def _do_create_action(act, kw): if isinstance(act, ActionBase): return act - if is_List(act): - return CommandAction(act, **kw) - - if callable(act): - try: - gen = kw['generator'] - del kw['generator'] - except KeyError: - gen = 0 - if gen: - action_type = CommandGeneratorAction - else: - action_type = FunctionAction - return action_type(act, kw) - if is_String(act): var=SCons.Util.get_environment_var(act) if var: @@ -388,6 +370,22 @@ def _do_create_action(act, kw): # The list of string commands may include a LazyAction, so we # reprocess them via _do_create_list_action. return _do_create_list_action(commands, kw) + + if is_List(act): + return CommandAction(act, **kw) + + if callable(act): + try: + gen = kw['generator'] + del kw['generator'] + except KeyError: + gen = 0 + if gen: + action_type = CommandGeneratorAction + else: + action_type = FunctionAction + return action_type(act, kw) + # Catch a common error case with a nice message: if isinstance(act, int) or isinstance(act, float): raise TypeError("Don't know how to create an Action from a number (%s)"%act) diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index b46347d..e069d51 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -23,8 +23,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import SCons.compat - # Define a null function and a null class for use as builder actions. # Where these are defined in the file seems to affect their byte-code # contents, so try to minimize changes by defining them here, before we diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index ed7650a..c82f6ac 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -107,8 +107,6 @@ from SCons.Debug import logInstanceCreation from SCons.Errors import InternalError, UserError import SCons.Executor import SCons.Memoize -import SCons.Node -import SCons.Node.FS import SCons.Util import SCons.Warnings @@ -862,7 +860,7 @@ class CompositeBuilder(SCons.Util.Proxy): self.set_src_suffix(self.cmdgen.src_suffixes()) def is_a_Builder(obj): - """"Returns True iff the specified obj is one of our Builder classes. + """"Returns True if the specified obj is one of our Builder classes. The test is complicated a bit by the fact that CompositeBuilder is a proxy, not a subclass of BuilderBase. diff --git a/src/engine/SCons/Executor.py b/src/engine/SCons/Executor.py index 051d275..388f8ac 100644 --- a/src/engine/SCons/Executor.py +++ b/src/engine/SCons/Executor.py @@ -554,19 +554,20 @@ def AddBatchExecutor(key, executor): nullenv = None +import SCons.Util +class NullEnvironment(SCons.Util.Null): + import SCons.CacheDir + _CacheDir_path = None + _CacheDir = SCons.CacheDir.CacheDir(None) + def get_CacheDir(self): + return self._CacheDir + + def get_NullEnvironment(): """Use singleton pattern for Null Environments.""" global nullenv - import SCons.Util - class NullEnvironment(SCons.Util.Null): - import SCons.CacheDir - _CacheDir_path = None - _CacheDir = SCons.CacheDir.CacheDir(None) - def get_CacheDir(self): - return self._CacheDir - - if not nullenv: + if nullenv is None: nullenv = NullEnvironment() return nullenv diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index e73dd92..4db1cb3 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -2230,17 +2230,7 @@ class RootDir(Dir): raise SCons.Errors.UserError(msg) # There is no Node for this path name, and we're allowed # to create it. - # (note: would like to use p.rsplit('/',1) here but - # that's not in python 2.3) - # e.g.: dir_name, file_name = p.rsplit('/',1) - last_slash = p.rindex('/') - if (last_slash >= 0): - dir_name = p[:last_slash] - file_name = p[last_slash+1:] - else: - dir_name = p # shouldn't happen, just in case - file_name = '' - + dir_name, file_name = p.rsplit('/',1) dir_node = self._lookup_abs(dir_name, Dir) result = klass(file_name, dir_node, self.fs) -- cgit v0.12