diff options
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Builder.py | 15 | ||||
-rw-r--r-- | src/engine/SCons/Defaults.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 13 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 12 | ||||
-rw-r--r-- | src/engine/SCons/Node/__init__.py | 3 |
5 files changed, 41 insertions, 4 deletions
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 72b01cf..2852b3a 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -94,7 +94,20 @@ class CommandAction(ActionBase): if print_actions: self.show(cmd) if execute_actions: - os.system(cmd) + pid = os.fork() + if not pid: + # Child process. + args = string.split(cmd) + try: + ENV = kw['ENV'] + except: + import SCons.Defaults + ENV = SCons.Defaults.ENV + os.execvpe(args[0], args, ENV) + else: + # Parent process. + os.waitpid(pid, 0) + class FunctionAction(ActionBase): """Class for Python function actions.""" diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 7b5e83d..0f6ffda 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -20,3 +20,5 @@ Program = SCons.Builder.Builder(name = 'Program', action = 'cc -o %(target)s %(source)s') Builders = [Object, Program] + +ENV = { 'PATH' : '/usr/local/bin:/bin:/usr/bin' } diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 508392b..c7c32dd 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -61,6 +61,9 @@ class Environment: else: import SCons.Defaults kw['BUILDERS'] = SCons.Defaults.Builders[:] + if not kw.has_key('ENV'): + import SCons.Defaults + kw['ENV'] = SCons.Defaults.ENV.copy() self._dict.update(copy.deepcopy(kw)) class BuilderWrapper: @@ -74,8 +77,16 @@ class Environment: def __call__(self, target = None, source = None): return self.builder(self.env, target, source) + # This allows a Builder to be executed directly + # through the Environment to which it's attached. + # In practice, we shouldn't need this, because + # builders actually get executed through a Node. + # But we do have a unit test for this, and can't + # yet rule out that it would be useful in the + # future, so leave it for now. def execute(self, **kw): - apply(self.builder.execute, (), kw) + kw['env'] = self + apply(self.builder.execute, (), kw) for b in kw['BUILDERS']: setattr(self, b.name, BuilderWrapper(self, b)) diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 0488173..c503fe2 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -16,7 +16,7 @@ class Builder: def __init__(self, name = None): self.name = name - def execute(self, target = None, source = None): + def execute(self, target = None, **kw): built_it[target] = 1 @@ -94,6 +94,16 @@ class EnvironmentTestCase(unittest.TestCase): assert xxx == 'x' assert zzz == 'z' assert env.Dictionary().has_key('BUILDERS') + assert env.Dictionary().has_key('ENV') + + def test_ENV(self): + """Test setting the external ENV in Environments + """ + env = Environment() + assert env.Dictionary().has_key('ENV') + + env = Environment(ENV = { 'PATH' : '/foo:/bar' }) + assert env.Dictionary('ENV')['PATH'] == '/foo:/bar' def test_Environment(self): """Test construction Environments creation diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 8609c57..4f414ec 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -25,7 +25,8 @@ class Node: def build(self): sources_str = string.join(map(lambda x: str(x), self.sources)) - self.builder.execute(target = str(self), source = sources_str) + self.builder.execute(ENV = self.env.Dictionary('ENV'), + target = str(self), source = sources_str) def builder_set(self, builder): self.builder = builder |