summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/knotty.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/ui/knotty.py')
-rw-r--r--bitbake/lib/bb/ui/knotty.py91
1 files changed, 73 insertions, 18 deletions
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index 61cf0a37f4..f86999bb09 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -179,7 +179,7 @@ class TerminalFilter(object):
new[3] = new[3] & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSADRAIN, new)
curses.setupterm()
- if curses.tigetnum("colors") > 2:
+ if curses.tigetnum("colors") > 2 and os.environ.get('NO_COLOR', '') == '':
for h in handlers:
try:
h.formatter.enable_color()
@@ -420,6 +420,11 @@ def main(server, eventHandler, params, tf = TerminalFilter):
except bb.BBHandledException:
drain_events_errorhandling(eventHandler)
return 1
+ except Exception as e:
+ # bitbake-server comms failure
+ early_logger = bb.msg.logger_create('bitbake', sys.stdout)
+ early_logger.fatal("Attempting to set server environment: %s", e)
+ return 1
if params.options.quiet == 0:
console_loglevel = loglevel
@@ -585,7 +590,12 @@ def main(server, eventHandler, params, tf = TerminalFilter):
return
llevel, debug_domains = bb.msg.constructLogOptions()
- server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
+ try:
+ server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
+ except (BrokenPipeError, EOFError) as e:
+ # bitbake-server comms failure
+ logger.fatal("Attempting to set event mask: %s", e)
+ return 1
# The logging_tree module is *extremely* helpful in debugging logging
# domains. Uncomment here to dump the logging tree when bitbake starts
@@ -594,7 +604,11 @@ def main(server, eventHandler, params, tf = TerminalFilter):
universe = False
if not params.observe_only:
- params.updateFromServer(server)
+ try:
+ params.updateFromServer(server)
+ except Exception as e:
+ logger.fatal("Fetching command line: %s", e)
+ return 1
cmdline = params.parseActions()
if not cmdline:
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
@@ -605,7 +619,12 @@ def main(server, eventHandler, params, tf = TerminalFilter):
if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]:
universe = True
- ret, error = server.runCommand(cmdline['action'])
+ try:
+ ret, error = server.runCommand(cmdline['action'])
+ except (BrokenPipeError, EOFError) as e:
+ # bitbake-server comms failure
+ logger.fatal("Command '{}' failed: %s".format(cmdline), e)
+ return 1
if error:
logger.error("Command '%s' failed: %s" % (cmdline, error))
return 1
@@ -625,25 +644,38 @@ def main(server, eventHandler, params, tf = TerminalFilter):
printintervaldelta = 10 * 60 # 10 minutes
printinterval = printintervaldelta
- lastprint = time.time()
+ pinginterval = 1 * 60 # 1 minute
+ lastevent = lastprint = time.time()
termfilter = tf(main, helper, console_handlers, params.options.quiet)
atexit.register(termfilter.finish)
- while True:
+ # shutdown levels
+ # 0 - normal operation
+ # 1 - no new task execution, let current running tasks finish
+ # 2 - interrupting currently executing tasks
+ # 3 - we're done, exit
+ while main.shutdown < 3:
try:
if (lastprint + printinterval) <= time.time():
termfilter.keepAlive(printinterval)
printinterval += printintervaldelta
event = eventHandler.waitEvent(0)
if event is None:
- if main.shutdown > 1:
- break
+ if (lastevent + pinginterval) <= time.time():
+ ret, error = server.runCommand(["ping"])
+ if error or not ret:
+ termfilter.clearFooter()
+ print("No reply after pinging server (%s, %s), exiting." % (str(error), str(ret)))
+ return_value = 3
+ main.shutdown = 3
+ lastevent = time.time()
if not parseprogress:
termfilter.updateFooter()
event = eventHandler.waitEvent(0.25)
if event is None:
continue
+ lastevent = time.time()
helper.eventHandler(event)
if isinstance(event, bb.runqueue.runQueueExitWait):
if not main.shutdown:
@@ -748,15 +780,15 @@ def main(server, eventHandler, params, tf = TerminalFilter):
if event.error:
errors = errors + 1
logger.error(str(event))
- main.shutdown = 2
+ main.shutdown = 3
continue
if isinstance(event, bb.command.CommandExit):
if not return_value:
return_value = event.exitcode
- main.shutdown = 2
+ main.shutdown = 3
continue
if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)):
- main.shutdown = 2
+ main.shutdown = 3
continue
if isinstance(event, bb.event.MultipleProviders):
logger.info(str(event))
@@ -841,15 +873,26 @@ def main(server, eventHandler, params, tf = TerminalFilter):
logger.error("Unknown event: %s", event)
+ except (BrokenPipeError, EOFError) as e:
+ # bitbake-server comms failure, don't attempt further comms and exit
+ logger.fatal("Executing event: %s", e)
+ return_value = 1
+ errors = errors + 1
+ main.shutdown = 3
except EnvironmentError as ioerror:
termfilter.clearFooter()
# ignore interrupted io
if ioerror.args[0] == 4:
continue
sys.stderr.write(str(ioerror))
- if not params.observe_only:
- _, error = server.runCommand(["stateForceShutdown"])
main.shutdown = 2
+ if not params.observe_only:
+ try:
+ _, error = server.runCommand(["stateForceShutdown"])
+ except (BrokenPipeError, EOFError) as e:
+ # bitbake-server comms failure, don't attempt further comms and exit
+ logger.fatal("Unable to force shutdown: %s", e)
+ main.shutdown = 3
except KeyboardInterrupt:
termfilter.clearFooter()
if params.observe_only:
@@ -858,9 +901,13 @@ def main(server, eventHandler, params, tf = TerminalFilter):
def state_force_shutdown():
print("\nSecond Keyboard Interrupt, stopping...\n")
- _, error = server.runCommand(["stateForceShutdown"])
- if error:
- logger.error("Unable to cleanly stop: %s" % error)
+ try:
+ _, error = server.runCommand(["stateForceShutdown"])
+ if error:
+ logger.error("Unable to cleanly stop: %s" % error)
+ except (BrokenPipeError, EOFError) as e:
+ # bitbake-server comms failure
+ logger.fatal("Unable to cleanly stop: %s", e)
if not params.observe_only and main.shutdown == 1:
state_force_shutdown()
@@ -873,6 +920,9 @@ def main(server, eventHandler, params, tf = TerminalFilter):
_, error = server.runCommand(["stateShutdown"])
if error:
logger.error("Unable to cleanly shutdown: %s" % error)
+ except (BrokenPipeError, EOFError) as e:
+ # bitbake-server comms failure
+ logger.fatal("Unable to cleanly shutdown: %s", e)
except KeyboardInterrupt:
state_force_shutdown()
@@ -880,9 +930,14 @@ def main(server, eventHandler, params, tf = TerminalFilter):
except Exception as e:
import traceback
sys.stderr.write(traceback.format_exc())
- if not params.observe_only:
- _, error = server.runCommand(["stateForceShutdown"])
main.shutdown = 2
+ if not params.observe_only:
+ try:
+ _, error = server.runCommand(["stateForceShutdown"])
+ except (BrokenPipeError, EOFError) as e:
+ # bitbake-server comms failure, don't attempt further comms and exit
+ logger.fatal("Unable to force shutdown: %s", e)
+ main.shudown = 3
return_value = 1
try:
termfilter.clearFooter()