Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 8C69AE00BE2; Tue, 8 Dec 2015 13:17:39 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.220.51 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-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 100E7E00BAA for ; Tue, 8 Dec 2015 13:17:04 -0800 (PST) Received: by pacej9 with SMTP id ej9so17862680pac.2 for ; Tue, 08 Dec 2015 13:17:04 -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=G3BFqnsqhcmfxJbJIytOjSoDqMpu6gdr9l+dhQEaySI=; b=noQSd0TCcvrsmBzWbdN3lobsn7IriYiFHQgsufYuSwBRgud4WRiAWhs7+Ptc6shcdc rsoST8T7vbscQekPnBeLp9fDZuyZDueP/e2vmAjM8yEPlRQS0siM7iM+GWTYklGS8raj oUI4f5SCWcW3xCu3AFTGQQiCoaTgstGeRVCKaDa1QgUm2n11KPRO1f1V58bkKzdcZ/Ey FkwlNGVwmd5hoEcFeoTwcDyMzYKB9afX+YqHrKM1jtSt2gXzy4seck0oL3Y4m2RBt0F0 H1p6qD5kOihWGaX6dAH1eOg2SXUU+fPn6UMvxVeQAC5ShonBatA6VlAAZs60WfBCQ82P 1UHw== 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=G3BFqnsqhcmfxJbJIytOjSoDqMpu6gdr9l+dhQEaySI=; b=kifmVj0ieVRaWGQR9MAS13ctHy2VyagRbeN56BbLQD9ug4lHC0wsU2WqgVOXfIOn+M PUqSS3lhLbD9HR5W1xl98ao/0XtgilFUIUA3EhBrNKqJXXGz3zwZYIReIFbZQ+/o5GqI QeDUR5bMgorbX/0iGUohRIC53e1npCQ9NlSBsDw/xraM+SaAOlEaM/nsXv/pPl6m+anr +IlPLbEqHJ5pbpY+jMI6LynvI+qUw8IrLAikdRiUc+xrn3h/Vw1eypl1vZu5q7ZvQStF QhavpVa/bmEBmqoPzqL9sm24BQYCEYtwUiFMetHAKq8e+e6+Kwl3kQ56HtamcYd6Ip+J 8RAw== X-Gm-Message-State: ALoCoQmijuHuPmpWjxvdrc6LfJoahO82aNd6XToEdnf7J3LMNWdQoXp8sZV8d63THd0vD/OrDPCXVcT1FHUp2VwIU6CVENXttw== X-Received: by 10.66.142.232 with SMTP id rz8mr3030806pab.74.1449609424493; Tue, 08 Dec 2015 13:17:04 -0800 (PST) Received: from draco.ger.corp.intel.com ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id v64sm6675766pfi.50.2015.12.08.13.17.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Dec 2015 13:17:03 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Tue, 8 Dec 2015 21:15:58 +0000 Message-Id: <1449609380-11073-13-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1449609380-11073-1-git-send-email-michael.g.wood@intel.com> References: <1449609380-11073-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 12/34] toaster: move CustomImageRecipe generation to API entry point 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, 08 Dec 2015 21:17:39 -0000 Use the CustomImageRecipe generate_recipe_file_contents to generate the recipe that we build from. Move creation of the dummy layer and recipe object to the point of recipe creation as we need these objects before the build time. Also update the methods to add and remove packages to account for the CustomImageRecipe inheriting from Recipe. Signed-off-by: Michael Wood --- .../toaster/bldcontrol/localhostbecontroller.py | 29 ++++--- bitbake/lib/toaster/toastergui/views.py | 90 ++++++++++++++++++---- 2 files changed, 90 insertions(+), 29 deletions(-) diff --git a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py index 81b773e..508efd4 100644 --- a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py +++ b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py @@ -241,23 +241,22 @@ class LocalhostBEController(BuildEnvironmentController): conf.write('BBPATH .= ":${LAYERDIR}"\nBBFILES += "${LAYERDIR}/recipes/*.bb"\n') # create recipe - recipe = os.path.join(layerpath, "recipes", "%s.bb" % target.target) - with open(recipe, "w") as recipef: - recipef.write("require %s\n" % customrecipe.base_recipe.file_path) - packages = [pkg.name for pkg in customrecipe.packages.all()] - if packages: - recipef.write('IMAGE_INSTALL = "%s"\n' % ' '.join(packages)) + recipe_path = \ + os.path.join(layerpath, "recipes", "%s.bb" % target.target) + with open(recipe_path, "w") as recipef: + recipef.write(customrecipe.generate_recipe_file_contents()) + + # Update the layer and recipe objects + customrecipe.layer_version.dirpath = layerpath + customrecipe.layer_version.save() + + customrecipe.file_path = recipe_path + customrecipe.save() # create *Layer* objects needed for build machinery to work - layer = Layer.objects.get_or_create(name="Toaster Custom layer", - summary="Layer for custom recipes", - vcs_url="file://%s" % layerpath)[0] - breq = target.req - lver = Layer_Version.objects.get_or_create(project=breq.project, layer=layer, - dirpath=layerpath, build=breq.build)[0] - ProjectLayer.objects.get_or_create(project=breq.project, layercommit=lver, - optional=False) - BRLayer.objects.get_or_create(req=breq, name=layer.name, dirpath=layerpath, + BRLayer.objects.get_or_create(req=target.req, + name=layer.name, + dirpath=layerpath, giturl="file://%s" % layerpath) if os.path.isdir(layerpath): layerlist.append(layerpath) diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 243bb09..45fb055 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2649,10 +2649,37 @@ if True: # create custom recipe try: + # create layer 'Custom layer' and verion if needed + layer = Layer.objects.get_or_create(name="toaster-custom-images", + summary="Layer for custom recipes", + vcs_url="file:///toaster_created_layer" + )[0] + + lver = Layer_Version.objects.get_or_create( + project=params['project'], + layer=layer, + dirpath='toaster_created_layer', + build=None)[0] + + # Add a dependency on our layer to the base recipe's layer + LayerVersionDependency.objects.get_or_create(layer_version=lver, + depends_on=params["base"].layer_version) + + # Add it to our current project if needed + ProjectLayer.objects.get_or_create(project=params['project'], + layercommit=lver, + optional=False) + + # Create the actual recipe recipe = CustomImageRecipe.objects.create( name=request.POST["name"], base_recipe=params["base"], - project=params["project"]) + project=params["project"], + file_path=request.POST["name"], + license="MIT", + version="0.1", + layer_version=lver) + except Error as err: return {"error": "Can't create custom recipe: %s" % err} @@ -2665,20 +2692,24 @@ if True: # We don't want these packages to be linked to anything because # that underlying data may change e.g. delete a build for package in build.package_set.all(): - # Create the duplicate - package.pk = None - package.save() - # Disassociate the package from the build - package.build = None - package.save() - recipe.packages.add(package) + _copy_packge_to_recipe(recipe, package) else: - logger.warn("No packages found for this base recipe") + logger.debug("No packages found for this base recipe") return {"error": "ok", "url": reverse('customrecipe', args=(params['project'].pk, recipe.id))} + def _copy_packge_to_recipe(recipe, package): + """ copy a package from another recipe """ + package.pk = None + package.save() + # Disassociate the package from the build + package.build = None + package.recipe = recipe + package.save() + return package + @xhr_response def xhr_customrecipe_id(request, recipe_id): """ @@ -2741,8 +2772,12 @@ if True: "not found" % recipe_id} if request.method == 'GET' and not package_id: + packages = recipe.package_set.values("id", "name", "version") + return {"error": "ok", - "packages": list(recipe.packages.values_list('id'))} + "packages" : list(packages), + "total" : len(packages) + } try: package = Package.objects.get(id=package_id) @@ -2751,11 +2786,38 @@ if True: "not found" % package_id} if request.method == 'PUT': - recipe.packages.add(package) - return {"error": "ok"} + # As these requests are asynchronous we need to make sure we don't + # already have the package in the image recipe + if recipe.package_set.filter(Q(name=package.name) & + Q(version=package.version)).count() > 0: + return {"error" : "Package %s already in recipe" % + package.name } + + # Make a copy of this package + dependencies = _get_package_dependencies(package.pk) + + package = _copy_packge_to_recipe(recipe, package) + recipe.package_set.add(package) + + # Filter out dependencies already in the custom image + all_in_image = recipe.package_set.all().values_list('name', + flat=True) + def in_image(pkg): + return pkg['name'] not in all_in_image + + dependencies = filter(in_image, dependencies['runtime_deps']) + return {"error": "ok", + "new_package" : {"id": package.pk, + "url": reverse('xhr_customrecipe_packages', + args=(recipe.pk, package.pk)) + }, + "dependencies_needed" : dependencies, + } + elif request.method == 'DELETE': - if package in recipe.packages.all(): - recipe.packages.remove(package) + if package in recipe.package_set.all(): + # note that we are infact deleting the copy of the package + package.delete() return {"error": "ok"} else: return {"error": "Package '%s' is not in the recipe '%s'" % \ -- 2.1.4