Record patch application order and use as default sorting

Patches often need to be applied in a specific order. For OE recipes we
were always storing the Patch objects correct order as they are
refreshed every time the recipe itself is refreshed, however for other
distro comparisons, import_otherdistro.py attempts to preserve existing
records, adds new ones and then deletes whatever is left over, which may
result in the order getting messed up over time. To avoid this issue,
record the order next to the patch and set the model meta-info to use
this to sort Patch queries by default.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-02-13 16:32:04 +13:00
parent f9c5143700
commit 975d2927d1
4 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2019-02-13 02:42
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('layerindex', '0026_incfile'),
]
operations = [
migrations.AddField(
model_name='patch',
name='apply_order',
field=models.IntegerField(blank=True, null=True),
),
migrations.AlterModelOptions(
name='patch',
options={'ordering': ['recipe', 'apply_order'], 'verbose_name_plural': 'Patches'},
),
]

View File

@ -559,9 +559,11 @@ class Patch(models.Model):
src_path = models.CharField(max_length=255)
status = models.CharField(max_length=1, choices=PATCH_STATUS_CHOICES, default='U')
status_extra = models.CharField(max_length=255, blank=True)
apply_order = models.IntegerField(blank=True, null=True)
class Meta:
verbose_name_plural = 'Patches'
ordering = ['recipe', 'apply_order']
def vcs_web_url(self):
url = self.recipe.layerbranch.file_url(self.path)

View File

@ -272,7 +272,7 @@ def update_recipe_file(path, recipe, repodir, raiseexceptions=False):
elif key == 'license':
recipe.license = expand(value)
elif key.startswith('patch'):
patches.append(expand(value))
patches.append((int(key[5:] or '0'), expand(value)))
elif key.startswith('source'):
sources.append(expand(value))
@ -280,10 +280,11 @@ def update_recipe_file(path, recipe, repodir, raiseexceptions=False):
recipe.save()
saved_patches = []
for patchfn in patches:
for index, patchfn in patches:
patchpath = os.path.join(os.path.relpath(os.path.dirname(path), repodir), patchfn)
patch, _ = Patch.objects.get_or_create(recipe=recipe, path=patchpath)
patch.src_path = patchfn
patch.apply_order = index
patch.save()
saved_patches.append(patch.id)
recipe.patch_set.exclude(id__in=saved_patches).delete()

View File

@ -56,7 +56,7 @@ def split_recipe_fn(path):
pv = "1.0"
return (pn, pv)
def collect_patch(recipe, patchfn, layerdir_start, stop_on_error):
def collect_patch(recipe, patchfn, index, layerdir_start, stop_on_error):
from django.db import DatabaseError
from layerindex.models import Patch
@ -64,6 +64,7 @@ def collect_patch(recipe, patchfn, layerdir_start, stop_on_error):
patchrec.recipe = recipe
patchrec.path = os.path.relpath(patchfn, layerdir_start)
patchrec.src_path = os.path.relpath(patchrec.path, recipe.filepath)
patchrec.apply_order = index
try:
patchrec.read_status_from_file(patchfn, logger)
patchrec.save()
@ -87,11 +88,11 @@ def collect_patches(recipe, envdata, layerdir_start, stop_on_error):
Patch.objects.filter(recipe=recipe).delete()
patches = oe.recipeutils.get_recipe_patches(envdata)
for patch in patches:
for i, patch in enumerate(patches):
if not patch.startswith(layerdir_start):
# Likely a remote patch, skip it
continue
collect_patch(recipe, patch, layerdir_start, stop_on_error)
collect_patch(recipe, patch, i, layerdir_start, stop_on_error)
def update_recipe_file(tinfoil, data, path, recipe, layerdir_start, repodir, stop_on_error, skip_patches=False):
from django.db import DatabaseError