summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/process.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/process.py')
-rw-r--r--bitbake/lib/bb/process.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/bitbake/lib/bb/process.py b/bitbake/lib/bb/process.py
index 8b1aea9a10..d95a03d176 100644
--- a/bitbake/lib/bb/process.py
+++ b/bitbake/lib/bb/process.py
@@ -64,7 +64,7 @@ class Popen(subprocess.Popen):
64 options.update(kwargs) 64 options.update(kwargs)
65 subprocess.Popen.__init__(self, *args, **options) 65 subprocess.Popen.__init__(self, *args, **options)
66 66
67def _logged_communicate(pipe, log, input): 67def _logged_communicate(pipe, log, input, extrafiles):
68 if pipe.stdin: 68 if pipe.stdin:
69 if input is not None: 69 if input is not None:
70 pipe.stdin.write(input) 70 pipe.stdin.write(input)
@@ -79,6 +79,19 @@ def _logged_communicate(pipe, log, input):
79 if pipe.stderr is not None: 79 if pipe.stderr is not None:
80 bb.utils.nonblockingfd(pipe.stderr.fileno()) 80 bb.utils.nonblockingfd(pipe.stderr.fileno())
81 rin.append(pipe.stderr) 81 rin.append(pipe.stderr)
82 for fobj, _ in extrafiles:
83 bb.utils.nonblockingfd(fobj.fileno())
84 rin.append(fobj)
85
86 def readextras():
87 for fobj, func in extrafiles:
88 try:
89 data = fobj.read()
90 except IOError as err:
91 if err.errno == errno.EAGAIN or err.errno == errno.EWOULDBLOCK:
92 data = None
93 if data is not None:
94 func(data)
82 95
83 try: 96 try:
84 while pipe.poll() is None: 97 while pipe.poll() is None:
@@ -100,15 +113,21 @@ def _logged_communicate(pipe, log, input):
100 if data is not None: 113 if data is not None:
101 errdata.append(data) 114 errdata.append(data)
102 log.write(data) 115 log.write(data)
116
117 readextras()
118
103 finally: 119 finally:
104 log.flush() 120 log.flush()
121
122 readextras()
123
105 if pipe.stdout is not None: 124 if pipe.stdout is not None:
106 pipe.stdout.close() 125 pipe.stdout.close()
107 if pipe.stderr is not None: 126 if pipe.stderr is not None:
108 pipe.stderr.close() 127 pipe.stderr.close()
109 return ''.join(outdata), ''.join(errdata) 128 return ''.join(outdata), ''.join(errdata)
110 129
111def run(cmd, input=None, log=None, **options): 130def run(cmd, input=None, log=None, extrafiles=[], **options):
112 """Convenience function to run a command and return its output, raising an 131 """Convenience function to run a command and return its output, raising an
113 exception when the command fails""" 132 exception when the command fails"""
114 133
@@ -124,7 +143,7 @@ def run(cmd, input=None, log=None, **options):
124 raise CmdError(cmd, exc) 143 raise CmdError(cmd, exc)
125 144
126 if log: 145 if log:
127 stdout, stderr = _logged_communicate(pipe, log, input) 146 stdout, stderr = _logged_communicate(pipe, log, input, extrafiles)
128 else: 147 else:
129 stdout, stderr = pipe.communicate(input) 148 stdout, stderr = pipe.communicate(input)
130 149