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>
This commit is contained in:
parent
3796541746
commit
f204d16012
|
@ -4,6 +4,10 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
|
||||||
|
from bb import fetch2
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger("BitBake")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
@ -16,13 +20,20 @@ class BBConfiguration(object):
|
||||||
Manages build options and configurations for one run
|
Manages build options and configurations for one run
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, debug, debug_domains):
|
def __init__(self, **options):
|
||||||
setattr(self, "data", {})
|
self.data = {}
|
||||||
setattr(self, "file", [])
|
self.file = []
|
||||||
setattr(self, "cmd", None)
|
self.cmd = None
|
||||||
setattr(self, "dump_signatures", True)
|
self.dump_signatures = True
|
||||||
setattr(self, "debug", debug)
|
self.prefile = []
|
||||||
setattr(self, "debug_domains", debug_domains)
|
self.postfile = []
|
||||||
|
self.parse_only = True
|
||||||
|
|
||||||
|
def __getattr__(self, attribute):
|
||||||
|
try:
|
||||||
|
return super(BBConfiguration, self).__getattribute__(attribute)
|
||||||
|
except AttributeError:
|
||||||
|
return None
|
||||||
|
|
||||||
_warnings_showwarning = warnings.showwarning
|
_warnings_showwarning = warnings.showwarning
|
||||||
def _showwarning(message, category, filename, lineno, file=None, line=None):
|
def _showwarning(message, category, filename, lineno, file=None, line=None):
|
||||||
|
@ -39,82 +50,70 @@ warnings.showwarning = _showwarning
|
||||||
warnings.simplefilter("ignore", DeprecationWarning)
|
warnings.simplefilter("ignore", DeprecationWarning)
|
||||||
|
|
||||||
import bb.event
|
import bb.event
|
||||||
|
|
||||||
# Need to map our I/O correctly. stdout is a pipe to the server expecting
|
|
||||||
# events. We save this and then map stdout to stderr.
|
|
||||||
|
|
||||||
eventfd = os.dup(sys.stdout.fileno())
|
|
||||||
bb.event.worker_pipe = os.fdopen(eventfd, 'w', 0)
|
|
||||||
|
|
||||||
# map stdout to stderr
|
|
||||||
os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
|
|
||||||
|
|
||||||
# Replace those fds with our own
|
|
||||||
#logout = data.expand("${TMPDIR}/log/stdout.%s" % os.getpid(), self.cfgData, True)
|
|
||||||
#mkdirhier(os.path.dirname(logout))
|
|
||||||
#newso = open("/tmp/stdout.%s" % os.getpid(), 'w')
|
|
||||||
#os.dup2(newso.fileno(), sys.stdout.fileno())
|
|
||||||
#os.dup2(newso.fileno(), sys.stderr.fileno())
|
|
||||||
|
|
||||||
# Don't read from stdin from the parent
|
|
||||||
si = file("/dev/null", 'r')
|
|
||||||
os.dup2(si.fileno( ), sys.stdin.fileno( ))
|
|
||||||
|
|
||||||
# We don't want to see signals to our parent, e.g. Ctrl+C
|
|
||||||
os.setpgrp()
|
|
||||||
|
|
||||||
# Save out the PID so that the event can include it the
|
|
||||||
# events
|
|
||||||
bb.event.worker_pid = os.getpid()
|
|
||||||
bb.event.useStdout = False
|
|
||||||
|
|
||||||
hashfile = sys.argv[1]
|
|
||||||
buildfile = sys.argv[2]
|
|
||||||
taskname = sys.argv[3]
|
|
||||||
|
|
||||||
import bb.cooker
|
import bb.cooker
|
||||||
|
|
||||||
p = pickle.Unpickler(file(hashfile, "rb"))
|
buildfile = sys.argv[1]
|
||||||
hashdata = p.load()
|
taskname = sys.argv[2]
|
||||||
|
if len(sys.argv) >= 4:
|
||||||
|
dryrun = sys.argv[3]
|
||||||
|
else:
|
||||||
|
dryrun = False
|
||||||
|
if len(sys.argv) >= 5:
|
||||||
|
hashfile = sys.argv[4]
|
||||||
|
p = pickle.Unpickler(file(hashfile, "rb"))
|
||||||
|
hashdata = p.load()
|
||||||
|
else:
|
||||||
|
hashdata = None
|
||||||
|
|
||||||
debug = hashdata["msg-debug"]
|
handler = bb.event.LogHandler()
|
||||||
debug_domains = hashdata["msg-debug-domains"]
|
logger.addHandler(handler)
|
||||||
verbose = hashdata["verbose"]
|
|
||||||
|
|
||||||
bb.utils.init_logger(bb.msg, verbose, debug, debug_domains)
|
#An example to make debug log messages show up
|
||||||
|
#bb.msg.init_msgconfig(True, 3, [])
|
||||||
|
|
||||||
cooker = bb.cooker.BBCooker(BBConfiguration(debug, debug_domains), None)
|
console = logging.StreamHandler(sys.stdout)
|
||||||
cooker.parseConfiguration()
|
format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
|
||||||
|
bb.msg.addDefaultlogFilter(console)
|
||||||
|
console.setFormatter(format)
|
||||||
|
|
||||||
cooker.bb_cache = bb.cache.init(cooker)
|
def worker_fire(event, d):
|
||||||
cooker.status = bb.cache.CacheData()
|
if isinstance(event, logging.LogRecord):
|
||||||
|
console.handle(event)
|
||||||
|
bb.event.worker_fire = worker_fire
|
||||||
|
bb.event.worker_pid = os.getpid()
|
||||||
|
|
||||||
(fn, cls) = cooker.bb_cache.virtualfn2realfn(buildfile)
|
initialenv = os.environ.copy()
|
||||||
|
config = BBConfiguration()
|
||||||
|
|
||||||
|
def register_idle_function(self, function, data):
|
||||||
|
pass
|
||||||
|
|
||||||
|
cooker = bb.cooker.BBCooker(config, register_idle_function, initialenv)
|
||||||
|
config_data = cooker.configuration.data
|
||||||
|
cooker.status = config_data
|
||||||
|
cooker.handleCollections(bb.data.getVar("BBFILE_COLLECTIONS", config_data, 1))
|
||||||
|
|
||||||
|
fn, cls = bb.cache.Cache.virtualfn2realfn(buildfile)
|
||||||
buildfile = cooker.matchFile(fn)
|
buildfile = cooker.matchFile(fn)
|
||||||
fn = cooker.bb_cache.realfn2virtual(buildfile, cls)
|
fn = bb.cache.Cache.realfn2virtual(buildfile, cls)
|
||||||
|
|
||||||
cooker.buildSetVars()
|
cooker.buildSetVars()
|
||||||
|
|
||||||
# Load data into the cache for fn and parse the loaded cache data
|
# Load data into the cache for fn and parse the loaded cache data
|
||||||
the_data = cooker.bb_cache.loadDataFull(fn, cooker.get_file_appends(fn), cooker.configuration.data)
|
the_data = bb.cache.Cache.loadDataFull(fn, cooker.get_file_appends(fn), cooker.configuration.data)
|
||||||
cooker.bb_cache.setData(fn, buildfile, the_data)
|
|
||||||
cooker.bb_cache.handle_data(fn, cooker.status)
|
|
||||||
|
|
||||||
#exportlist = bb.utils.preserved_envvars_export_list()
|
|
||||||
#bb.utils.filter_environment(exportlist)
|
|
||||||
|
|
||||||
if taskname.endswith("_setscene"):
|
if taskname.endswith("_setscene"):
|
||||||
the_data.setVarFlag(taskname, "quieterrors", "1")
|
the_data.setVarFlag(taskname, "quieterrors", "1")
|
||||||
|
|
||||||
bb.parse.siggen.set_taskdata(hashdata["hashes"], hashdata["deps"])
|
if hashdata:
|
||||||
|
bb.parse.siggen.set_taskdata(hashdata["hashes"], hashdata["deps"])
|
||||||
for h in hashdata["hashes"]:
|
for h in hashdata["hashes"]:
|
||||||
bb.data.setVar("BBHASH_%s" % h, hashdata["hashes"][h], the_data)
|
bb.data.setVar("BBHASH_%s" % h, hashdata["hashes"][h], the_data)
|
||||||
for h in hashdata["deps"]:
|
for h in hashdata["deps"]:
|
||||||
bb.data.setVar("BBHASHDEPS_%s" % h, hashdata["deps"][h], the_data)
|
bb.data.setVar("BBHASHDEPS_%s" % h, hashdata["deps"][h], the_data)
|
||||||
|
|
||||||
ret = 0
|
ret = 0
|
||||||
if sys.argv[4] != "True":
|
if dryrun != "True":
|
||||||
ret = bb.build.exec_task(fn, taskname, the_data)
|
ret = bb.build.exec_task(fn, taskname, the_data)
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue