summaryrefslogtreecommitdiffstats
path: root/bitbake/bin
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.co>2011-11-24 12:55:14 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-11-25 11:25:53 +0000
commit37c4f373e42b54f6c65b8482bd1172563fbc1ea5 (patch)
tree794326622526c6005326e1427a074b894c3a75eb /bitbake/bin
parent4ce5d30de78be5ce637a576bc84d59ca1547f5bc (diff)
downloadpoky-37c4f373e42b54f6c65b8482bd1172563fbc1ea5.tar.gz
bitbake: Update and fix bitbake-runtask
Since bitbake switched back to the fork instead of the exec model, it no longer used bitbake-runtask and the code has suffered some bitrot. bitbake-runtask is a useful tool for excuting the task without the scheduler of bitbake, so that the external tool can invoke it easily. It also provides a useful example of how to invoke exec_task() with low overhead without a lot of the bitbake threading/UI overhead. Significant changes: * This patch changes the argument order so that the commonly used and mandatory arguments come first. * The taskhash file and dryrun options are now optional * It now uses the bitbake logging mechanisms to provide processed logging output to the console. * The process handling to do with stdout/stderr redirection are removed since they're no longer required. [YOCTO #1229] RP: Logging updates to the patch based on Roberts original patch Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin')
-rwxr-xr-xbitbake/bin/bitbake-runtask131
1 files changed, 65 insertions, 66 deletions
diff --git a/bitbake/bin/bitbake-runtask b/bitbake/bin/bitbake-runtask
index bee0f429ff..394b4c3ef9 100755
--- a/bitbake/bin/bitbake-runtask
+++ b/bitbake/bin/bitbake-runtask
@@ -4,6 +4,10 @@ import os
4import sys 4import sys
5import warnings 5import warnings
6sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib')) 6sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
7from bb import fetch2
8import logging
9
10logger = logging.getLogger("BitBake")
7 11
8try: 12try:
9 import cPickle as pickle 13 import cPickle as pickle
@@ -16,13 +20,20 @@ class BBConfiguration(object):
16 Manages build options and configurations for one run 20 Manages build options and configurations for one run
17 """ 21 """
18 22
19 def __init__(self, debug, debug_domains): 23 def __init__(self, **options):
20 setattr(self, "data", {}) 24 self.data = {}
21 setattr(self, "file", []) 25 self.file = []
22 setattr(self, "cmd", None) 26 self.cmd = None
23 setattr(self, "dump_signatures", True) 27 self.dump_signatures = True
24 setattr(self, "debug", debug) 28 self.prefile = []
25 setattr(self, "debug_domains", debug_domains) 29 self.postfile = []
30 self.parse_only = True
31
32 def __getattr__(self, attribute):
33 try:
34 return super(BBConfiguration, self).__getattribute__(attribute)
35 except AttributeError:
36 return None
26 37
27_warnings_showwarning = warnings.showwarning 38_warnings_showwarning = warnings.showwarning
28def _showwarning(message, category, filename, lineno, file=None, line=None): 39def _showwarning(message, category, filename, lineno, file=None, line=None):
@@ -39,82 +50,70 @@ warnings.showwarning = _showwarning
39warnings.simplefilter("ignore", DeprecationWarning) 50warnings.simplefilter("ignore", DeprecationWarning)
40 51
41import bb.event 52import bb.event
42
43# Need to map our I/O correctly. stdout is a pipe to the server expecting
44# events. We save this and then map stdout to stderr.
45
46eventfd = os.dup(sys.stdout.fileno())
47bb.event.worker_pipe = os.fdopen(eventfd, 'w', 0)
48
49# map stdout to stderr
50os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
51
52# Replace those fds with our own
53#logout = data.expand("${TMPDIR}/log/stdout.%s" % os.getpid(), self.cfgData, True)
54#mkdirhier(os.path.dirname(logout))
55#newso = open("/tmp/stdout.%s" % os.getpid(), 'w')
56#os.dup2(newso.fileno(), sys.stdout.fileno())
57#os.dup2(newso.fileno(), sys.stderr.fileno())
58
59# Don't read from stdin from the parent
60si = file("/dev/null", 'r')
61os.dup2(si.fileno( ), sys.stdin.fileno( ))
62
63# We don't want to see signals to our parent, e.g. Ctrl+C
64os.setpgrp()
65
66# Save out the PID so that the event can include it the
67# events
68bb.event.worker_pid = os.getpid()
69bb.event.useStdout = False
70
71hashfile = sys.argv[1]
72buildfile = sys.argv[2]
73taskname = sys.argv[3]
74
75import bb.cooker 53import bb.cooker
76 54
77p = pickle.Unpickler(file(hashfile, "rb")) 55buildfile = sys.argv[1]
78hashdata = p.load() 56taskname = sys.argv[2]
79 57if len(sys.argv) >= 4:
80debug = hashdata["msg-debug"] 58 dryrun = sys.argv[3]
81debug_domains = hashdata["msg-debug-domains"] 59else:
82verbose = hashdata["verbose"] 60 dryrun = False
61if len(sys.argv) >= 5:
62 hashfile = sys.argv[4]
63 p = pickle.Unpickler(file(hashfile, "rb"))
64 hashdata = p.load()
65else:
66 hashdata = None
67
68handler = bb.event.LogHandler()
69logger.addHandler(handler)
70
71#An example to make debug log messages show up
72#bb.msg.init_msgconfig(True, 3, [])
73
74console = logging.StreamHandler(sys.stdout)
75format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
76bb.msg.addDefaultlogFilter(console)
77console.setFormatter(format)
78
79def worker_fire(event, d):
80 if isinstance(event, logging.LogRecord):
81 console.handle(event)
82bb.event.worker_fire = worker_fire
83bb.event.worker_pid = os.getpid()
83 84
84bb.utils.init_logger(bb.msg, verbose, debug, debug_domains) 85initialenv = os.environ.copy()
86config = BBConfiguration()
85 87
86cooker = bb.cooker.BBCooker(BBConfiguration(debug, debug_domains), None) 88def register_idle_function(self, function, data):
87cooker.parseConfiguration() 89 pass
88 90
89cooker.bb_cache = bb.cache.init(cooker) 91cooker = bb.cooker.BBCooker(config, register_idle_function, initialenv)
90cooker.status = bb.cache.CacheData() 92config_data = cooker.configuration.data
93cooker.status = config_data
94cooker.handleCollections(bb.data.getVar("BBFILE_COLLECTIONS", config_data, 1))
91 95
92(fn, cls) = cooker.bb_cache.virtualfn2realfn(buildfile) 96fn, cls = bb.cache.Cache.virtualfn2realfn(buildfile)
93buildfile = cooker.matchFile(fn) 97buildfile = cooker.matchFile(fn)
94fn = cooker.bb_cache.realfn2virtual(buildfile, cls) 98fn = bb.cache.Cache.realfn2virtual(buildfile, cls)
95 99
96cooker.buildSetVars() 100cooker.buildSetVars()
97 101
98# Load data into the cache for fn and parse the loaded cache data 102# Load data into the cache for fn and parse the loaded cache data
99the_data = cooker.bb_cache.loadDataFull(fn, cooker.get_file_appends(fn), cooker.configuration.data) 103the_data = bb.cache.Cache.loadDataFull(fn, cooker.get_file_appends(fn), cooker.configuration.data)
100cooker.bb_cache.setData(fn, buildfile, the_data)
101cooker.bb_cache.handle_data(fn, cooker.status)
102
103#exportlist = bb.utils.preserved_envvars_export_list()
104#bb.utils.filter_environment(exportlist)
105 104
106if taskname.endswith("_setscene"): 105if taskname.endswith("_setscene"):
107 the_data.setVarFlag(taskname, "quieterrors", "1") 106 the_data.setVarFlag(taskname, "quieterrors", "1")
108 107
109bb.parse.siggen.set_taskdata(hashdata["hashes"], hashdata["deps"]) 108if hashdata:
110 109 bb.parse.siggen.set_taskdata(hashdata["hashes"], hashdata["deps"])
111for h in hashdata["hashes"]: 110 for h in hashdata["hashes"]:
112 bb.data.setVar("BBHASH_%s" % h, hashdata["hashes"][h], the_data) 111 bb.data.setVar("BBHASH_%s" % h, hashdata["hashes"][h], the_data)
113for h in hashdata["deps"]: 112 for h in hashdata["deps"]:
114 bb.data.setVar("BBHASHDEPS_%s" % h, hashdata["deps"][h], the_data) 113 bb.data.setVar("BBHASHDEPS_%s" % h, hashdata["deps"][h], the_data)
115 114
116ret = 0 115ret = 0
117if sys.argv[4] != "True": 116if dryrun != "True":
118 ret = bb.build.exec_task(fn, taskname, the_data) 117 ret = bb.build.exec_task(fn, taskname, the_data)
119sys.exit(ret) 118sys.exit(ret)
120 119