Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 3BA80E00CEC; Tue, 22 Nov 2016 09:56:34 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no * trust * [74.125.83.48 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-pg0-f48.google.com (mail-pg0-f48.google.com [74.125.83.48]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 789B9E00CE0 for ; Tue, 22 Nov 2016 09:56:16 -0800 (PST) Received: by mail-pg0-f48.google.com with SMTP id x23so9851341pgx.1 for ; Tue, 22 Nov 2016 09:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uKOUnVRFqM2fvCe812J0YXis7ARwuxqccMCtD21elb0=; b=wJAph0F+GmzDfi/r1e6SWYq5F64SH6S2wSSldtwbeO2iqlWFShYk5qmWWJs8nadbVy U6zh5+NUYozy2wxwc2/bXjjHI8yCP+uMC/jolZV8uBPDzNNaHex8vbEnBK4+oJRBMQdC 9walab0pStvWbjhTo6Y7h4M+mygS8ykNlp2VvdWvnFRwpELFr1XKuHNhCP0Y2+4xePsZ PF04ZEcG6n9YvWVVO86vy23WZEaeeSlYLf7t3j5Mz0lyKzsEUBqOHSQeahRW7471LTJq TV3Z38GWtqetOoCeShawNMq9sDLiiyvQzVKWpVy3Z+KdZWOLQcbt4eZbhAkkjp3AIFfl qR2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uKOUnVRFqM2fvCe812J0YXis7ARwuxqccMCtD21elb0=; b=U18Pf+assufr4/MXfn+iV5+HuC8SYn3Wl7epAIA78la5TONefjpy1iXAQo9uANKYKZ kBUcA0vU63okp57Z9qAXKT5YMjg2oMPzYJyR3zM0rtjfKOgC1coz7AS+YpN/AG1oPuHN d0nIc1c8wVXp7tBV9yG+JTWBICGEg73KbFBh2iWz7cOoIJrIPptyY0mqIeS0YTLwTF1P FpC9VB4qBYa38H5HJLjBkpbXFE5htKXmbQiAiWSMlyXsh1OhYI8l0LZ951H4Zo8BYj/I ZZW3nfWP7/WVqEcN2Lg+c3lPf/JpNgpJ83aVoUYwmT6Yyo6hTewkr1jia6J4R5OTJdN/ Vj2Q== X-Gm-Message-State: AKaTC02yZgmvEFubL1/Vb01KNXCrEz49MFUquHkkY/9Lt2F2FTAaNBaLWHldYYqjQAZMndNs X-Received: by 10.99.122.92 with SMTP id j28mr46171401pgn.64.1479837375789; Tue, 22 Nov 2016 09:56:15 -0800 (PST) Received: from orion.ger.corp.intel.com ([192.55.54.42]) by smtp.gmail.com with ESMTPSA id y6sm28758504pge.27.2016.11.22.09.56.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Nov 2016 09:56:15 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Tue, 22 Nov 2016 17:55:36 +0000 Message-Id: <1479837338-15969-17-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479837338-15969-1-git-send-email-michael.g.wood@intel.com> References: <1479837338-15969-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 16/18] toaster: buildinfohelper Simplify layer event to toaster layer function X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Nov 2016 17:56:34 -0000 Simplify the layer event information to layer version object in toaster function. Previously this attempted many different methods of trying to obtain the correct layer from toaster by manipulating the data from the event or the data from the known layers to try and match them together. We speed up and simplify this process by making better use of django's orm methods and by working down the most likely matching methods in order of accuracy. [YOCTO #10220] Signed-off-by: Michael Wood --- bitbake/lib/bb/ui/buildinfohelper.py | 69 +++++++++++++++--------------------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py index e96e934..43a1411 100644 --- a/bitbake/lib/bb/ui/buildinfohelper.py +++ b/bitbake/lib/bb/ui/buildinfohelper.py @@ -46,6 +46,8 @@ from orm.models import Project, CustomImagePackage from orm.models import signal_runbuilds from bldcontrol.models import BuildEnvironment, BuildRequest +from bldcontrol.models import BRLayer +from bldcontrol import bbcontroller from bb.msg import BBLogFormatter as formatter from django.db import models @@ -436,48 +438,33 @@ class ORMWrapper(object): else: br_id, be_id = brbe.split(":") - # find layer by checkout path; - from bldcontrol import bbcontroller - bc = bbcontroller.getBuildEnvironmentController(pk = be_id) - - # we might have a race condition here, as the project layers may change between the build trigger and the actual build execution - # but we can only match on the layer name, so the worst thing can happen is a mis-identification of the layer, not a total failure - - # note that this is different - buildrequest = BuildRequest.objects.get(pk = br_id) - for brl in buildrequest.brlayer_set.all(): - if brl.local_source_dir: - localdirname = os.path.join(brl.local_source_dir, - brl.dirpath) - else: - localdirname = os.path.join(bc.getGitCloneDirectory(brl.giturl, brl.commit), brl.dirpath) - # we get a relative path, unless running in HEAD mode where the path is absolute - if not localdirname.startswith("/"): - localdirname = os.path.join(bc.be.sourcedir, localdirname) - #logger.debug(1, "Localdirname %s lcal_path %s" % (localdirname, layer_information['local_path'])) - if localdirname.startswith(layer_information['local_path']): - # If the build request came from toaster this field - # should contain the information from the layer_version - # That created this build request. - if brl.layer_version: - return brl.layer_version - - # This might be a local layer (i.e. no git info) so try - # matching local_source_dir - if brl.local_source_dir and brl.local_source_dir == layer_information["local_path"]: - return brl.layer_version - - # we matched the BRLayer, but we need the layer_version that generated this BR; reverse of the Project.schedule_build() - #logger.debug(1, "Matched %s to BRlayer %s" % (pformat(layer_information["local_path"]), localdirname)) - - for pl in buildrequest.project.projectlayer_set.filter(layercommit__layer__name = brl.name): - if pl.layercommit.layer.vcs_url == brl.giturl : - layer = pl.layercommit.layer - layer.save() - return layer - - raise NotExisting("Unidentified layer %s" % pformat(layer_information)) + # Find the layer version by matching the layer event information + # against the metadata we have in Toaster + try: + br_layer = BRLayer.objects.get(req=br_id, + name=layer_information['name']) + return br_layer.layer_version + except (BRLayer.MultipleObjectsReturned, BRLayer.DoesNotExist): + # There are multiple of the same layer name or the name + # hasn't been determined by the toaster.bbclass layer + # so let's filter by the local_path + bc = bbcontroller.getBuildEnvironmentController(pk=be_id) + for br_layer in BRLayer.objects.filter(req=br_id): + if br_layer.giturl and \ + layer_information['local_path'].endswith( + bc.getGitCloneDirectory(br_layer.giturl, + br_layer.commit)): + return br_layer.layer_version + + if br_layer.local_source_dir == \ + layer_information['local_path']: + return br_layer.layer_version + + # We've reached the end of our search and couldn't find the layer + # we can continue but some data may be missing + raise NotExisting("Unidentified layer %s" % + pformat(layer_information)) def save_target_file_information(self, build_obj, target_obj, filedata): assert isinstance(build_obj, Build) -- 2.7.4