Always launch a sub command with a specified environment.

This commit is contained in:
Matthieu Gautier 2017-01-17 11:24:01 +01:00 committed by Matthieu Gautier
parent 0676667fe0
commit ea6bf84f2c
1 changed files with 6 additions and 7 deletions

View File

@ -170,20 +170,19 @@ class BuildEnv:
def run_command(self, command, cwd, context, env=None, input=None): def run_command(self, command, cwd, context, env=None, input=None):
os.makedirs(cwd, exist_ok=True) os.makedirs(cwd, exist_ok=True)
if env is None:
env = dict(os.environ)
with open(context.log_file, 'w') as log: with open(context.log_file, 'w') as log:
log.write("run command '{}'\n".format(command)) log.write("run command '{}'\n".format(command))
if env: log.write("env is :\n")
log.write("env is :\n") for k, v in env.items():
for k, v in env.items(): log.write(" {} : {!r}\n".format(k, v))
log.write(" {} : {!r}\n".format(k, v))
log.flush() log.flush()
kwargs = dict() kwargs = dict()
if env:
kwargs['env'] = env
if input: if input:
kwargs['stdin'] = input kwargs['stdin'] = input
return subprocess.check_call(command, shell=True, cwd=cwd, stdout=log, stderr=subprocess.STDOUT, **kwargs) return subprocess.check_call(command, shell=True, cwd=cwd, env=env, stdout=log, stderr=subprocess.STDOUT, **kwargs)
def download(self, what, where=None): def download(self, what, where=None):
where = where or self.archive_dir where = where or self.archive_dir