]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
build: fix -D with shell functions
authorChris Larson <chris_larson@mentor.com>
Tue, 14 Dec 2010 16:20:33 +0000 (09:20 -0700)
committerChris Larson <chris_larson@mentor.com>
Tue, 14 Dec 2010 16:21:38 +0000 (09:21 -0700)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
lib/bb/build.py

index 01da9b3a3edd1debd6999782753928a19ced4311..df7bb7d6ea961e260d4241ca63f9d91b2b3b1efe 100644 (file)
@@ -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 "<open[tee] file '{0}'>".format(self.name)
+        return '<LogTee {0}>'.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)