diff options
Diffstat (limited to 'src/engine/SCons/Environment.py')
-rw-r--r-- | src/engine/SCons/Environment.py | 123 |
1 files changed, 51 insertions, 72 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index bffe0ef..8a7721e 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -6,7 +6,7 @@ construction information to the build engine. Keyword arguments supplied when the construction Environment is created are construction variables used to initialize the -Environment +Environment """ # @@ -72,27 +72,6 @@ CalculatorArgs = {} # which seem to mess up its ability to reference SCons directly. UserError = SCons.Errors.UserError -def installFunc(target, source, env): - """Install a source file into a target using the function specified - as the INSTALL construction variable.""" - try: - install = env['INSTALL'] - except KeyError: - raise SCons.Errors.UserError('Missing INSTALL construction variable.') - return install(target[0].path, source[0].path, env) - -def installString(target, source, env): - s = env.get('INSTALLSTR', '') - if callable(s): - return s(target[0].path, source[0].path, env) - else: - return env.subst_target_source(s, 0, target, source) - -installAction = SCons.Action.Action(installFunc, installString) - -InstallBuilder = SCons.Builder.Builder(action=installAction, - name='InstallBuilder') - def alias_builder(env, target, source): pass @@ -370,7 +349,7 @@ class SubstitutionEnvironment: nodes.append(v) else: nodes.append(v) - + return nodes def gvars(self): @@ -717,6 +696,17 @@ class SubstitutionEnvironment: self[key] = t return self +# Used by the FindSourceFiles() method, below. +# Stuck here for support of pre-2.2 Python versions. +def build_source(ss, result): + for s in ss: + if isinstance(s, SCons.Node.FS.Dir): + build_source(s.all_children(), result) + elif s.has_builder(): + build_source(s.sources, result) + elif isinstance(s.disambiguate(), SCons.Node.FS.File): + result.append(s) + class Base(SubstitutionEnvironment): """Base class for "real" construction Environments. These are the primary objects used to communicate dependency and construction @@ -895,7 +885,7 @@ class Base(SubstitutionEnvironment): self._memo['_gsm'] = result return result - + def get_scanner(self, skey): """Find the appropriate scanner given a key (usually a file suffix). """ @@ -1006,7 +996,7 @@ class Base(SubstitutionEnvironment): orig = self._dict[envname][name] nv = SCons.Util.AppendPath(orig, newpath, sep) - + if not self._dict.has_key(envname): self._dict[envname] = {} @@ -1122,7 +1112,7 @@ class Base(SubstitutionEnvironment): for path in paths: dir,name = os.path.split(str(path)) - if name[:len(prefix)] == prefix and name[-len(suffix):] == suffix: + if name[:len(prefix)] == prefix and name[-len(suffix):] == suffix: return path def ParseConfig(self, command, function=None, unique=1): @@ -1261,7 +1251,7 @@ class Base(SubstitutionEnvironment): orig = self._dict[envname][name] nv = SCons.Util.PrependPath(orig, newpath, sep) - + if not self._dict.has_key(envname): self._dict[envname] = {} @@ -1593,50 +1583,6 @@ class Base(SubstitutionEnvironment): t.add_ignore(dlist) return tlist - def Install(self, dir, source): - """Install specified files in the given directory.""" - try: - dnodes = self.arg2nodes(dir, self.fs.Dir) - except TypeError: - fmt = "Target `%s' of Install() is a file, but should be a directory. Perhaps you have the Install() arguments backwards?" - raise SCons.Errors.UserError, fmt % str(dir) - try: - sources = self.arg2nodes(source, self.fs.Entry) - except TypeError: - if SCons.Util.is_List(source): - s = repr(map(str, source)) - else: - s = str(source) - fmt = "Source `%s' of Install() is neither a file nor a directory. Install() source must be one or more files or directories" - raise SCons.Errors.UserError, fmt % s - tgt = [] - for dnode in dnodes: - for src in sources: - # Prepend './' so the lookup doesn't interpret an initial - # '#' on the file name portion as meaning the Node should - # be relative to the top-level SConstruct directory. - target = dnode.Entry('.'+os.sep+src.name) - tgt.extend(InstallBuilder(self, target, src)) - return tgt - - def InstallAs(self, target, source): - """Install sources as targets.""" - sources = self.arg2nodes(source, self.fs.Entry) - targets = self.arg2nodes(target, self.fs.Entry) - if len(sources) != len(targets): - if not SCons.Util.is_List(target): - target = [target] - if not SCons.Util.is_List(source): - source = [source] - t = repr(map(str, target)) - s = repr(map(str, source)) - fmt = "Target (%s) and source (%s) lists of InstallAs() must be the same length." - raise SCons.Errors.UserError, fmt % (t, s) - result = [] - for src, tgt in map(lambda x, y: (x, y), sources, targets): - result.extend(InstallBuilder(self, tgt, src)) - return result - def Literal(self, string): return SCons.Subst.Literal(string) @@ -1681,7 +1627,7 @@ class Base(SubstitutionEnvironment): SCons.SConsign.File(name, dbm_module) def SideEffect(self, side_effect, target): - """Tell scons that side_effects are built as side + """Tell scons that side_effects are built as side effects of building targets.""" side_effects = self.arg2nodes(side_effect, self.fs.Entry) targets = self.arg2nodes(target, self.fs.Entry) @@ -1753,6 +1699,39 @@ class Base(SubstitutionEnvironment): """ return SCons.Node.Python.Value(value, built_value) + def FindSourceFiles(self, node='.'): + """ returns a list of all source files. + """ + node = self.arg2nodes(node, self.fs.Entry)[0] + + sources = [] + # Uncomment this and get rid of the global definition when we + # drop support for pre-2.2 Python versions. + #def build_source(ss, result): + # for s in ss: + # if isinstance(s, SCons.Node.FS.Dir): + # build_source(s.all_children(), result) + # elif s.has_builder(): + # build_source(s.sources, result) + # elif isinstance(s.disambiguate(), SCons.Node.FS.File): + # result.append(s) + build_source(node.all_children(), sources) + + # now strip the build_node from the sources by calling the srcnode + # function + def get_final_srcnode(file): + srcnode = file.srcnode() + while srcnode != file.srcnode(): + srcnode = file.srcnode() + return srcnode + + # get the final srcnode for all nodes, this means stripping any + # attached build node. + map( get_final_srcnode, sources ) + + # remove duplicates + return list(set(sources)) + class OverrideEnvironment(Base): """A proxy that overrides variables in a wrapped construction environment by returning values from an overrides dictionary in |