2006-08-28 20:36:36 +00:00
|
|
|
# Copyright (C) 2006 OpenedHand LTD
|
|
|
|
|
2007-04-14 11:07:33 +00:00
|
|
|
# Point to an empty file so any user's custom settings don't break things
|
|
|
|
QUILTRCFILE ?= "${STAGING_BINDIR_NATIVE}/quiltrc"
|
|
|
|
|
2006-08-28 20:36:36 +00:00
|
|
|
def patch_init(d):
|
2006-08-21 00:50:19 +00:00
|
|
|
import os, sys
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def md5sum(fname):
|
|
|
|
import md5, sys
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
f = file(fname, 'rb')
|
|
|
|
m = md5.new()
|
|
|
|
while True:
|
|
|
|
d = f.read(8096)
|
|
|
|
if not d:
|
|
|
|
break
|
|
|
|
m.update(d)
|
|
|
|
f.close()
|
|
|
|
return m.hexdigest()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
class CmdError(Exception):
|
|
|
|
def __init__(self, exitstatus, output):
|
|
|
|
self.status = exitstatus
|
|
|
|
self.output = output
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "Command Error: exit status: %d Output:\n%s" % (self.status, self.output)
|
2006-08-22 08:58:02 +00:00
|
|
|
|
|
|
|
class NotFoundError(Exception):
|
|
|
|
def __init__(self, path):
|
|
|
|
self.path = path
|
|
|
|
def __str__(self):
|
|
|
|
return "Error: %s not found." % self.path
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def runcmd(args, dir = None):
|
|
|
|
import commands
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if dir:
|
|
|
|
olddir = os.path.abspath(os.curdir)
|
2006-08-22 08:58:02 +00:00
|
|
|
if not os.path.exists(dir):
|
|
|
|
raise NotFoundError(dir)
|
2006-08-21 00:50:19 +00:00
|
|
|
os.chdir(dir)
|
|
|
|
# print("cwd: %s -> %s" % (olddir, self.dir))
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
try:
|
|
|
|
args = [ commands.mkarg(str(arg)) for arg in args ]
|
|
|
|
cmd = " ".join(args)
|
|
|
|
# print("cmd: %s" % cmd)
|
|
|
|
(exitstatus, output) = commands.getstatusoutput(cmd)
|
|
|
|
if exitstatus != 0:
|
|
|
|
raise CmdError(exitstatus >> 8, output)
|
|
|
|
return output
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
finally:
|
|
|
|
if dir:
|
|
|
|
os.chdir(olddir)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
class PatchError(Exception):
|
2006-08-23 08:50:26 +00:00
|
|
|
def __init__(self, msg):
|
2006-08-21 00:50:19 +00:00
|
|
|
self.msg = msg
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def __str__(self):
|
2006-08-23 08:50:26 +00:00
|
|
|
return "Patch Error: %s" % self.msg
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
import bb, bb.data, bb.fetch
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
class PatchSet(object):
|
|
|
|
defaults = {
|
|
|
|
"strippath": 1
|
|
|
|
}
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def __init__(self, dir, d):
|
|
|
|
self.dir = dir
|
|
|
|
self.d = d
|
|
|
|
self.patches = []
|
|
|
|
self._current = None
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def current(self):
|
|
|
|
return self._current
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Clean(self):
|
|
|
|
"""
|
|
|
|
Clean out the patch set. Generally includes unapplying all
|
|
|
|
patches and wiping out all associated metadata.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Import(self, patch, force):
|
|
|
|
if not patch.get("file"):
|
|
|
|
if not patch.get("remote"):
|
|
|
|
raise PatchError("Patch file must be specified in patch import.")
|
|
|
|
else:
|
|
|
|
patch["file"] = bb.fetch.localpath(patch["remote"], self.d)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
for param in PatchSet.defaults:
|
|
|
|
if not patch.get(param):
|
|
|
|
patch[param] = PatchSet.defaults[param]
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if patch.get("remote"):
|
2006-08-27 22:29:46 +00:00
|
|
|
patch["file"] = bb.data.expand(bb.fetch.localpath(patch["remote"], self.d), self.d)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
patch["filemd5"] = md5sum(patch["file"])
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Push(self, force):
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Pop(self, force):
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Refresh(self, remote = None, all = None):
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PatchTree(PatchSet):
|
|
|
|
def __init__(self, dir, d):
|
|
|
|
PatchSet.__init__(self, dir, d)
|
|
|
|
|
|
|
|
def Import(self, patch, force = None):
|
|
|
|
""""""
|
|
|
|
PatchSet.Import(self, patch, force)
|
|
|
|
|
2006-09-15 07:54:58 +00:00
|
|
|
if self._current is not None:
|
|
|
|
i = self._current + 1
|
|
|
|
else:
|
|
|
|
i = 0
|
|
|
|
self.patches.insert(i, patch)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
|
|
|
def _applypatch(self, patch, force = None, reverse = None):
|
2006-09-15 07:54:58 +00:00
|
|
|
shellcmd = ["cat", patch['file'], "|", "patch", "-p", patch['strippath']]
|
2006-08-28 20:36:36 +00:00
|
|
|
if reverse:
|
|
|
|
shellcmd.append('-R')
|
|
|
|
|
2006-09-15 07:54:58 +00:00
|
|
|
if not force:
|
|
|
|
shellcmd.append('--dry-run')
|
|
|
|
|
|
|
|
output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
|
|
|
|
|
|
|
|
if force:
|
|
|
|
return
|
|
|
|
|
|
|
|
shellcmd.pop(len(shellcmd) - 1)
|
|
|
|
output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
|
2006-08-28 20:36:36 +00:00
|
|
|
return output
|
|
|
|
|
|
|
|
def Push(self, force = None, all = None):
|
|
|
|
if all:
|
|
|
|
for i in self.patches:
|
|
|
|
if self._current is not None:
|
|
|
|
self._current = self._current + 1
|
|
|
|
else:
|
|
|
|
self._current = 0
|
2006-09-15 07:54:58 +00:00
|
|
|
bb.note("applying patch %s" % i)
|
2006-08-28 20:36:36 +00:00
|
|
|
self._applypatch(i, force)
|
|
|
|
else:
|
|
|
|
if self._current is not None:
|
|
|
|
self._current = self._current + 1
|
|
|
|
else:
|
|
|
|
self._current = 0
|
2006-09-15 07:54:58 +00:00
|
|
|
bb.note("applying patch %s" % self.patches[self._current])
|
2006-08-28 20:36:36 +00:00
|
|
|
self._applypatch(self.patches[self._current], force)
|
|
|
|
|
|
|
|
|
|
|
|
def Pop(self, force = None, all = None):
|
|
|
|
if all:
|
|
|
|
for i in self.patches:
|
|
|
|
self._applypatch(i, force, True)
|
|
|
|
else:
|
|
|
|
self._applypatch(self.patches[self._current], force, True)
|
|
|
|
|
|
|
|
def Clean(self):
|
|
|
|
""""""
|
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
class QuiltTree(PatchSet):
|
|
|
|
def _runcmd(self, args):
|
2007-04-14 11:07:33 +00:00
|
|
|
quiltrc = bb.data.getVar('QUILTRCFILE', self.d, 1)
|
|
|
|
runcmd(["quilt"] + ["--quiltrc"] + [quiltrc] + args, self.dir)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def _quiltpatchpath(self, file):
|
|
|
|
return os.path.join(self.dir, "patches", os.path.basename(file))
|
2006-08-28 20:36:36 +00:00
|
|
|
|
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def __init__(self, dir, d):
|
|
|
|
PatchSet.__init__(self, dir, d)
|
|
|
|
self.initialized = False
|
2006-08-30 07:25:59 +00:00
|
|
|
p = os.path.join(self.dir, 'patches')
|
|
|
|
if not os.path.exists(p):
|
2006-09-01 08:36:17 +00:00
|
|
|
os.makedirs(p)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Clean(self):
|
|
|
|
try:
|
|
|
|
self._runcmd(["pop", "-a", "-f"])
|
2006-09-01 08:36:17 +00:00
|
|
|
except Exception:
|
2006-08-22 08:58:02 +00:00
|
|
|
pass
|
2006-08-21 00:50:19 +00:00
|
|
|
self.initialized = True
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def InitFromDir(self):
|
|
|
|
# read series -> self.patches
|
|
|
|
seriespath = os.path.join(self.dir, 'patches', 'series')
|
|
|
|
if not os.path.exists(self.dir):
|
|
|
|
raise Exception("Error: %s does not exist." % self.dir)
|
|
|
|
if os.path.exists(seriespath):
|
|
|
|
series = file(seriespath, 'r')
|
|
|
|
for line in series.readlines():
|
|
|
|
patch = {}
|
|
|
|
parts = line.strip().split()
|
|
|
|
patch["quiltfile"] = self._quiltpatchpath(parts[0])
|
|
|
|
patch["quiltfilemd5"] = md5sum(patch["quiltfile"])
|
|
|
|
if len(parts) > 1:
|
|
|
|
patch["strippath"] = parts[1][2:]
|
|
|
|
self.patches.append(patch)
|
|
|
|
series.close()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
# determine which patches are applied -> self._current
|
|
|
|
try:
|
|
|
|
output = runcmd(["quilt", "applied"], self.dir)
|
|
|
|
except CmdError:
|
|
|
|
if sys.exc_value.output.strip() == "No patches applied":
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
raise sys.exc_value
|
|
|
|
output = [val for val in output.split('\n') if not val.startswith('#')]
|
|
|
|
for patch in self.patches:
|
|
|
|
if os.path.basename(patch["quiltfile"]) == output[-1]:
|
|
|
|
self._current = self.patches.index(patch)
|
|
|
|
self.initialized = True
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Import(self, patch, force = None):
|
|
|
|
if not self.initialized:
|
|
|
|
self.InitFromDir()
|
|
|
|
PatchSet.Import(self, patch, force)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
args = ["import", "-p", patch["strippath"]]
|
|
|
|
if force:
|
|
|
|
args.append("-f")
|
2007-01-08 21:04:27 +00:00
|
|
|
args.append("-dn")
|
2006-08-21 00:50:19 +00:00
|
|
|
args.append(patch["file"])
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
self._runcmd(args)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
patch["quiltfile"] = self._quiltpatchpath(patch["file"])
|
|
|
|
patch["quiltfilemd5"] = md5sum(patch["quiltfile"])
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
# TODO: determine if the file being imported:
|
|
|
|
# 1) is already imported, and is the same
|
|
|
|
# 2) is already imported, but differs
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
self.patches.insert(self._current or 0, patch)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Push(self, force = None, all = None):
|
|
|
|
# quilt push [-f]
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
args = ["push"]
|
|
|
|
if force:
|
|
|
|
args.append("-f")
|
|
|
|
if all:
|
|
|
|
args.append("-a")
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
self._runcmd(args)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if self._current is not None:
|
|
|
|
self._current = self._current + 1
|
|
|
|
else:
|
|
|
|
self._current = 0
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Pop(self, force = None, all = None):
|
|
|
|
# quilt pop [-f]
|
|
|
|
args = ["pop"]
|
|
|
|
if force:
|
|
|
|
args.append("-f")
|
|
|
|
if all:
|
|
|
|
args.append("-a")
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
self._runcmd(args)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if self._current == 0:
|
|
|
|
self._current = None
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if self._current is not None:
|
|
|
|
self._current = self._current - 1
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Refresh(self, **kwargs):
|
|
|
|
if kwargs.get("remote"):
|
|
|
|
patch = self.patches[kwargs["patch"]]
|
|
|
|
if not patch:
|
|
|
|
raise PatchError("No patch found at index %s in patchset." % kwargs["patch"])
|
|
|
|
(type, host, path, user, pswd, parm) = bb.decodeurl(patch["remote"])
|
|
|
|
if type == "file":
|
|
|
|
import shutil
|
|
|
|
if not patch.get("file") and patch.get("remote"):
|
|
|
|
patch["file"] = bb.fetch.localpath(patch["remote"], self.d)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
shutil.copyfile(patch["quiltfile"], patch["file"])
|
|
|
|
else:
|
2006-08-23 08:50:26 +00:00
|
|
|
raise PatchError("Unable to do a remote refresh of %s, unsupported remote url scheme %s." % (os.path.basename(patch["quiltfile"]), type))
|
2006-08-21 00:50:19 +00:00
|
|
|
else:
|
|
|
|
# quilt refresh
|
|
|
|
args = ["refresh"]
|
|
|
|
if kwargs.get("quiltfile"):
|
|
|
|
args.append(os.path.basename(kwargs["quiltfile"]))
|
|
|
|
elif kwargs.get("patch"):
|
|
|
|
args.append(os.path.basename(self.patches[kwargs["patch"]]["quiltfile"]))
|
|
|
|
self._runcmd(args)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
class Resolver(object):
|
|
|
|
def __init__(self, patchset):
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Resolve(self):
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Revert(self):
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
def Finalize(self):
|
|
|
|
raise NotImplementedError()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-30 07:25:59 +00:00
|
|
|
class NOOPResolver(Resolver):
|
|
|
|
def __init__(self, patchset):
|
|
|
|
self.patchset = patchset
|
|
|
|
|
|
|
|
def Resolve(self):
|
|
|
|
olddir = os.path.abspath(os.curdir)
|
|
|
|
os.chdir(self.patchset.dir)
|
|
|
|
try:
|
|
|
|
self.patchset.Push()
|
|
|
|
except Exception:
|
|
|
|
os.chdir(olddir)
|
|
|
|
raise sys.exc_value
|
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
# Patch resolver which relies on the user doing all the work involved in the
|
|
|
|
# resolution, with the exception of refreshing the remote copy of the patch
|
|
|
|
# files (the urls).
|
|
|
|
class UserResolver(Resolver):
|
|
|
|
def __init__(self, patchset):
|
|
|
|
self.patchset = patchset
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
# Force a push in the patchset, then drop to a shell for the user to
|
|
|
|
# resolve any rejected hunks
|
|
|
|
def Resolve(self):
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
olddir = os.path.abspath(os.curdir)
|
|
|
|
os.chdir(self.patchset.dir)
|
|
|
|
try:
|
|
|
|
self.patchset.Push(True)
|
|
|
|
except CmdError, v:
|
|
|
|
# Patch application failed
|
|
|
|
if sys.exc_value.output.strip() == "No patches applied":
|
|
|
|
return
|
|
|
|
print(sys.exc_value)
|
|
|
|
print('NOTE: dropping user into a shell, so that patch rejects can be fixed manually.')
|
2006-10-25 18:19:39 +00:00
|
|
|
print('Press CTRL+D to exit.')
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
os.system('/bin/sh')
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
# Construct a new PatchSet after the user's changes, compare the
|
|
|
|
# sets, checking patches for modifications, and doing a remote
|
|
|
|
# refresh on each.
|
|
|
|
oldpatchset = self.patchset
|
|
|
|
self.patchset = oldpatchset.__class__(self.patchset.dir, self.patchset.d)
|
2006-10-25 18:19:39 +00:00
|
|
|
self.patchset.InitFromDir()
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
for patch in self.patchset.patches:
|
|
|
|
oldpatch = None
|
|
|
|
for opatch in oldpatchset.patches:
|
|
|
|
if opatch["quiltfile"] == patch["quiltfile"]:
|
|
|
|
oldpatch = opatch
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if oldpatch:
|
|
|
|
patch["remote"] = oldpatch["remote"]
|
|
|
|
if patch["quiltfile"] == oldpatch["quiltfile"]:
|
|
|
|
if patch["quiltfilemd5"] != oldpatch["quiltfilemd5"]:
|
|
|
|
bb.note("Patch %s has changed, updating remote url %s" % (os.path.basename(patch["quiltfile"]), patch["remote"]))
|
|
|
|
# user change? remote refresh
|
|
|
|
self.patchset.Refresh(remote=True, patch=self.patchset.patches.index(patch))
|
|
|
|
else:
|
|
|
|
# User did not fix the problem. Abort.
|
|
|
|
raise PatchError("Patch application failed, and user did not fix and refresh the patch.")
|
|
|
|
except Exception:
|
|
|
|
os.chdir(olddir)
|
|
|
|
raise
|
|
|
|
os.chdir(olddir)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
g = globals()
|
|
|
|
g["PatchSet"] = PatchSet
|
2006-08-28 20:36:36 +00:00
|
|
|
g["PatchTree"] = PatchTree
|
2006-08-21 00:50:19 +00:00
|
|
|
g["QuiltTree"] = QuiltTree
|
|
|
|
g["Resolver"] = Resolver
|
|
|
|
g["UserResolver"] = UserResolver
|
2006-08-30 07:25:59 +00:00
|
|
|
g["NOOPResolver"] = NOOPResolver
|
2006-08-22 08:58:02 +00:00
|
|
|
g["NotFoundError"] = NotFoundError
|
|
|
|
g["CmdError"] = CmdError
|
2006-10-25 18:19:39 +00:00
|
|
|
g["PatchError"] = PatchError
|
2006-08-21 00:50:19 +00:00
|
|
|
|
|
|
|
addtask patch after do_unpack
|
|
|
|
do_patch[dirs] = "${WORKDIR}"
|
2007-04-03 11:31:02 +00:00
|
|
|
do_patch[depends] = "${PATCHTOOL}-native:do_populate_staging"
|
|
|
|
|
2006-08-28 20:36:36 +00:00
|
|
|
python patch_do_patch() {
|
2006-08-21 00:50:19 +00:00
|
|
|
import re
|
|
|
|
import bb.fetch
|
|
|
|
|
2006-08-28 20:36:36 +00:00
|
|
|
patch_init(d)
|
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split()
|
|
|
|
if not src_uri:
|
|
|
|
return
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
patchsetmap = {
|
2006-08-28 20:36:36 +00:00
|
|
|
"patch": PatchTree,
|
2006-08-21 00:50:19 +00:00
|
|
|
"quilt": QuiltTree,
|
|
|
|
}
|
|
|
|
|
|
|
|
cls = patchsetmap[bb.data.getVar('PATCHTOOL', d, 1) or 'quilt']
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
resolvermap = {
|
2006-08-30 07:25:59 +00:00
|
|
|
"noop": NOOPResolver,
|
2006-08-21 00:50:19 +00:00
|
|
|
"user": UserResolver,
|
|
|
|
}
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2007-05-11 11:17:32 +00:00
|
|
|
rcls = resolvermap[bb.data.getVar('PATCHRESOLVE', d, 1) or 'noop']
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
s = bb.data.getVar('S', d, 1)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
|
|
|
path = os.getenv('PATH')
|
|
|
|
os.putenv('PATH', bb.data.getVar('PATH', d, 1))
|
2006-08-21 00:50:19 +00:00
|
|
|
patchset = cls(s, d)
|
|
|
|
patchset.Clean()
|
|
|
|
|
|
|
|
resolver = rcls(patchset)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
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:
|
|
|
|
continue
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
bb.fetch.init([url],d)
|
|
|
|
url = bb.encodeurl((type, host, path, user, pswd, []))
|
|
|
|
local = os.path.join('/', bb.fetch.localpath(url, d))
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
# 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]))
|
|
|
|
else:
|
|
|
|
unpacked = local
|
|
|
|
unpacked = bb.data.expand(unpacked, d)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if "pnum" in parm:
|
|
|
|
pnum = parm["pnum"]
|
|
|
|
else:
|
|
|
|
pnum = "1"
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
if "pname" in parm:
|
|
|
|
pname = parm["pname"]
|
|
|
|
else:
|
|
|
|
pname = os.path.basename(unpacked)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2007-08-03 14:29:07 +00:00
|
|
|
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:
|
|
|
|
srcdate = bb.data.getVar('SRCDATE', d, 1)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2007-08-03 14:29:07 +00:00
|
|
|
if srcdate == "now":
|
|
|
|
srcdate = bb.data.getVar('DATE', d, 1)
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2007-08-03 14:29:07 +00:00
|
|
|
if "maxdate" in parm and parm["maxdate"] < srcdate:
|
2006-08-21 00:50:19 +00:00
|
|
|
bb.note("Patch '%s' is outdated" % pname)
|
2007-08-03 14:29:07 +00:00
|
|
|
continue
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2007-08-03 14:29:07 +00:00
|
|
|
if "mindate" in parm and parm["mindate"] > srcdate:
|
2006-08-21 00:50:19 +00:00
|
|
|
bb.note("Patch '%s' is predated" % pname)
|
2007-08-03 14:29:07 +00:00
|
|
|
continue
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2007-08-03 14:29:07 +00:00
|
|
|
|
|
|
|
if "minrev" in parm:
|
|
|
|
srcrev = bb.data.getVar('SRCREV', d, 1)
|
|
|
|
if srcrev and srcrev < parm["minrev"]:
|
|
|
|
bb.note("Patch '%s' applies to later revisions" % pname)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if "maxrev" in parm:
|
|
|
|
srcrev = bb.data.getVar('SRCREV', d, 1)
|
|
|
|
if srcrev and srcrev > parm["maxrev"]:
|
|
|
|
bb.note("Patch '%s' applies to earlier revisions" % pname)
|
|
|
|
continue
|
2006-08-28 20:36:36 +00:00
|
|
|
|
2006-08-21 00:50:19 +00:00
|
|
|
bb.note("Applying patch '%s'" % pname)
|
2006-08-22 08:58:02 +00:00
|
|
|
try:
|
|
|
|
patchset.Import({"file":unpacked, "remote":url, "strippath": pnum}, True)
|
|
|
|
except NotFoundError:
|
|
|
|
import sys
|
|
|
|
raise bb.build.FuncFailed(str(sys.exc_value))
|
2006-10-25 18:19:39 +00:00
|
|
|
try:
|
|
|
|
resolver.Resolve()
|
|
|
|
except PatchError:
|
|
|
|
import sys
|
|
|
|
raise bb.build.FuncFailed(str(sys.exc_value))
|
2006-08-21 00:50:19 +00:00
|
|
|
}
|
2006-08-28 20:36:36 +00:00
|
|
|
|
|
|
|
EXPORT_FUNCTIONS do_patch
|