summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-07-24 18:20:25 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-08-29 13:56:48 +0100
commit7eb3e45a33e6fdd310ba47375f6a4577614cc9c4 (patch)
tree834060e5554d68c24fda9a63a429cb0a72bb06a7
parent669c07d6022174d01fe5a95b7b0faa9ef86da1e2 (diff)
downloadpoky-7eb3e45a33e6fdd310ba47375f6a4577614cc9c4.tar.gz
bitbake: toasterui: refactor log saving and save out-of-build errors
We refactor log saving to go through only one code path. All logs that happened outside the build (i.e. before build starting) now will be logged to either toaster_ui.log if the build command ran in interactive mode, or to the build request errors if the command ran in managed mode. This enables proper display of error logs in project page. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/ui/buildinfohelper.py79
-rw-r--r--bitbake/lib/bb/ui/toasterui.py10
2 files changed, 51 insertions, 38 deletions
diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index f64423b733..e1ef16d509 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -480,6 +480,8 @@ class ORMWrapper(object):
480 line_number = vh['line'], 480 line_number = vh['line'],
481 operation = vh['op']) 481 operation = vh['op'])
482 482
483class MockEvent: pass # sometimes we mock an event, declare it here
484
483class BuildInfoHelper(object): 485class BuildInfoHelper(object):
484 """ This class gathers the build information from the server and sends it 486 """ This class gathers the build information from the server and sends it
485 towards the ORM wrapper for storing in the database 487 towards the ORM wrapper for storing in the database
@@ -487,6 +489,7 @@ class BuildInfoHelper(object):
487 Keeps in memory all data that needs matching before writing it to the database 489 Keeps in memory all data that needs matching before writing it to the database
488 """ 490 """
489 491
492
490 def __init__(self, server, has_build_history = False): 493 def __init__(self, server, has_build_history = False):
491 self._configure_django() 494 self._configure_django()
492 self.internal_state = {} 495 self.internal_state = {}
@@ -496,6 +499,8 @@ class BuildInfoHelper(object):
496 self.orm_wrapper = ORMWrapper() 499 self.orm_wrapper = ORMWrapper()
497 self.has_build_history = has_build_history 500 self.has_build_history = has_build_history
498 self.tmp_dir = self.server.runCommand(["getVariable", "TMPDIR"])[0] 501 self.tmp_dir = self.server.runCommand(["getVariable", "TMPDIR"])[0]
502 self.brbe = self.server.runCommand(["getVariable", "TOASTER_BRBE"])[0]
503
499 504
500 def _configure_django(self): 505 def _configure_django(self):
501 # Add toaster to sys path for importing modules 506 # Add toaster to sys path for importing modules
@@ -607,9 +612,7 @@ class BuildInfoHelper(object):
607 assert '_pkgs' in vars(event) 612 assert '_pkgs' in vars(event)
608 build_information = self._get_build_information() 613 build_information = self._get_build_information()
609 614
610 brbe = self.server.runCommand(["getVariable", "TOASTER_BRBE"])[0] 615 build_obj = self.orm_wrapper.create_build_object(build_information, self.brbe)
611
612 build_obj = self.orm_wrapper.create_build_object(build_information, brbe)
613 616
614 self.internal_state['build'] = build_obj 617 self.internal_state['build'] = build_obj
615 618
@@ -629,7 +632,8 @@ class BuildInfoHelper(object):
629 # Save build configuration 632 # Save build configuration
630 self.orm_wrapper.save_build_variables(build_obj, self.server.runCommand(["getAllKeysWithFlags", ["doc", "func"]])[0]) 633 self.orm_wrapper.save_build_variables(build_obj, self.server.runCommand(["getAllKeysWithFlags", ["doc", "func"]])[0])
631 634
632 return brbe 635 return self.brbe
636
633 637
634 638
635 def update_target_image_file(self, event): 639 def update_target_image_file(self, event):
@@ -773,7 +777,6 @@ class BuildInfoHelper(object):
773 identifier = fn + taskname + "_setscene" 777 identifier = fn + taskname + "_setscene"
774 recipe_information = self._get_recipe_information_from_taskfile(fn) 778 recipe_information = self._get_recipe_information_from_taskfile(fn)
775 recipe = self.orm_wrapper.get_update_recipe_object(recipe_information) 779 recipe = self.orm_wrapper.get_update_recipe_object(recipe_information)
776 class MockEvent: pass
777 mevent = MockEvent() 780 mevent = MockEvent()
778 mevent.taskname = taskname 781 mevent.taskname = taskname
779 mevent.taskhash = taskhash 782 mevent.taskhash = taskhash
@@ -792,7 +795,6 @@ class BuildInfoHelper(object):
792 identifier = fn + taskname + "_setscene" 795 identifier = fn + taskname + "_setscene"
793 recipe_information = self._get_recipe_information_from_taskfile(fn) 796 recipe_information = self._get_recipe_information_from_taskfile(fn)
794 recipe = self.orm_wrapper.get_update_recipe_object(recipe_information) 797 recipe = self.orm_wrapper.get_update_recipe_object(recipe_information)
795 class MockEvent: pass
796 mevent = MockEvent() 798 mevent = MockEvent()
797 mevent.taskname = taskname 799 mevent.taskname = taskname
798 mevent.taskhash = taskhash 800 mevent.taskhash = taskhash
@@ -929,7 +931,8 @@ class BuildInfoHelper(object):
929 self.internal_state['recipes'], 931 self.internal_state['recipes'],
930 ) 932 )
931 933
932 def store_build_done(self, br_id, be_id): 934 def _store_build_done(self):
935 br_id, be_id = self.brbe.split(":")
933 from bldcontrol.models import BuildEnvironment, BuildRequest 936 from bldcontrol.models import BuildEnvironment, BuildRequest
934 be = BuildEnvironment.objects.get(pk = be_id) 937 be = BuildEnvironment.objects.get(pk = be_id)
935 be.lock = BuildEnvironment.LOCK_LOCK 938 be.lock = BuildEnvironment.LOCK_LOCK
@@ -939,49 +942,61 @@ class BuildInfoHelper(object):
939 br.build = self.internal_state['build'] 942 br.build = self.internal_state['build']
940 br.save() 943 br.save()
941 944
942 def _store_log_information(self, level, text):
943 log_information = {}
944 log_information['build'] = self.internal_state['build']
945 log_information['level'] = level
946 log_information['message'] = text
947 self.orm_wrapper.create_logmessage(log_information)
948
949 def store_log_info(self, text):
950 self._store_log_information(LogMessage.INFO, text)
951
952 def store_log_warn(self, text):
953 self._store_log_information(LogMessage.WARNING, text)
954 945
955 def store_log_error(self, text): 946 def store_log_error(self, text):
956 self._store_log_information(LogMessage.ERROR, text) 947 mockevent = MockEvent()
948 mockevent.levelno = format.ERROR
949 mockevent.msg = text
950 self.store_log_event(mockevent)
957 951
958 def store_log_event(self, event): 952 def store_log_event(self, event):
953 if event.levelno < format.WARNING:
954 return
955
956 if 'args' in vars(event):
957 event.msg = event.msg % event.args
958
959 if not 'build' in self.internal_state:
960 if self.brbe is None:
961 if not 'backlog' in self.internal_state:
962 self.internal_state['backlog'] = []
963 self.internal_state['backlog'].append(event)
964 else: # we're under Toaster control, post the errors to the build request
965 from bldcontrol.models import BuildRequest, BRError
966 br, be = brbe.split(":")
967 buildrequest = BuildRequest.objects.get(pk = br)
968 brerror = BRError.objects.create(req = buildrequest, errtype="build", errmsg = event.msg)
969
970 return
971
959 if 'build' in self.internal_state and 'backlog' in self.internal_state: 972 if 'build' in self.internal_state and 'backlog' in self.internal_state:
960 if len(self.internal_state['backlog']): 973 if len(self.internal_state['backlog']):
961 tempevent = self.internal_state['backlog'].pop() 974 tempevent = self.internal_state['backlog'].pop()
962 print "Saving stored event ", tempevent 975 print " Saving stored event ", tempevent
963 self.store_log_event(tempevent) 976 self.store_log_event(tempevent)
964 else: 977 else:
965 del self.internal_state['backlog'] 978 del self.internal_state['backlog']
966 979
967 if event.levelno < format.WARNING:
968 return
969
970 if not 'build' in self.internal_state:
971 print "Save event for later"
972 if not 'backlog' in self.internal_state:
973 self.internal_state['backlog'] = []
974 self.internal_state['backlog'].append(event)
975
976 return
977 log_information = {} 980 log_information = {}
978 log_information['build'] = self.internal_state['build'] 981 log_information['build'] = self.internal_state['build']
979 if event.levelno >= format.ERROR: 982 if event.levelno >= format.ERROR:
980 log_information['level'] = LogMessage.ERROR 983 log_information['level'] = event.levelno
981 elif event.levelno == format.WARNING: 984 elif event.levelno == format.WARNING:
982 log_information['level'] = LogMessage.WARNING 985 log_information['level'] = LogMessage.WARNING
986 elif event.levelno == format.INFO:
987 log_information['level'] = LogMessage.INFO
988 else:
989 log_information['level'] = event.levelno
990
983 log_information['message'] = event.msg 991 log_information['message'] = event.msg
984 log_information['pathname'] = event.pathname 992 log_information['pathname'] = event.pathname
985 log_information['lineno'] = event.lineno 993 log_information['lineno'] = event.lineno
986 self.orm_wrapper.create_logmessage(log_information) 994 self.orm_wrapper.create_logmessage(log_information)
987 995
996 def close(self):
997 if self.brbe is not None:
998 buildinfohelper._store_build_done()
999
1000 if 'backlog' in self.internal_state:
1001 for event in self.internal_state['backlog']:
1002 print "NOTE: Unsaved log: ", event.msg
diff --git a/bitbake/lib/bb/ui/toasterui.py b/bitbake/lib/bb/ui/toasterui.py
index 2f628e9a72..d81b8a989c 100644
--- a/bitbake/lib/bb/ui/toasterui.py
+++ b/bitbake/lib/bb/ui/toasterui.py
@@ -94,7 +94,6 @@ def main(server, eventHandler, params ):
94 first = True 94 first = True
95 95
96 buildinfohelper = BuildInfoHelper(server, build_history_enabled) 96 buildinfohelper = BuildInfoHelper(server, build_history_enabled)
97 brbe = None
98 97
99 while True: 98 while True:
100 try: 99 try:
@@ -111,7 +110,7 @@ def main(server, eventHandler, params ):
111 helper.eventHandler(event) 110 helper.eventHandler(event)
112 111
113 if isinstance(event, bb.event.BuildStarted): 112 if isinstance(event, bb.event.BuildStarted):
114 brbe = buildinfohelper.store_started_build(event) 113 buildinfohelper.store_started_build(event)
115 114
116 if isinstance(event, (bb.build.TaskStarted, bb.build.TaskSucceeded, bb.build.TaskFailedSilent)): 115 if isinstance(event, (bb.build.TaskStarted, bb.build.TaskSucceeded, bb.build.TaskFailedSilent)):
117 buildinfohelper.update_and_store_task(event) 116 buildinfohelper.update_and_store_task(event)
@@ -222,19 +221,18 @@ def main(server, eventHandler, params ):
222 bb.command.CommandExit)): 221 bb.command.CommandExit)):
223 if (isinstance(event, bb.command.CommandFailed)): 222 if (isinstance(event, bb.command.CommandFailed)):
224 event.levelno = format.ERROR 223 event.levelno = format.ERROR
225 event.msg = event.error 224 event.msg = "Command Failed " + event.error
226 event.pathname = "" 225 event.pathname = ""
227 event.lineno = 0 226 event.lineno = 0
228 buildinfohelper.store_log_event(event) 227 buildinfohelper.store_log_event(event)
229 errors += 1 228 errors += 1
230 229
231 buildinfohelper.update_build_information(event, errors, warnings, taskfailures) 230 buildinfohelper.update_build_information(event, errors, warnings, taskfailures)
231 buildinfohelper.close()
232 232
233 233
234 # we start a new build info 234 # we start a new build info
235 if brbe is not None: 235 if buildinfohelper.brbe is not None:
236 br_id, be_id = brbe.split(":")
237 buildinfohelper.store_build_done(br_id, be_id)
238 236
239 print "we are under BuildEnvironment management - after the build, we exit" 237 print "we are under BuildEnvironment management - after the build, we exit"
240 server.terminateServer() 238 server.terminateServer()