summaryrefslogtreecommitdiffstats
path: root/scripts/combo-layer
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2015-03-10 09:48:15 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-03-20 11:21:22 +0000
commit627e524238893b537454fd48dade0dde8c64362d (patch)
tree5688e31e46dbf4df8c3328a0abef71a7ca262062 /scripts/combo-layer
parent58c5bb28b525afb1ed1959305adee65ae7f5dba0 (diff)
downloadpoky-627e524238893b537454fd48dade0dde8c64362d.tar.gz
combo-layer: runcmd() with separate output
Allow the caller to specify a separate output stream. stderr is always a temporary file opened by runcmd(), so read from that to capture output for error reporting *and* the return value. The reasoning for the latter is a) that this preserves the traditional behavior when out=None and b) if the caller wants the content of stdout, it can read from the stream itself, which is not possible for the temporary stderr. (From OE-Core rev: a084162a9dc4718ab453723f1f28aefc55100e2e) Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/combo-layer')
-rwxr-xr-xscripts/combo-layer18
1 files changed, 11 insertions, 7 deletions
diff --git a/scripts/combo-layer b/scripts/combo-layer
index 62f2cf8fa3..3ee9eb203d 100755
--- a/scripts/combo-layer
+++ b/scripts/combo-layer
@@ -152,23 +152,27 @@ class Configuration(object):
152 logger.error("ERROR: patchutils package is missing, please install it (e.g. # apt-get install patchutils)") 152 logger.error("ERROR: patchutils package is missing, please install it (e.g. # apt-get install patchutils)")
153 sys.exit(1) 153 sys.exit(1)
154 154
155def runcmd(cmd,destdir=None,printerr=True): 155def runcmd(cmd,destdir=None,printerr=True,out=None):
156 """ 156 """
157 execute command, raise CalledProcessError if fail 157 execute command, raise CalledProcessError if fail
158 return output if succeed 158 return output if succeed
159 """ 159 """
160 logger.debug("run cmd '%s' in %s" % (cmd, os.getcwd() if destdir is None else destdir)) 160 logger.debug("run cmd '%s' in %s" % (cmd, os.getcwd() if destdir is None else destdir))
161 out = os.tmpfile() 161 if not out:
162 out = os.tmpfile()
163 err = out
164 else:
165 err = os.tmpfile()
162 try: 166 try:
163 subprocess.check_call(cmd, stdout=out, stderr=out, cwd=destdir, shell=True) 167 subprocess.check_call(cmd, stdout=out, stderr=err, cwd=destdir, shell=isinstance(cmd, str))
164 except subprocess.CalledProcessError,e: 168 except subprocess.CalledProcessError,e:
165 out.seek(0) 169 err.seek(0)
166 if printerr: 170 if printerr:
167 logger.error("%s" % out.read()) 171 logger.error("%s" % err.read())
168 raise e 172 raise e
169 173
170 out.seek(0) 174 err.seek(0)
171 output = out.read() 175 output = err.read()
172 logger.debug("output: %s" % output ) 176 logger.debug("output: %s" % output )
173 return output 177 return output
174 178