diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2010-10-11 12:53:54 +0100 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-10-11 12:53:54 +0100 |
commit | d14f9bf6c470907d77654a35b4b55f30bdc182ff (patch) | |
tree | 0c8d6175525338c8460718760d4df4ee98094410 /bitbake | |
parent | ff539b11acca9831b72f3bc951a6ef20cd293786 (diff) | |
download | poky-d14f9bf6c470907d77654a35b4b55f30bdc182ff.tar.gz |
bitbake/build.py: Write logfiles on a per task basis, not per function
Per function logging made it hard to track down what was happening so
switch to logging on a per task basis.
[BUGID #383]
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/build.py | 149 |
1 files changed, 78 insertions, 71 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 0e2b8bf2f5..5fa18aa6af 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py | |||
@@ -117,59 +117,18 @@ def exec_func(func, d, dirs = None): | |||
117 | except OSError: | 117 | except OSError: |
118 | prevdir = data.getVar('TOPDIR', d, True) | 118 | prevdir = data.getVar('TOPDIR', d, True) |
119 | 119 | ||
120 | # Setup logfiles | 120 | # Setup scriptfile |
121 | t = data.getVar('T', d, 1) | 121 | t = data.getVar('T', d, 1) |
122 | if not t: | 122 | if not t: |
123 | raise SystemExit("T variable not set, unable to build") | 123 | raise SystemExit("T variable not set, unable to build") |
124 | bb.utils.mkdirhier(t) | 124 | bb.utils.mkdirhier(t) |
125 | loglink = "%s/log.%s" % (t, func) | ||
126 | logfile = "%s/log.%s.%s" % (t, func, str(os.getpid())) | ||
127 | runfile = "%s/run.%s.%s" % (t, func, str(os.getpid())) | 125 | runfile = "%s/run.%s.%s" % (t, func, str(os.getpid())) |
128 | 126 | logfile = d.getVar("BB_LOGFILE", True) | |
129 | # Even though the log file has not yet been opened, lets create the link | ||
130 | if loglink: | ||
131 | try: | ||
132 | os.remove(loglink) | ||
133 | except OSError as e: | ||
134 | pass | ||
135 | |||
136 | try: | ||
137 | os.symlink(logfile, loglink) | ||
138 | except OSError as e: | ||
139 | pass | ||
140 | 127 | ||
141 | # Change to correct directory (if specified) | 128 | # Change to correct directory (if specified) |
142 | if adir and os.access(adir, os.F_OK): | 129 | if adir and os.access(adir, os.F_OK): |
143 | os.chdir(adir) | 130 | os.chdir(adir) |
144 | 131 | ||
145 | # Handle logfiles | ||
146 | si = file('/dev/null', 'r') | ||
147 | try: | ||
148 | if bb.msg.debug_level['default'] > 0 and not ispython: | ||
149 | so = os.popen("tee \"%s\"" % logfile, "w") | ||
150 | else: | ||
151 | so = file(logfile, 'w') | ||
152 | except OSError as e: | ||
153 | bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e) | ||
154 | pass | ||
155 | |||
156 | se = so | ||
157 | |||
158 | # Dup the existing fds so we dont lose them | ||
159 | osi = [os.dup(sys.stdin.fileno()), sys.stdin.fileno()] | ||
160 | oso = [os.dup(sys.stdout.fileno()), sys.stdout.fileno()] | ||
161 | ose = [os.dup(sys.stderr.fileno()), sys.stderr.fileno()] | ||
162 | |||
163 | # Replace those fds with our own | ||
164 | os.dup2(si.fileno(), osi[1]) | ||
165 | os.dup2(so.fileno(), oso[1]) | ||
166 | os.dup2(se.fileno(), ose[1]) | ||
167 | |||
168 | # Since we've remapped stdout and stderr, its safe for log messages to be printed there now | ||
169 | # exec_func can nest so we have to save state | ||
170 | origstdout = bb.event.useStdout | ||
171 | bb.event.useStdout = True | ||
172 | |||
173 | locks = [] | 132 | locks = [] |
174 | lockfiles = flags['lockfiles'] | 133 | lockfiles = flags['lockfiles'] |
175 | if lockfiles: | 134 | if lockfiles: |
@@ -195,34 +154,6 @@ def exec_func(func, d, dirs = None): | |||
195 | for lock in locks: | 154 | for lock in locks: |
196 | bb.utils.unlockfile(lock) | 155 | bb.utils.unlockfile(lock) |
197 | 156 | ||
198 | sys.stdout.flush() | ||
199 | sys.stderr.flush() | ||
200 | |||
201 | bb.event.useStdout = origstdout | ||
202 | |||
203 | # Restore the backup fds | ||
204 | os.dup2(osi[0], osi[1]) | ||
205 | os.dup2(oso[0], oso[1]) | ||
206 | os.dup2(ose[0], ose[1]) | ||
207 | |||
208 | # Close our logs | ||
209 | si.close() | ||
210 | so.close() | ||
211 | se.close() | ||
212 | |||
213 | if os.path.exists(logfile) and os.path.getsize(logfile) == 0: | ||
214 | bb.msg.debug(2, bb.msg.domain.Build, "Zero size logfile %s, removing" % logfile) | ||
215 | os.remove(logfile) | ||
216 | try: | ||
217 | os.remove(loglink) | ||
218 | except OSError as e: | ||
219 | pass | ||
220 | |||
221 | # Close the backup fds | ||
222 | os.close(osi[0]) | ||
223 | os.close(oso[0]) | ||
224 | os.close(ose[0]) | ||
225 | |||
226 | def exec_func_python(func, d, runfile, logfile): | 157 | def exec_func_python(func, d, runfile, logfile): |
227 | """Execute a python BB 'function'""" | 158 | """Execute a python BB 'function'""" |
228 | 159 | ||
@@ -312,6 +243,53 @@ def exec_task(fn, task, d): | |||
312 | data.setVar('BB_FILENAME', fn, d) | 243 | data.setVar('BB_FILENAME', fn, d) |
313 | data.setVar('BB_CURRENTTASK', task[3:], d) | 244 | data.setVar('BB_CURRENTTASK', task[3:], d) |
314 | event.fire(TaskStarted(task, localdata), localdata) | 245 | event.fire(TaskStarted(task, localdata), localdata) |
246 | |||
247 | # Setup logfiles | ||
248 | t = data.getVar('T', d, 1) | ||
249 | if not t: | ||
250 | raise SystemExit("T variable not set, unable to build") | ||
251 | bb.utils.mkdirhier(t) | ||
252 | loglink = "%s/log.%s" % (t, task) | ||
253 | logfile = "%s/log.%s.%s" % (t, task, str(os.getpid())) | ||
254 | d.setVar("BB_LOGFILE", logfile) | ||
255 | |||
256 | # Even though the log file has not yet been opened, lets create the link | ||
257 | if loglink: | ||
258 | try: | ||
259 | os.remove(loglink) | ||
260 | except OSError as e: | ||
261 | pass | ||
262 | |||
263 | try: | ||
264 | os.symlink(logfile, loglink) | ||
265 | except OSError as e: | ||
266 | pass | ||
267 | |||
268 | # Handle logfiles | ||
269 | si = file('/dev/null', 'r') | ||
270 | try: | ||
271 | so = file(logfile, 'w') | ||
272 | except OSError as e: | ||
273 | bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e) | ||
274 | pass | ||
275 | se = so | ||
276 | |||
277 | # Dup the existing fds so we dont lose them | ||
278 | osi = [os.dup(sys.stdin.fileno()), sys.stdin.fileno()] | ||
279 | oso = [os.dup(sys.stdout.fileno()), sys.stdout.fileno()] | ||
280 | ose = [os.dup(sys.stderr.fileno()), sys.stderr.fileno()] | ||
281 | |||
282 | # Replace those fds with our own | ||
283 | os.dup2(si.fileno(), osi[1]) | ||
284 | os.dup2(so.fileno(), oso[1]) | ||
285 | os.dup2(se.fileno(), ose[1]) | ||
286 | |||
287 | # Since we've remapped stdout and stderr, its safe for log messages to be printed there now | ||
288 | # exec_func can nest so we have to save state | ||
289 | origstdout = bb.event.useStdout | ||
290 | bb.event.useStdout = True | ||
291 | |||
292 | |||
315 | prefuncs = (data.getVarFlag(task, 'prefuncs', localdata) or "").split() | 293 | prefuncs = (data.getVarFlag(task, 'prefuncs', localdata) or "").split() |
316 | for func in prefuncs: | 294 | for func in prefuncs: |
317 | exec_func(func, localdata) | 295 | exec_func(func, localdata) |
@@ -319,6 +297,7 @@ def exec_task(fn, task, d): | |||
319 | postfuncs = (data.getVarFlag(task, 'postfuncs', localdata) or "").split() | 297 | postfuncs = (data.getVarFlag(task, 'postfuncs', localdata) or "").split() |
320 | for func in postfuncs: | 298 | for func in postfuncs: |
321 | exec_func(func, localdata) | 299 | exec_func(func, localdata) |
300 | |||
322 | event.fire(TaskSucceeded(task, localdata), localdata) | 301 | event.fire(TaskSucceeded(task, localdata), localdata) |
323 | 302 | ||
324 | # make stamp, or cause event and raise exception | 303 | # make stamp, or cause event and raise exception |
@@ -346,6 +325,34 @@ def exec_task(fn, task, d): | |||
346 | failedevent = TaskFailed("Task Failed", None, task, d) | 325 | failedevent = TaskFailed("Task Failed", None, task, d) |
347 | event.fire(failedevent, d) | 326 | event.fire(failedevent, d) |
348 | return 1 | 327 | return 1 |
328 | finally: | ||
329 | sys.stdout.flush() | ||
330 | sys.stderr.flush() | ||
331 | |||
332 | bb.event.useStdout = origstdout | ||
333 | |||
334 | # Restore the backup fds | ||
335 | os.dup2(osi[0], osi[1]) | ||
336 | os.dup2(oso[0], oso[1]) | ||
337 | os.dup2(ose[0], ose[1]) | ||
338 | |||
339 | # Close our logs | ||
340 | si.close() | ||
341 | so.close() | ||
342 | se.close() | ||
343 | |||
344 | if logfile and os.path.exists(logfile) and os.path.getsize(logfile) == 0: | ||
345 | bb.msg.debug(2, bb.msg.domain.Build, "Zero size logfile %s, removing" % logfile) | ||
346 | os.remove(logfile) | ||
347 | try: | ||
348 | os.remove(loglink) | ||
349 | except OSError as e: | ||
350 | pass | ||
351 | |||
352 | # Close the backup fds | ||
353 | os.close(osi[0]) | ||
354 | os.close(oso[0]) | ||
355 | os.close(ose[0]) | ||
349 | 356 | ||
350 | return 0 | 357 | return 0 |
351 | 358 | ||