summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/buildinfohelper.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-17 17:30:34 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-26 09:27:32 +0100
commit70c4eb8d3acaad267ee943ebfba793f9cc1c5ee6 (patch)
tree416f9dcf9c16014e1fc2b975a1de01b286847e25 /bitbake/lib/bb/ui/buildinfohelper.py
parent287b49a35b3f06b302ee199ed4b2d123f1aae58c (diff)
downloadpoky-70c4eb8d3acaad267ee943ebfba793f9cc1c5ee6.tar.gz
bitbake: toaster: refactor build model
We remove the "timespent", "errors_no" and "warnings_no" fields in favor of computing the needed values at runtime. This prevents inconsistencies in the UI. Also removeing all references to BuildRequests from the interface - all build details now display in the build dashboard. Minor fixes related to data logging. (Bitbake rev: 44f37394ed3e4ca02f940be172fe4395b0ee0f7d) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/buildinfohelper.py')
-rw-r--r--bitbake/lib/bb/ui/buildinfohelper.py70
1 files changed, 47 insertions, 23 deletions
diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index 8b63f70a07..63976b57e0 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -16,7 +16,6 @@
16# with this program; if not, write to the Free Software Foundation, Inc., 16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 18
19import datetime
20import sys 19import sys
21import bb 20import bb
22import re 21import re
@@ -24,6 +23,7 @@ import ast
24 23
25os.environ["DJANGO_SETTINGS_MODULE"] = "toaster.toastermain.settings" 24os.environ["DJANGO_SETTINGS_MODULE"] = "toaster.toastermain.settings"
26 25
26from django.utils import timezone
27import toaster.toastermain.settings as toaster_django_settings 27import toaster.toastermain.settings as toaster_django_settings
28from toaster.orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText 28from toaster.orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText
29from toaster.orm.models import Target_Image_File, BuildArtifact 29from toaster.orm.models import Target_Image_File, BuildArtifact
@@ -41,7 +41,7 @@ import logging
41 41
42from django.db import transaction, connection 42from django.db import transaction, connection
43 43
44logger = logging.getLogger("BitBake") 44logger = logging.getLogger("ToasterLogger")
45 45
46 46
47class NotExisting(Exception): 47class NotExisting(Exception):
@@ -135,16 +135,18 @@ class ORMWrapper(object):
135 135
136 if buildrequest is not None: 136 if buildrequest is not None:
137 build = buildrequest.build 137 build = buildrequest.build
138 build.machine=build_info['machine'], 138 logger.info("Updating existing build, with %s" % build_info)
139 build.distro=build_info['distro'], 139 build.machine=build_info['machine']
140 build.distro_version=build_info['distro_version'], 140 build.distro=build_info['distro']
141 build.completed_on=build_info['started_on'], 141 build.distro_version=build_info['distro_version']
142 build.cooker_log_path=build_info['cooker_log_path'], 142 started_on=build_info['started_on']
143 build.build_name=build_info['build_name'], 143 completed_on=build_info['started_on']
144 build.cooker_log_path=build_info['cooker_log_path']
145 build.build_name=build_info['build_name']
144 build.bitbake_version=build_info['bitbake_version'] 146 build.bitbake_version=build_info['bitbake_version']
145 build.save() 147 build.save()
146 148
147 build.target_set.delete() 149 Target.objects.filter(build = build).delete()
148 150
149 else: 151 else:
150 build = Build.objects.create( 152 build = Build.objects.create(
@@ -188,10 +190,7 @@ class ORMWrapper(object):
188 if errors or taskfailures: 190 if errors or taskfailures:
189 outcome = Build.FAILED 191 outcome = Build.FAILED
190 192
191 build.completed_on = datetime.datetime.now() 193 build.completed_on = timezone.now()
192 build.timespent = int((build.completed_on - build.started_on).total_seconds())
193 build.errors_no = errors
194 build.warnings_no = warnings
195 build.outcome = outcome 194 build.outcome = outcome
196 build.save() 195 build.save()
197 196
@@ -687,8 +686,8 @@ class BuildInfoHelper(object):
687 build_info['machine'] = self.server.runCommand(["getVariable", "MACHINE"])[0] 686 build_info['machine'] = self.server.runCommand(["getVariable", "MACHINE"])[0]
688 build_info['distro'] = self.server.runCommand(["getVariable", "DISTRO"])[0] 687 build_info['distro'] = self.server.runCommand(["getVariable", "DISTRO"])[0]
689 build_info['distro_version'] = self.server.runCommand(["getVariable", "DISTRO_VERSION"])[0] 688 build_info['distro_version'] = self.server.runCommand(["getVariable", "DISTRO_VERSION"])[0]
690 build_info['started_on'] = datetime.datetime.now() 689 build_info['started_on'] = timezone.now()
691 build_info['completed_on'] = datetime.datetime.now() 690 build_info['completed_on'] = timezone.now()
692 build_info['cooker_log_path'] = self.server.runCommand(["getVariable", "BB_CONSOLELOG"])[0] 691 build_info['cooker_log_path'] = self.server.runCommand(["getVariable", "BB_CONSOLELOG"])[0]
693 build_info['build_name'] = self.server.runCommand(["getVariable", "BUILDNAME"])[0] 692 build_info['build_name'] = self.server.runCommand(["getVariable", "BUILDNAME"])[0]
694 build_info['bitbake_version'] = self.server.runCommand(["getVariable", "BB_VERSION"])[0] 693 build_info['bitbake_version'] = self.server.runCommand(["getVariable", "BB_VERSION"])[0]
@@ -857,6 +856,30 @@ class BuildInfoHelper(object):
857 856
858 # Save build configuration 857 # Save build configuration
859 data = self.server.runCommand(["getAllKeysWithFlags", ["doc", "func"]])[0] 858 data = self.server.runCommand(["getAllKeysWithFlags", ["doc", "func"]])[0]
859
860 # convert the paths from absolute to relative to either the build directory or layer checkouts
861 path_prefixes = []
862
863 br_id, be_id = self.brbe.split(":")
864 from bldcontrol.models import BuildEnvironment, BuildRequest
865 be = BuildEnvironment.objects.get(pk = be_id)
866 path_prefixes.append(be.builddir)
867
868 for layer in sorted(self.orm_wrapper.layer_version_objects, key = lambda x:len(x.local_path), reverse=True):
869 path_prefixes.append(layer.local_path)
870
871 # we strip the prefixes
872 for k in data:
873 if not bool(data[k]['func']):
874 for vh in data[k]['history']:
875 if not 'documentation.conf' in vh['file']:
876 abs_file_name = vh['file']
877 for pp in path_prefixes:
878 if abs_file_name.startswith(pp + "/"):
879 vh['file']=abs_file_name[len(pp + "/"):]
880 break
881
882 # save the variables
860 self.orm_wrapper.save_build_variables(build_obj, data) 883 self.orm_wrapper.save_build_variables(build_obj, data)
861 884
862 return self.brbe 885 return self.brbe
@@ -1031,7 +1054,7 @@ class BuildInfoHelper(object):
1031 mevent.taskhash = taskhash 1054 mevent.taskhash = taskhash
1032 task_information = self._get_task_information(mevent,recipe) 1055 task_information = self._get_task_information(mevent,recipe)
1033 1056
1034 task_information['start_time'] = datetime.datetime.now() 1057 task_information['start_time'] = timezone.now()
1035 task_information['outcome'] = Task.OUTCOME_NA 1058 task_information['outcome'] = Task.OUTCOME_NA
1036 task_information['sstate_checksum'] = taskhash 1059 task_information['sstate_checksum'] = taskhash
1037 task_information['sstate_result'] = Task.SSTATE_MISS 1060 task_information['sstate_result'] = Task.SSTATE_MISS
@@ -1206,6 +1229,7 @@ class BuildInfoHelper(object):
1206 ) 1229 )
1207 1230
1208 def _store_build_done(self, errorcode): 1231 def _store_build_done(self, errorcode):
1232 logger.info("Build exited with errorcode %d", errorcode)
1209 br_id, be_id = self.brbe.split(":") 1233 br_id, be_id = self.brbe.split(":")
1210 from bldcontrol.models import BuildEnvironment, BuildRequest 1234 from bldcontrol.models import BuildEnvironment, BuildRequest
1211 be = BuildEnvironment.objects.get(pk = be_id) 1235 be = BuildEnvironment.objects.get(pk = be_id)
@@ -1225,7 +1249,7 @@ class BuildInfoHelper(object):
1225 mockevent.levelno = format.ERROR 1249 mockevent.levelno = format.ERROR
1226 mockevent.msg = text 1250 mockevent.msg = text
1227 mockevent.pathname = '-- None' 1251 mockevent.pathname = '-- None'
1228 mockevent.lineno = -1 1252 mockevent.lineno = LogMessage.ERROR
1229 self.store_log_event(mockevent) 1253 self.store_log_event(mockevent)
1230 1254
1231 def store_log_exception(self, text, backtrace = ""): 1255 def store_log_exception(self, text, backtrace = ""):
@@ -1249,13 +1273,12 @@ class BuildInfoHelper(object):
1249 if not 'backlog' in self.internal_state: 1273 if not 'backlog' in self.internal_state:
1250 self.internal_state['backlog'] = [] 1274 self.internal_state['backlog'] = []
1251 self.internal_state['backlog'].append(event) 1275 self.internal_state['backlog'].append(event)
1252 else: # we're under Toaster control, post the errors to the build request 1276 return
1277 else: # we're under Toaster control, the build is already created
1253 from bldcontrol.models import BuildRequest, BRError 1278 from bldcontrol.models import BuildRequest, BRError
1254 br, be = self.brbe.split(":") 1279 br, be = self.brbe.split(":")
1255 buildrequest = BuildRequest.objects.get(pk = br) 1280 buildrequest = BuildRequest.objects.get(pk = br)
1256 brerror = BRError.objects.create(req = buildrequest, errtype="build", errmsg = event.msg) 1281 self.internal_state['build'] = buildrequest.build
1257
1258 return
1259 1282
1260 if 'build' in self.internal_state and 'backlog' in self.internal_state: 1283 if 'build' in self.internal_state and 'backlog' in self.internal_state:
1261 # if we have a backlog of events, do our best to save them here 1284 # if we have a backlog of events, do our best to save them here
@@ -1273,14 +1296,15 @@ class BuildInfoHelper(object):
1273 log_information['level'] = LogMessage.ERROR 1296 log_information['level'] = LogMessage.ERROR
1274 elif event.levelno == format.WARNING: 1297 elif event.levelno == format.WARNING:
1275 log_information['level'] = LogMessage.WARNING 1298 log_information['level'] = LogMessage.WARNING
1276 elif event.levelno == -1: # toaster self-logging 1299 elif event.levelno == -2: # toaster self-logging
1277 log_information['level'] = -1 1300 log_information['level'] = -2
1278 else: 1301 else:
1279 log_information['level'] = LogMessage.INFO 1302 log_information['level'] = LogMessage.INFO
1280 1303
1281 log_information['message'] = event.msg 1304 log_information['message'] = event.msg
1282 log_information['pathname'] = event.pathname 1305 log_information['pathname'] = event.pathname
1283 log_information['lineno'] = event.lineno 1306 log_information['lineno'] = event.lineno
1307 logger.info("Logging error 2: %s" % log_information)
1284 self.orm_wrapper.create_logmessage(log_information) 1308 self.orm_wrapper.create_logmessage(log_information)
1285 1309
1286 def close(self, errorcode): 1310 def close(self, errorcode):