patch.bbclass: Merge patch enhancements from OE by Chris Larson

Chris made some interesting changes to the patch handling in OE. Firstly the
patch and pnum parameters have been renamed, to better reflect their function,
to apply and striplevel. The apply parameter now takes either yes or no as its
value.

Therefore a patch line would be changed from:
file://some.patch;patch=1;pnum=2
to:
file://some.patch;apply=yes;striplevel=2

Secondly the apply parameter is inferred if not defined. Entries in SRC_URI
with diff or patch filename extensions will be automatically applied as patches
if the apply parameter is not set to no (or an unknown value).

Note: We have disabled the warnings when using the old style parameters for now

Signed-off-by: Joshua Lock <josh@linux.intel.com>
This commit is contained in:
Joshua Lock 2010-06-01 14:24:13 +01:00
parent 1f2646981f
commit 09536a7592
1 changed files with 35 additions and 22 deletions

View File

@ -6,7 +6,7 @@ QUILTRCFILE ?= "${STAGING_BINDIR_NATIVE}/quiltrc"
PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot"
python patch_do_patch() {
import oe.patch
import oe.patch
src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split()
if not src_uri:
@ -25,7 +25,7 @@ python patch_do_patch() {
"user": oe.patch.UserResolver,
}
rcls = resolvermap[bb.data.getVar('PATCHRESOLVE', d, 1) or 'noop']
rcls = resolvermap[bb.data.getVar('PATCHRESOLVE', d, 1) or 'user']
s = bb.data.getVar('S', d, 1)
@ -39,32 +39,44 @@ python patch_do_patch() {
workdir = bb.data.getVar('WORKDIR', d, 1)
for url in src_uri:
(type, host, path, user, pswd, parm) = bb.decodeurl(url)
if not "patch" in parm:
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
bb.fetch.init([url],d)
url = bb.encodeurl((type, host, path, user, pswd, []))
local = os.path.join('/', bb.fetch.localpath(url, d))
if not local:
bb.fetch.init([url],d)
url = bb.encodeurl((type, host, path, user, pswd, []))
local = os.path.join('/', bb.fetch.localpath(url, d))
local = bb.data.expand(local, d)
# did it need to be unpacked?
dots = os.path.basename(local).split(".")
if dots[-1] in ['gz', 'bz2', 'Z']:
unpacked = os.path.join(bb.data.getVar('WORKDIR', d),'.'.join(dots[0:-1]))
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:
unpacked = local
unpacked = bb.data.expand(unpacked, d)
if "pnum" in parm:
pnum = parm["pnum"]
else:
pnum = "1"
striplevel = '1'
if "pname" in parm:
pname = parm["pname"]
else:
pname = os.path.basename(unpacked)
pname = os.path.basename(local)
if "mindate" in parm or "maxdate" in parm:
if "mindate" in parm or "maxdate" in parm:
pn = bb.data.getVar('PN', d, 1)
srcdate = bb.data.getVar('SRCDATE_%s' % pn, d, 1)
if not srcdate:
@ -106,16 +118,17 @@ python patch_do_patch() {
bb.note("Patch '%s' doesn't apply to revision" % pname)
continue
bb.note("Applying patch '%s'" % pname)
bb.note("Applying patch '%s' (%s)" % (pname, oe.path.format_display(local, d)))
try:
patchset.Import({"file":unpacked, "remote":url, "strippath": pnum}, True)
resolver.Resolve()
patchset.Import({"file":local, "remote":url, "strippath": striplevel}, True)
except Exception:
import sys
raise bb.build.FuncFailed(str(sys.exc_value))
resolver.Resolve()
}
addtask patch after do_unpack
do_patch[dirs] = "${WORKDIR}"
do_patch[depends] = "${PATCHDEPENDENCY}"
EXPORT_FUNCTIONS do_patch