All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bruce Ashfield <bruce.ashfield@gmail.com>
To: Patches and discussions about the oe-core layer
	<openembedded-core@lists.openembedded.org>
Subject: Re: [PATCH] patch.bbclass: abstract out logic that determines patches to apply
Date: Tue, 20 Dec 2011 13:28:49 -0500	[thread overview]
Message-ID: <CADkTA4PQC4K2CsEQQz4TbK2JOU26K3R=XUtjEg_OB-nTTgTyXw@mail.gmail.com> (raw)
In-Reply-To: <4EF0C808.8060609@gmail.com>

On Tue, Dec 20, 2011 at 12:38 PM, Christopher Larson <kergoth@gmail.com> wrote:
> This is needed by the copyleft_compliance class, so it can emit series files
> for the patches, which greatly increases their usefulness to a user trying
> to
> reconstruct the sources outside of OE.

.. or inside! As it turns out, I was writing something very similar to
this to export
patches for processing with the linux-yocto build changes. I was about to send
them out, but this looks drop in or even better.

I'm going to take this for a spin here and see if I can get it working
with my other
changes.

Cheers,

Bruce

>
> Signed-off-by: Christopher Larson <chris_larson@mentor.com>
> ---
>  meta/classes/patch.bbclass |  196
> +++++++++++++++++++++++--------------------
>  1 files changed, 105 insertions(+), 91 deletions(-)
>
> diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
> index ac6c1ce..454d9ce 100644
> --- a/meta/classes/patch.bbclass
> +++ b/meta/classes/patch.bbclass
> @@ -7,13 +7,106 @@ PATCHDEPENDENCY =
> "${PATCHTOOL}-native:do_populate_sysroot"
>  inherit terminal
>  -python patch_do_patch() {
> -       import oe.patch
> +def src_patches(d):
> +       workdir = d.getVar('WORKDIR', True)
> +       fetch = bb.fetch2.Fetch([], d)
> +       patches = []
> +       for url in fetch.urls:
> +               local = patch_path(url, fetch, workdir)
> +               if not local:
> +                       continue
> +
> +               urldata = fetch.ud[url]
> +               parm = urldata.parm
> +               patchname = parm.get('pname') or os.path.basename(local)
> +
> +               apply, reason = should_apply(parm)
> +               if not apply:
> +                       if reason:
> +                               bb.note("Patch %s %s" % (patchname, reason))
> +                       continue
>  -      src_uri = (d.getVar('SRC_URI', 1) or '').split()
> -       if not src_uri:
> +               patchparm = {'patchname': patchname}
> +               if "striplevel" in parm:
> +                       striplevel = parm["striplevel"]
> +               elif "pnum" in parm:
> +                       striplevel = parm["pnum"]
> +               else:
> +                       striplevel = '1'
> +               patchparm['striplevel'] = striplevel
> +
> +               patchdir = parm.get('patchdir')
> +               if patchdir:
> +                       patchparm['patchdir'] = patchdir
> +
> +               localurl = bb.encodeurl(('file', '', local, '', '',
> patchparm))
> +               patches.append(localurl)
> +
> +       return patches
> +
> +def patch_path(url, fetch, workdir):
> +       """Return the local path of a patch, or None if this isn't a
> patch"""
> +
> +       local = fetch.localpath(url)
> +       base, ext = os.path.splitext(os.path.basename(local))
> +       if ext in ('.gz', '.bz2', '.Z'):
> +               local = os.path.join(workdir, base)
> +               ext = os.path.splitext(base)[1]
> +
> +       urldata = fetch.ud[url]
> +       if "apply" in urldata.parm:
> +               apply = oe.types.boolean(urldata.parm["apply"])
> +               if not apply:
> +                       return
> +       elif ext not in (".diff", ".patch"):
>                return
>  +      return local
> +
> +def should_apply(parm):
> +       """Determine if we should apply the given patch"""
> +
> +       if "mindate" in parm or "maxdate" in parm:
> +               pn = d.getVar('PN', 1)
> +               srcdate = d.getVar('SRCDATE_%s' % pn, 1)
> +               if not srcdate:
> +                       srcdate = d.getVar('SRCDATE', 1)
> +
> +               if srcdate == "now":
> +                       srcdate = d.getVar('DATE', 1)
> +
> +               if "maxdate" in parm and parm["maxdate"] < srcdate:
> +                       return False, 'is outdated'
> +
> +               if "mindate" in parm and parm["mindate"] > srcdate:
> +                       return False, 'is predated'
> +
> +
> +       if "minrev" in parm:
> +               srcrev = d.getVar('SRCREV', 1)
> +               if srcrev and srcrev < parm["minrev"]:
> +                       return False, 'applies to later revisions'
> +
> +       if "maxrev" in parm:
> +               srcrev = d.getVar('SRCREV', 1)
> +               if srcrev and srcrev > parm["maxrev"]:
> +                       return False, 'applies to earlier revisions'
> +
> +       if "rev" in parm:
> +               srcrev = d.getVar('SRCREV', 1)
> +               if srcrev and parm["rev"] not in srcrev:
> +                       return False, "doesn't apply to revision"
> +
> +       if "notrev" in parm:
> +               srcrev = d.getVar('SRCREV', 1)
> +               if srcrev and parm["notrev"] in srcrev:
> +                       return False, "doesn't apply to revision"
> +
> +       return True, None
> +
> +python patch_do_patch() {
> +       import oe.patch
> +
>        patchsetmap = {
>                "patch": oe.patch.PatchTree,
>                "quilt": oe.patch.QuiltTree,
> @@ -29,93 +122,15 @@ python patch_do_patch() {
>        rcls = resolvermap[d.getVar('PATCHRESOLVE', 1) or 'user']
>  +      classes = {}
> +
>        s = d.getVar('S', 1)
>        path = os.getenv('PATH')
>        os.putenv('PATH', d.getVar('PATH', 1))
>  -      classes = {}
> -
> -       workdir = d.getVar('WORKDIR', 1)
> -       for url in src_uri:
> -               (type, host, path, user, pswd, parm) = bb.decodeurl(url)
> -
> -               local = None
> -               base, ext = os.path.splitext(os.path.basename(path))
> -               if ext in ('.gz', '.bz2', '.Z'):
> -                       local = os.path.join(workdir, base)
> -                       ext = os.path.splitext(base)[1]
> -
> -               if "apply" in parm:
> -                       apply = parm["apply"]
> -                       if apply != "yes":
> -                               if apply != "no":
> -                                       bb.msg.warn(None, "Unsupported value
> '%s' for 'apply' url param in '%s', please use 'yes' or 'no'" % (apply,
> url))
> -                               continue
> -               #elif "patch" in parm:
> -                       #bb.msg.warn(None, "Deprecated usage of 'patch' url
> param in '%s', please use 'apply={yes,no}'" % url)
> -               elif ext not in (".diff", ".patch"):
> -                       continue
> -
> -               if not local:
> -                       url = bb.encodeurl((type, host, path, user, pswd,
> []))
> -                       local = os.path.join('/', bb.fetch2.localpath(url,
> d))
> -               local = bb.data.expand(local, d)
> -
> -               if "striplevel" in parm:
> -                       striplevel = parm["striplevel"]
> -               elif "pnum" in parm:
> -                       #bb.msg.warn(None, "Deprecated usage of 'pnum' url
> parameter in '%s', please use 'striplevel'" % url)
> -                       striplevel = parm["pnum"]
> -               else:
> -                       striplevel = '1'
> -
> -               if "pname" in parm:
> -                       pname = parm["pname"]
> -               else:
> -                       pname = os.path.basename(local)
> -
> -               if "mindate" in parm or "maxdate" in parm:
> -                       pn = d.getVar('PN', 1)
> -                       srcdate = d.getVar('SRCDATE_%s' % pn, 1)
> -                       if not srcdate:
> -                               srcdate = d.getVar('SRCDATE', 1)
> -
> -                       if srcdate == "now":
> -                               srcdate = d.getVar('DATE', 1)
> -
> -                       if "maxdate" in parm and parm["maxdate"] < srcdate:
> -                               bb.note("Patch '%s' is outdated" % pname)
> -                               continue
> -
> -                       if "mindate" in parm and parm["mindate"] > srcdate:
> -                               bb.note("Patch '%s' is predated" % pname)
> -                               continue
> -
> -
> -               if "minrev" in parm:
> -                       srcrev = d.getVar('SRCREV', 1)
> -                       if srcrev and srcrev < parm["minrev"]:
> -                               bb.note("Patch '%s' applies to later
> revisions" % pname)
> -                               continue
> -
> -               if "maxrev" in parm:
> -                       srcrev = d.getVar('SRCREV', 1)
> -                       if srcrev and srcrev > parm["maxrev"]:
> -                               bb.note("Patch '%s' applies to earlier
> revisions" % pname)
> -                               continue
> -
> -               if "rev" in parm:
> -                       srcrev = d.getVar('SRCREV', 1)
> -                       if srcrev and parm["rev"] not in srcrev:
> -                               bb.note("Patch '%s' doesn't apply to
> revision" % pname)
> -                               continue
> -
> -               if "notrev" in parm:
> -                       srcrev = d.getVar('SRCREV', 1)
> -                       if srcrev and parm["notrev"] in srcrev:
> -                               bb.note("Patch '%s' doesn't apply to
> revision" % pname)
> -                               continue
> +       for patch in src_patches(d):
> +               _, _, local, _, _, parm = bb.decodeurl(patch)
>                if "patchdir" in parm:
>                        patchdir = parm["patchdir"]
> @@ -132,12 +147,11 @@ python patch_do_patch() {
>                else:
>                        patchset, resolver = classes[patchdir]
>  -              bb.note("Applying patch '%s' (%s)" % (pname,
> oe.path.format_display(local, d)))
> +               bb.note("Applying patch '%s' (%s)" % (parm['patchname'],
> oe.path.format_display(local, d)))
>                try:
> -                       patchset.Import({"file":local, "remote":url,
> "strippath": striplevel}, True)
> -               except Exception:
> -                       import sys
> -                       raise bb.build.FuncFailed(str(sys.exc_value))
> +                       patchset.Import({"file":local, "strippath":
> parm['striplevel']}, True)
> +               except Exception as exc:
> +                       bb.fatal(str(exc))
>                resolver.Resolve()
>  }
>  patch_do_patch[vardepsexclude] = "DATE SRCDATE PATCHRESOLVE"
> --
> 1.7.8
>
>
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core



-- 
"Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end"



  reply	other threads:[~2011-12-20 18:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-20 17:38 [PATCH] patch.bbclass: abstract out logic that determines patches to apply Christopher Larson
2011-12-20 18:28 ` Bruce Ashfield [this message]
2011-12-21 17:24 ` Richard Purdie
2011-12-27 17:31   ` Chris Larson
2011-12-27 20:33 ` Saul Wold
2011-12-27 20:38   ` Chris Larson
2011-12-28  3:18     ` Christopher Larson
2012-01-03 23:52       ` Saul Wold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADkTA4PQC4K2CsEQQz4TbK2JOU26K3R=XUtjEg_OB-nTTgTyXw@mail.gmail.com' \
    --to=bruce.ashfield@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.