From: Chris Larson Date: Tue, 14 Dec 2010 16:20:33 +0000 (-0700) Subject: build: fix -D with shell functions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c8be64732fdf4f3a608c090b3dc92065d6058d6;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git build: fix -D with shell functions Signed-off-by: Chris Larson --- diff --git a/lib/bb/build.py b/lib/bb/build.py index 01da9b3a3ed..df7bb7d6ea9 100644 --- a/lib/bb/build.py +++ b/lib/bb/build.py @@ -105,13 +105,27 @@ class InvalidTask(Exception): return "No such task '%s'" % self.task -class tee(file): +class LogTee(object): + def __init__(self, logger, *files): + self.files = files + self.logger = logger + def write(self, string): - logger.plain(string) - file.write(self, string) + self.logger.plain(string) + for f in self.files: + f.write(string) + + def __enter__(self): + for f in self.files: + f.__enter__() + return self + + def __exit__(self, *excinfo): + for f in self.files: + f.__exit__(*excinfo) def __repr__(self): - return "".format(self.name) + return ''.format(', '.join(repr(f.name) for f in self.files)) def exec_func(func, d, dirs = None): @@ -164,17 +178,13 @@ def exec_func(func, d, dirs = None): except OSError: pass - if logger.getEffectiveLevel() <= logging.DEBUG: - logfile = tee(logfn, 'w') - else: - logfile = open(logfn, 'w') - lockflag = flags.get('lockfiles') if lockflag: lockfiles = [data.expand(f, d) for f in lockflag.split()] else: lockfiles = None + logfile = open(logfn, 'w') with nested(logfile, bb.utils.fileslocked(lockfiles)): try: if ispython: @@ -255,6 +265,9 @@ def exec_func_shell(function, d, runfile, logfile, cwd=None, fakeroot=False): else: cmd = runfile + if logger.getEffectiveLevel() <= logging.DEBUG: + logfile = LogTee(logger, logfile) + try: bb.process.run(cmd, env=env, cwd=cwd, shell=False, stdin=NULL, log=logfile)