Patchwork patch.bbclass: abstract out logic that determines patches to apply

login
register
mail settings
Submitter Christopher Larson
Date Dec. 20, 2011, 5:38 p.m.
Message ID <4EF0C808.8060609@gmail.com>
Download mbox | patch
Permalink /patch/17321/
State New
Headers show

Comments

Christopher Larson - Dec. 20, 2011, 5:38 p.m.
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.

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
---
  meta/classes/patch.bbclass |  196 
+++++++++++++++++++++++--------------------
  1 files changed, 105 insertions(+), 91 deletions(-)

  +	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"
Bruce Ashfield - Dec. 20, 2011, 6:28 p.m.
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
Richard Purdie - Dec. 21, 2011, 5:24 p.m.
On Tue, 2011-12-20 at 10:38 -0700, Christopher Larson 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.
> 
> Signed-off-by: Christopher Larson <chris_larson@mentor.com>
> ---
>   meta/classes/patch.bbclass |  196 
> +++++++++++++++++++++++--------------------
>   1 files changed, 105 insertions(+), 91 deletions(-)

I have no objection to the change but the patch seems to be mangled
somehow. Could you resend it or point me at a git tree please?

Cheers,

Richard
Christopher Larson - Dec. 27, 2011, 5:31 p.m.
On Wed, Dec 21, 2011 at 10:24 AM, Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
> On Tue, 2011-12-20 at 10:38 -0700, Christopher Larson 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.
>>
>> Signed-off-by: Christopher Larson <chris_larson@mentor.com>
>> ---
>>   meta/classes/patch.bbclass |  196
>> +++++++++++++++++++++++--------------------
>>   1 files changed, 105 insertions(+), 91 deletions(-)
>
> I have no objection to the change but the patch seems to be mangled
> somehow. Could you resend it or point me at a git tree please?

Sorry about that, my git send-email isn't working on my main dev
machine at the moment, strange error from git that no one seems to
recognize. used imap-send, and apparently tbird defaults to wrapping
the same way the gmail UI does *eyeroll*. See
https://github.com/kergoth/oe-core/compare/patch-refactor
Saul Wold - Dec. 27, 2011, 8:33 p.m.
On 12/20/2011 09:38 AM, Christopher Larson 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.
>
> 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):

Do you need to pass d here?

I am seeing errors (see 
http://autobuilder.yoctoproject.org:8010/builders/nightly-x86/builds/295/steps/shell_14/logs/stdio)

Sau!

> + """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"
Christopher Larson - Dec. 27, 2011, 8:38 p.m.
On Tue, Dec 27, 2011 at 1:33 PM, Saul Wold <sgw@linux.intel.com> wrote:
> Do you need to pass d here?
>
> I am seeing errors (see
> http://autobuilder.yoctoproject.org:8010/builders/nightly-x86/builds/295/steps/shell_14/logs/stdio)

Bah, indeed, apparently my testing didn't hit any recipes using
minrev/maxrev/notrev. Will rework the patch. Grr.
Christopher Larson - Dec. 28, 2011, 3:18 a.m.
Pushed an updated version of the patch-refactor commit that should fix this.
Saul Wold - Jan. 3, 2012, 11:52 p.m.
On 12/27/2011 07:18 PM, Christopher Larson wrote:
> Pushed an updated version of the patch-refactor commit that should fix this.
> --
> Christopher Larson
>
> On Tuesday, December 27, 2011 at 1:38 PM, Chris Larson wrote:
>
>> On Tue, Dec 27, 2011 at 1:33 PM, Saul Wold <sgw@linux.intel.com
>> <mailto:sgw@linux.intel.com>> wrote:
>>> Do you need to pass d here?
>>>
>>> I am seeing errors (see
>>> http://autobuilder.yoctoproject.org:8010/builders/nightly-x86/builds/295/steps/shell_14/logs/stdio)
>>
>> Bah, indeed, apparently my testing didn't hit any recipes using
>> minrev/maxrev/notrev. Will rework the patch. Grr.

Merged the Updated version to OE-Core

Thanks
	Sau!

Patch

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']