2008-09-30 15:08:33 +00:00
|
|
|
#
|
|
|
|
# BitBake (No)TTY UI Implementation
|
|
|
|
#
|
|
|
|
# Handling output to TTYs or files (no TTY)
|
|
|
|
#
|
|
|
|
# Copyright (C) 2006-2007 Richard Purdie
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
2010-06-10 17:23:03 +00:00
|
|
|
from __future__ import division
|
2008-09-30 15:08:33 +00:00
|
|
|
|
2010-06-10 17:23:03 +00:00
|
|
|
import os
|
2008-09-30 15:08:33 +00:00
|
|
|
import sys
|
|
|
|
import itertools
|
|
|
|
import xmlrpclib
|
2010-06-10 15:05:52 +00:00
|
|
|
import logging
|
2010-11-19 04:15:07 +00:00
|
|
|
import progressbar
|
2010-12-10 04:38:35 +00:00
|
|
|
import bb.msg
|
2010-01-21 23:49:17 +00:00
|
|
|
from bb import ui
|
|
|
|
from bb.ui import uihelper
|
|
|
|
|
2010-06-10 15:05:52 +00:00
|
|
|
logger = logging.getLogger("BitBake")
|
2010-12-07 04:06:13 +00:00
|
|
|
widgets = [progressbar.Percentage(), ' ', progressbar.Bar(), ' ',
|
|
|
|
progressbar.ETA()]
|
|
|
|
|
|
|
|
class BBProgress(progressbar.ProgressBar):
|
|
|
|
def __init__(self, msg, maxval):
|
|
|
|
self.msg = msg
|
|
|
|
progressbar.ProgressBar.__init__(self, maxval, [self.msg + ": "] + widgets)
|
|
|
|
|
|
|
|
class NonInteractiveProgress(object):
|
|
|
|
fobj = sys.stdout
|
|
|
|
|
|
|
|
def __init__(self, msg, maxval):
|
|
|
|
self.msg = msg
|
|
|
|
self.maxval = maxval
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.fobj.write("%s..." % self.msg)
|
|
|
|
self.fobj.flush()
|
|
|
|
return self
|
|
|
|
|
|
|
|
def update(self, value):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def finish(self):
|
|
|
|
self.fobj.write("done.\n")
|
|
|
|
self.fobj.flush()
|
2008-09-30 15:08:33 +00:00
|
|
|
|
2010-12-09 19:05:22 +00:00
|
|
|
def main(server, eventHandler):
|
2008-09-30 15:08:33 +00:00
|
|
|
|
|
|
|
# Get values of variables which control our output
|
2008-10-23 13:58:36 +00:00
|
|
|
includelogs = server.runCommand(["getVariable", "BBINCLUDELOGS"])
|
|
|
|
loglines = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
|
2008-09-30 15:08:33 +00:00
|
|
|
|
2010-01-21 23:49:17 +00:00
|
|
|
helper = uihelper.BBUIHelper()
|
|
|
|
|
2010-06-10 15:05:52 +00:00
|
|
|
# Set up logging to stdout in our usual format
|
|
|
|
logging.addLevelName(logging.INFO, "NOTE")
|
|
|
|
logging.addLevelName(logging.CRITICAL, "FATAL")
|
|
|
|
|
|
|
|
for level in xrange(logging.INFO - 1, logging.DEBUG + 1, -1):
|
|
|
|
logging.addLevelName(level, logging.getLevelName(logging.INFO))
|
|
|
|
|
|
|
|
for level in xrange(logging.DEBUG - 1, 0, -1):
|
|
|
|
logging.addLevelName(level, logging.getLevelName(logging.DEBUG))
|
|
|
|
|
|
|
|
console = logging.StreamHandler(sys.stdout)
|
2010-12-10 04:38:35 +00:00
|
|
|
format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
|
2010-06-10 15:05:52 +00:00
|
|
|
console.setFormatter(format)
|
|
|
|
logger.addHandler(console)
|
|
|
|
|
2008-09-30 15:08:33 +00:00
|
|
|
try:
|
|
|
|
cmdline = server.runCommand(["getCmdLineAction"])
|
|
|
|
if not cmdline:
|
|
|
|
return 1
|
|
|
|
ret = server.runCommand(cmdline)
|
|
|
|
if ret != True:
|
2010-04-10 02:46:14 +00:00
|
|
|
print("Couldn't get default commandline! %s" % ret)
|
2008-09-30 15:08:33 +00:00
|
|
|
return 1
|
2010-04-12 00:03:55 +00:00
|
|
|
except xmlrpclib.Fault as x:
|
2010-04-10 02:46:14 +00:00
|
|
|
print("XMLRPC Fault getting commandline:\n %s" % x)
|
2008-09-30 15:08:33 +00:00
|
|
|
return 1
|
|
|
|
|
2010-12-07 04:06:13 +00:00
|
|
|
parseprogress = None
|
2010-11-19 05:47:36 +00:00
|
|
|
interactive = os.isatty(sys.stdout.fileno())
|
2008-09-30 15:08:33 +00:00
|
|
|
shutdown = 0
|
|
|
|
return_value = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
event = eventHandler.waitEvent(0.25)
|
|
|
|
if event is None:
|
|
|
|
continue
|
2010-01-21 23:49:17 +00:00
|
|
|
helper.eventHandler(event)
|
|
|
|
if isinstance(event, bb.runqueue.runQueueExitWait):
|
|
|
|
if not shutdown:
|
|
|
|
shutdown = 1
|
|
|
|
if shutdown and helper.needUpdate:
|
|
|
|
activetasks, failedtasks = helper.getTasks()
|
|
|
|
if activetasks:
|
2010-04-10 02:46:14 +00:00
|
|
|
print("Waiting for %s active tasks to finish:" % len(activetasks))
|
2010-12-07 04:58:07 +00:00
|
|
|
for tasknum, task in enumerate(activetasks):
|
2010-04-10 02:46:14 +00:00
|
|
|
print("%s: %s (pid %s)" % (tasknum, activetasks[task]["title"], task))
|
2010-01-21 23:49:17 +00:00
|
|
|
|
2010-06-10 15:05:52 +00:00
|
|
|
if isinstance(event, logging.LogRecord):
|
|
|
|
if event.levelno is logging.CRITICAL or event.levelno is logging.ERROR:
|
|
|
|
return_value = 1
|
|
|
|
if isinstance(event, logging.LogRecord):
|
|
|
|
logger.handle(event)
|
2010-08-20 11:24:13 +00:00
|
|
|
continue
|
2010-06-10 15:05:52 +00:00
|
|
|
|
2010-01-19 14:48:19 +00:00
|
|
|
if isinstance(event, bb.build.TaskFailed):
|
2008-09-30 15:08:33 +00:00
|
|
|
return_value = 1
|
2010-01-19 14:48:19 +00:00
|
|
|
logfile = event.logfile
|
2010-06-10 17:44:20 +00:00
|
|
|
if logfile and os.path.exists(logfile):
|
2010-04-10 02:46:14 +00:00
|
|
|
print("ERROR: Logfile of failure stored in: %s" % logfile)
|
2008-11-07 14:08:11 +00:00
|
|
|
if 1 or includelogs:
|
2010-04-10 02:46:14 +00:00
|
|
|
print("Log data follows:")
|
2008-09-30 15:08:33 +00:00
|
|
|
f = open(logfile, "r")
|
|
|
|
lines = []
|
|
|
|
while True:
|
|
|
|
l = f.readline()
|
|
|
|
if l == '':
|
|
|
|
break
|
|
|
|
l = l.rstrip()
|
|
|
|
if loglines:
|
|
|
|
lines.append(' | %s' % l)
|
|
|
|
if len(lines) > int(loglines):
|
|
|
|
lines.pop(0)
|
|
|
|
else:
|
2010-04-10 02:46:14 +00:00
|
|
|
print('| %s' % l)
|
2008-09-30 15:08:33 +00:00
|
|
|
f.close()
|
|
|
|
if lines:
|
|
|
|
for line in lines:
|
2010-04-10 02:46:14 +00:00
|
|
|
print(line)
|
2010-01-19 14:48:19 +00:00
|
|
|
if isinstance(event, bb.build.TaskBase):
|
2010-06-10 15:05:52 +00:00
|
|
|
logger.info(event._message)
|
2008-09-30 15:08:33 +00:00
|
|
|
continue
|
2010-11-19 05:47:36 +00:00
|
|
|
if isinstance(event, bb.event.ParseStarted):
|
|
|
|
if interactive:
|
2010-12-07 04:06:13 +00:00
|
|
|
progress = BBProgress
|
2010-11-19 05:47:36 +00:00
|
|
|
else:
|
2010-12-07 04:06:13 +00:00
|
|
|
progress = NonInteractiveProgress
|
|
|
|
parseprogress = progress("Parsing recipes", event.total).start()
|
2010-11-19 05:47:36 +00:00
|
|
|
continue
|
2010-01-19 14:48:19 +00:00
|
|
|
if isinstance(event, bb.event.ParseProgress):
|
2010-12-07 04:06:13 +00:00
|
|
|
parseprogress.update(event.current)
|
2010-11-19 05:47:36 +00:00
|
|
|
continue
|
|
|
|
if isinstance(event, bb.event.ParseCompleted):
|
2010-12-07 04:06:13 +00:00
|
|
|
parseprogress.finish()
|
|
|
|
print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors."
|
2010-11-19 05:47:36 +00:00
|
|
|
% ( event.total, event.cached, event.parsed, event.virtuals, event.skipped, event.masked, event.errors)))
|
2008-09-30 15:08:33 +00:00
|
|
|
continue
|
|
|
|
|
2010-12-10 23:53:19 +00:00
|
|
|
if isinstance(event, bb.command.CommandCompleted):
|
2008-09-30 15:08:33 +00:00
|
|
|
break
|
2010-12-10 23:53:19 +00:00
|
|
|
if isinstance(event, bb.command.CommandFailed):
|
2010-01-19 14:48:19 +00:00
|
|
|
return_value = event.exitcode
|
2010-06-10 15:05:52 +00:00
|
|
|
logger.error("Command execution failed: %s" % event.error)
|
2008-09-30 15:08:33 +00:00
|
|
|
break
|
2010-12-10 23:53:19 +00:00
|
|
|
if isinstance(event, bb.command.CommandExit):
|
|
|
|
return_value = event.exitcode
|
|
|
|
continue
|
2010-01-19 14:48:19 +00:00
|
|
|
if isinstance(event, bb.cooker.CookerExit):
|
2008-09-30 15:08:33 +00:00
|
|
|
break
|
2010-06-08 20:20:35 +00:00
|
|
|
if isinstance(event, bb.event.MultipleProviders):
|
2010-06-10 15:05:52 +00:00
|
|
|
logger.info("multiple providers are available for %s%s (%s)", event._is_runtime and "runtime " or "",
|
|
|
|
event._item,
|
|
|
|
", ".join(event._candidates))
|
|
|
|
logger.info("consider defining a PREFERRED_PROVIDER entry to match %s", event._item)
|
2010-06-08 20:20:35 +00:00
|
|
|
continue
|
|
|
|
if isinstance(event, bb.event.NoProvider):
|
|
|
|
if event._runtime:
|
|
|
|
r = "R"
|
|
|
|
else:
|
|
|
|
r = ""
|
|
|
|
|
|
|
|
if event._dependees:
|
2010-06-10 15:05:52 +00:00
|
|
|
logger.error("Nothing %sPROVIDES '%s' (but %s %sDEPENDS on or otherwise requires it)", r, event._item, ", ".join(event._dependees), r)
|
2010-06-08 20:20:35 +00:00
|
|
|
else:
|
2010-06-10 15:05:52 +00:00
|
|
|
logger.error("Nothing %sPROVIDES '%s'", r, event._item)
|
2010-06-08 20:20:35 +00:00
|
|
|
continue
|
2008-09-30 15:08:33 +00:00
|
|
|
|
|
|
|
# ignore
|
2010-06-08 18:42:49 +00:00
|
|
|
if isinstance(event, (bb.event.BuildBase,
|
|
|
|
bb.event.StampUpdate,
|
|
|
|
bb.event.ConfigParsed,
|
|
|
|
bb.event.RecipeParsed,
|
|
|
|
bb.runqueue.runQueueEvent,
|
|
|
|
bb.runqueue.runQueueExitWait)):
|
2009-10-17 19:11:27 +00:00
|
|
|
continue
|
2010-06-08 20:20:35 +00:00
|
|
|
|
2010-06-10 15:05:52 +00:00
|
|
|
logger.error("Unknown event: %s", event)
|
2008-09-30 15:08:33 +00:00
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
if shutdown == 2:
|
2010-04-10 02:46:14 +00:00
|
|
|
print("\nThird Keyboard Interrupt, exit.\n")
|
2008-09-30 15:08:33 +00:00
|
|
|
break
|
|
|
|
if shutdown == 1:
|
2010-04-10 02:46:14 +00:00
|
|
|
print("\nSecond Keyboard Interrupt, stopping...\n")
|
2008-09-30 15:08:33 +00:00
|
|
|
server.runCommand(["stateStop"])
|
|
|
|
if shutdown == 0:
|
2010-04-10 02:46:14 +00:00
|
|
|
print("\nKeyboard Interrupt, closing down...\n")
|
2008-09-30 15:08:33 +00:00
|
|
|
server.runCommand(["stateShutdown"])
|
|
|
|
shutdown = shutdown + 1
|
|
|
|
pass
|
|
|
|
return return_value
|