diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-12 08:30:35 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-02 08:24:02 +0100 |
commit | 0f2c59367a649de5f57acdccfb4f1fdba9cde730 (patch) | |
tree | 7a3558a3e08e690fbb0b5bdc4044316f9ab4bbcb /bitbake/bin/bitbake-worker | |
parent | ef1df516512587ad415f76a9626620992d660e45 (diff) | |
download | poky-0f2c59367a649de5f57acdccfb4f1fdba9cde730.tar.gz |
bitbake: bitbake: Convert to python 3
Various misc changes to convert bitbake to python3 which don't warrant
separation into separate commits.
(Bitbake rev: d0f904d407f57998419bd9c305ce53e5eaa36b24)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin/bitbake-worker')
-rwxr-xr-x | bitbake/bin/bitbake-worker | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/bitbake/bin/bitbake-worker b/bitbake/bin/bitbake-worker index 6a6b26b64a..5d062a23e9 100755 --- a/bitbake/bin/bitbake-worker +++ b/bitbake/bin/bitbake-worker | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
2 | 2 | ||
3 | import os | 3 | import os |
4 | import sys | 4 | import sys |
@@ -10,8 +10,12 @@ import bb | |||
10 | import select | 10 | import select |
11 | import errno | 11 | import errno |
12 | import signal | 12 | import signal |
13 | import pickle | ||
13 | from multiprocessing import Lock | 14 | from multiprocessing import Lock |
14 | 15 | ||
16 | if sys.getfilesystemencoding() != "utf-8": | ||
17 | sys.exit("Please use a locale setting which supports utf-8.\nPython can't change the filesystem locale after loading so we need a utf-8 when python starts or things won't work.") | ||
18 | |||
15 | # Users shouldn't be running this code directly | 19 | # Users shouldn't be running this code directly |
16 | if len(sys.argv) != 2 or not sys.argv[1].startswith("decafbad"): | 20 | if len(sys.argv) != 2 or not sys.argv[1].startswith("decafbad"): |
17 | print("bitbake-worker is meant for internal execution by bitbake itself, please don't use it standalone.") | 21 | print("bitbake-worker is meant for internal execution by bitbake itself, please don't use it standalone.") |
@@ -30,19 +34,16 @@ if sys.argv[1].startswith("decafbadbad"): | |||
30 | # updates to log files for use with tail | 34 | # updates to log files for use with tail |
31 | try: | 35 | try: |
32 | if sys.stdout.name == '<stdout>': | 36 | if sys.stdout.name == '<stdout>': |
33 | sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | 37 | import fcntl |
38 | fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL) | ||
39 | fl |= os.O_SYNC | ||
40 | fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl) | ||
41 | #sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | ||
34 | except: | 42 | except: |
35 | pass | 43 | pass |
36 | 44 | ||
37 | logger = logging.getLogger("BitBake") | 45 | logger = logging.getLogger("BitBake") |
38 | 46 | ||
39 | try: | ||
40 | import cPickle as pickle | ||
41 | except ImportError: | ||
42 | import pickle | ||
43 | bb.msg.note(1, bb.msg.domain.Cache, "Importing cPickle failed. Falling back to a very slow implementation.") | ||
44 | |||
45 | |||
46 | worker_pipe = sys.stdout.fileno() | 47 | worker_pipe = sys.stdout.fileno() |
47 | bb.utils.nonblockingfd(worker_pipe) | 48 | bb.utils.nonblockingfd(worker_pipe) |
48 | # Need to guard against multiprocessing being used in child processes | 49 | # Need to guard against multiprocessing being used in child processes |
@@ -62,10 +63,10 @@ if 0: | |||
62 | consolelog.setFormatter(conlogformat) | 63 | consolelog.setFormatter(conlogformat) |
63 | logger.addHandler(consolelog) | 64 | logger.addHandler(consolelog) |
64 | 65 | ||
65 | worker_queue = "" | 66 | worker_queue = b"" |
66 | 67 | ||
67 | def worker_fire(event, d): | 68 | def worker_fire(event, d): |
68 | data = "<event>" + pickle.dumps(event) + "</event>" | 69 | data = b"<event>" + pickle.dumps(event) + b"</event>" |
69 | worker_fire_prepickled(data) | 70 | worker_fire_prepickled(data) |
70 | 71 | ||
71 | def worker_fire_prepickled(event): | 72 | def worker_fire_prepickled(event): |
@@ -91,7 +92,7 @@ def worker_child_fire(event, d): | |||
91 | global worker_pipe | 92 | global worker_pipe |
92 | global worker_pipe_lock | 93 | global worker_pipe_lock |
93 | 94 | ||
94 | data = "<event>" + pickle.dumps(event) + "</event>" | 95 | data = b"<event>" + pickle.dumps(event) + b"</event>" |
95 | try: | 96 | try: |
96 | worker_pipe_lock.acquire() | 97 | worker_pipe_lock.acquire() |
97 | worker_pipe.write(data) | 98 | worker_pipe.write(data) |
@@ -251,7 +252,7 @@ def fork_off_task(cfg, data, workerdata, fn, task, taskname, appends, taskdepdat | |||
251 | bb.utils.process_profilelog(profname) | 252 | bb.utils.process_profilelog(profname) |
252 | os._exit(ret) | 253 | os._exit(ret) |
253 | else: | 254 | else: |
254 | for key, value in envbackup.iteritems(): | 255 | for key, value in iter(envbackup.items()): |
255 | if value is None: | 256 | if value is None: |
256 | del os.environ[key] | 257 | del os.environ[key] |
257 | else: | 258 | else: |
@@ -268,22 +269,22 @@ class runQueueWorkerPipe(): | |||
268 | if pipeout: | 269 | if pipeout: |
269 | pipeout.close() | 270 | pipeout.close() |
270 | bb.utils.nonblockingfd(self.input) | 271 | bb.utils.nonblockingfd(self.input) |
271 | self.queue = "" | 272 | self.queue = b"" |
272 | 273 | ||
273 | def read(self): | 274 | def read(self): |
274 | start = len(self.queue) | 275 | start = len(self.queue) |
275 | try: | 276 | try: |
276 | self.queue = self.queue + self.input.read(102400) | 277 | self.queue = self.queue + (self.input.read(102400) or b"") |
277 | except (OSError, IOError) as e: | 278 | except (OSError, IOError) as e: |
278 | if e.errno != errno.EAGAIN: | 279 | if e.errno != errno.EAGAIN: |
279 | raise | 280 | raise |
280 | 281 | ||
281 | end = len(self.queue) | 282 | end = len(self.queue) |
282 | index = self.queue.find("</event>") | 283 | index = self.queue.find(b"</event>") |
283 | while index != -1: | 284 | while index != -1: |
284 | worker_fire_prepickled(self.queue[:index+8]) | 285 | worker_fire_prepickled(self.queue[:index+8]) |
285 | self.queue = self.queue[index+8:] | 286 | self.queue = self.queue[index+8:] |
286 | index = self.queue.find("</event>") | 287 | index = self.queue.find(b"</event>") |
287 | return (end > start) | 288 | return (end > start) |
288 | 289 | ||
289 | def close(self): | 290 | def close(self): |
@@ -299,7 +300,7 @@ class BitbakeWorker(object): | |||
299 | def __init__(self, din): | 300 | def __init__(self, din): |
300 | self.input = din | 301 | self.input = din |
301 | bb.utils.nonblockingfd(self.input) | 302 | bb.utils.nonblockingfd(self.input) |
302 | self.queue = "" | 303 | self.queue = b"" |
303 | self.cookercfg = None | 304 | self.cookercfg = None |
304 | self.databuilder = None | 305 | self.databuilder = None |
305 | self.data = None | 306 | self.data = None |
@@ -336,12 +337,12 @@ class BitbakeWorker(object): | |||
336 | except (OSError, IOError): | 337 | except (OSError, IOError): |
337 | pass | 338 | pass |
338 | if len(self.queue): | 339 | if len(self.queue): |
339 | self.handle_item("cookerconfig", self.handle_cookercfg) | 340 | self.handle_item(b"cookerconfig", self.handle_cookercfg) |
340 | self.handle_item("workerdata", self.handle_workerdata) | 341 | self.handle_item(b"workerdata", self.handle_workerdata) |
341 | self.handle_item("runtask", self.handle_runtask) | 342 | self.handle_item(b"runtask", self.handle_runtask) |
342 | self.handle_item("finishnow", self.handle_finishnow) | 343 | self.handle_item(b"finishnow", self.handle_finishnow) |
343 | self.handle_item("ping", self.handle_ping) | 344 | self.handle_item(b"ping", self.handle_ping) |
344 | self.handle_item("quit", self.handle_quit) | 345 | self.handle_item(b"quit", self.handle_quit) |
345 | 346 | ||
346 | for pipe in self.build_pipes: | 347 | for pipe in self.build_pipes: |
347 | self.build_pipes[pipe].read() | 348 | self.build_pipes[pipe].read() |
@@ -351,12 +352,12 @@ class BitbakeWorker(object): | |||
351 | 352 | ||
352 | 353 | ||
353 | def handle_item(self, item, func): | 354 | def handle_item(self, item, func): |
354 | if self.queue.startswith("<" + item + ">"): | 355 | if self.queue.startswith(b"<" + item + b">"): |
355 | index = self.queue.find("</" + item + ">") | 356 | index = self.queue.find(b"</" + item + b">") |
356 | while index != -1: | 357 | while index != -1: |
357 | func(self.queue[(len(item) + 2):index]) | 358 | func(self.queue[(len(item) + 2):index]) |
358 | self.queue = self.queue[(index + len(item) + 3):] | 359 | self.queue = self.queue[(index + len(item) + 3):] |
359 | index = self.queue.find("</" + item + ">") | 360 | index = self.queue.find(b"</" + item + b">") |
360 | 361 | ||
361 | def handle_cookercfg(self, data): | 362 | def handle_cookercfg(self, data): |
362 | self.cookercfg = pickle.loads(data) | 363 | self.cookercfg = pickle.loads(data) |
@@ -420,12 +421,12 @@ class BitbakeWorker(object): | |||
420 | self.build_pipes[pid].close() | 421 | self.build_pipes[pid].close() |
421 | del self.build_pipes[pid] | 422 | del self.build_pipes[pid] |
422 | 423 | ||
423 | worker_fire_prepickled("<exitcode>" + pickle.dumps((task, status)) + "</exitcode>") | 424 | worker_fire_prepickled(b"<exitcode>" + pickle.dumps((task, status)) + b"</exitcode>") |
424 | 425 | ||
425 | def handle_finishnow(self, _): | 426 | def handle_finishnow(self, _): |
426 | if self.build_pids: | 427 | if self.build_pids: |
427 | logger.info("Sending SIGTERM to remaining %s tasks", len(self.build_pids)) | 428 | logger.info("Sending SIGTERM to remaining %s tasks", len(self.build_pids)) |
428 | for k, v in self.build_pids.iteritems(): | 429 | for k, v in iter(self.build_pids.items()): |
429 | try: | 430 | try: |
430 | os.kill(-k, signal.SIGTERM) | 431 | os.kill(-k, signal.SIGTERM) |
431 | os.waitpid(-1, 0) | 432 | os.waitpid(-1, 0) |
@@ -435,6 +436,7 @@ class BitbakeWorker(object): | |||
435 | self.build_pipes[pipe].read() | 436 | self.build_pipes[pipe].read() |
436 | 437 | ||
437 | try: | 438 | try: |
439 | sys.stdin = sys.stdin.detach() | ||
438 | worker = BitbakeWorker(sys.stdin) | 440 | worker = BitbakeWorker(sys.stdin) |
439 | if not profiling: | 441 | if not profiling: |
440 | worker.serve() | 442 | worker.serve() |