diff options
Diffstat (limited to 'yocto-poky/bitbake/lib/bb/ui/toasterui.py')
-rw-r--r-- | yocto-poky/bitbake/lib/bb/ui/toasterui.py | 127 |
1 files changed, 97 insertions, 30 deletions
diff --git a/yocto-poky/bitbake/lib/bb/ui/toasterui.py b/yocto-poky/bitbake/lib/bb/ui/toasterui.py index e0c278bb3..3d261503e 100644 --- a/yocto-poky/bitbake/lib/bb/ui/toasterui.py +++ b/yocto-poky/bitbake/lib/bb/ui/toasterui.py @@ -21,6 +21,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from __future__ import division +import time import sys try: import bb @@ -43,8 +44,6 @@ featureSet = [bb.cooker.CookerFeatures.HOB_EXTRA_CACHES, bb.cooker.CookerFeature logger = logging.getLogger("ToasterLogger") interactive = sys.stdout.isatty() - - def _log_settings_from_server(server): # Get values of variables which control our output includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"]) @@ -59,12 +58,56 @@ def _log_settings_from_server(server): if error: logger.error("Unable to get the value of BB_CONSOLELOG variable: %s", error) raise BaseException(error) - return includelogs, loglines, consolelogfile + return consolelogfile + +# create a log file for a single build and direct the logger at it; +# log file name is timestamped to the millisecond (depending +# on system clock accuracy) to ensure it doesn't overlap with +# other log file names +# +# returns (log file, path to log file) for a build +def _open_build_log(log_dir): + format_str = "%(levelname)s: %(message)s" + + now = time.time() + now_ms = int((now - int(now)) * 1000) + time_str = time.strftime('build_%Y%m%d_%H%M%S', time.localtime(now)) + log_file_name = time_str + ('.%d.log' % now_ms) + build_log_file_path = os.path.join(log_dir, log_file_name) + + build_log = logging.FileHandler(build_log_file_path) + + logformat = bb.msg.BBLogFormatter(format_str) + build_log.setFormatter(logformat) + bb.msg.addDefaultlogFilter(build_log) + logger.addHandler(build_log) + + return (build_log, build_log_file_path) + +# stop logging to the build log if it exists +def _close_build_log(build_log): + if build_log: + build_log.flush() + build_log.close() + logger.removeHandler(build_log) + +def main(server, eventHandler, params): + # set to a logging.FileHandler instance when a build starts; + # see _open_build_log() + build_log = None + + # set to the log path when a build starts + build_log_file_path = None -def main(server, eventHandler, params ): helper = uihelper.BBUIHelper() + # TODO don't use log output to determine when bitbake has started + # + # WARNING: this log handler cannot be removed, as localhostbecontroller + # relies on output in the toaster_ui.log file to determine whether + # the bitbake server has started, which only happens if + # this logger is setup here (see the TODO in the loop below) console = logging.StreamHandler(sys.stdout) format_str = "%(levelname)s: %(message)s" formatter = bb.msg.BBLogFormatter(format_str) @@ -73,8 +116,6 @@ def main(server, eventHandler, params ): logger.addHandler(console) logger.setLevel(logging.INFO) - _, _, consolelogfile = _log_settings_from_server(server) - # verify and warn build_history_enabled = True inheritlist, _ = server.runCommand(["getVariable", "INHERIT"]) @@ -87,8 +128,9 @@ def main(server, eventHandler, params ): logger.error("ToasterUI can only work in observer mode") return 1 - + # set to 1 when toasterui needs to shut down main.shutdown = 0 + interrupted = False return_value = 0 errors = 0 @@ -98,25 +140,31 @@ def main(server, eventHandler, params ): buildinfohelper = BuildInfoHelper(server, build_history_enabled) - if buildinfohelper.brbe is not None and consolelogfile: - # if we are under managed mode we have no other UI and we need to write our own file - bb.utils.mkdirhier(os.path.dirname(consolelogfile)) - conlogformat = bb.msg.BBLogFormatter(format_str) - consolelog = logging.FileHandler(consolelogfile) - bb.msg.addDefaultlogFilter(consolelog) - consolelog.setFormatter(conlogformat) - logger.addHandler(consolelog) - + # write our own log files into bitbake's log directory; + # we're only interested in the path to the parent directory of + # this file, as we're writing our own logs into the same directory + consolelogfile = _log_settings_from_server(server) + log_dir = os.path.dirname(consolelogfile) + bb.utils.mkdirhier(log_dir) while True: try: event = eventHandler.waitEvent(0.25) if first: first = False + + # TODO don't use log output to determine when bitbake has started + # + # this is the line localhostbecontroller needs to + # see in toaster_ui.log which it uses to decide whether + # the bitbake server has started... logger.info("ToasterUI waiting for events") if event is None: if main.shutdown > 0: + # if shutting down, close any open build log first + _close_build_log(build_log) + break continue @@ -125,19 +173,32 @@ def main(server, eventHandler, params ): # pylint: disable=protected-access # the code will look into the protected variables of the event; no easy way around this + # we treat ParseStarted as the first event of toaster-triggered + # builds; that way we get the Build Configuration included in the log + # and any errors that occur before BuildStarted is fired + if isinstance(event, bb.event.ParseStarted): + if not (build_log and build_log_file_path): + build_log, build_log_file_path = _open_build_log(log_dir) + continue + if isinstance(event, bb.event.BuildStarted): - buildinfohelper.store_started_build(event, consolelogfile) + # command-line builds don't fire a ParseStarted event, + # so we have to start the log file for those on BuildStarted instead + if not (build_log and build_log_file_path): + build_log, build_log_file_path = _open_build_log(log_dir) + + buildinfohelper.store_started_build(event, build_log_file_path) if isinstance(event, (bb.build.TaskStarted, bb.build.TaskSucceeded, bb.build.TaskFailedSilent)): buildinfohelper.update_and_store_task(event) - logger.warn("Logfile for task %s", event.logfile) + logger.info("Logfile for task %s", event.logfile) continue if isinstance(event, bb.build.TaskBase): logger.info(event._message) if isinstance(event, bb.event.LogExecTTY): - logger.warn(event.msg) + logger.info(event.msg) continue if isinstance(event, logging.LogRecord): @@ -145,10 +206,12 @@ def main(server, eventHandler, params ): event.levelno = formatter.ERROR buildinfohelper.store_log_event(event) + if event.levelno >= formatter.ERROR: errors = errors + 1 elif event.levelno == formatter.WARNING: warnings = warnings + 1 + # For "normal" logging conditions, don't show note logs from tasks # but do show them if the user has changed the default log level to # include verbose/debug messages @@ -169,8 +232,6 @@ def main(server, eventHandler, params ): # timing and error informations from the parsing phase in Toaster if isinstance(event, (bb.event.SanityCheckPassed, bb.event.SanityCheck)): continue - if isinstance(event, bb.event.ParseStarted): - continue if isinstance(event, bb.event.ParseProgress): continue if isinstance(event, bb.event.ParseCompleted): @@ -246,6 +307,12 @@ def main(server, eventHandler, params ): errorcode = 1 logger.error("Command execution failed: %s", event.error) + # turn off logging to the current build log + _close_build_log(build_log) + + # reset ready for next BuildStarted + build_log = None + # update the build info helper on BuildCompleted, not on CommandXXX buildinfohelper.update_build_information(event, errors, warnings, taskfailures) buildinfohelper.close(errorcode) @@ -254,7 +321,6 @@ def main(server, eventHandler, params ): # we start a new build info if buildinfohelper.brbe is not None: - logger.debug("ToasterUI under BuildEnvironment management - exiting after the build") server.terminateServer() else: @@ -296,8 +362,9 @@ def main(server, eventHandler, params ): continue if isinstance(event, bb.cooker.CookerExit): - # exit when the server exits - break + # shutdown when bitbake server shuts down + main.shutdown = 1 + continue # ignore if isinstance(event, (bb.event.BuildBase, @@ -308,14 +375,15 @@ def main(server, eventHandler, params ): bb.event.OperationProgress, bb.command.CommandFailed, bb.command.CommandExit, - bb.command.CommandCompleted)): + bb.command.CommandCompleted, + bb.event.ReachableStamps)): continue if isinstance(event, bb.event.DepTreeGenerated): buildinfohelper.store_dependency_information(event) continue - logger.error("Unknown event: %s", event) + logger.warn("Unknown event: %s", event) return_value += 1 except EnvironmentError as ioerror: @@ -335,7 +403,7 @@ def main(server, eventHandler, params ): if tb is not None: curr = tb while curr is not None: - logger.warn("Error data dump %s\n%s\n" , traceback.format_tb(curr,1), pformat(curr.tb_frame.f_locals)) + logger.error("Error data dump %s\n%s\n" , traceback.format_tb(curr,1), pformat(curr.tb_frame.f_locals)) curr = curr.tb_next # save them to database, if possible; if it fails, we already logged to console. @@ -347,9 +415,8 @@ def main(server, eventHandler, params ): # make sure we return with an error return_value += 1 - if interrupted: - if return_value == 0: - return_value += 1 + if interrupted and return_value == 0: + return_value += 1 logger.warn("Return value is %d", return_value) return return_value |