summaryrefslogtreecommitdiffstats
path: root/meta/classes/patch.bbclass
blob: 52630899167238bc668183191b6fc33060d26df6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
From 04a7a672301bb07caea6a7cad8378f63f1fe3200 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Fri, 29 Mar 2013 09:16:28 +0400
Subject: [PATCH 15/47] COLLECT_GCC_OPTIONS

This patch adds --sysroot into COLLECT_GCC_OPTIONS which is used to
invoke collect2.

Signed-off-by: Khem Raj <raj.khem@gmail.com>

Upstream-Status: Pending
---
 gcc/gcc.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/gcc.c b/gcc/gcc.c
index a5fafbe5107..05896e19926 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4654,6 +4654,15 @@ set_collect_gcc_options (void)
 		sizeof ("COLLECT_GCC_OPTIONS=") - 1);
 
   first_time = TRUE;
+#ifdef HAVE_LD_SYSROOT
+  if (target_system_root_changed && target_system_root)
+    {
+      obstack_grow (&collect_obstack, "'--sysroot=", sizeof("'--sysroot=")-1);
+      obstack_grow (&collect_obstack, target_system_root,strlen(target_system_root));
+      obstack_grow (&collect_obstack, "'", 1);
+      first_time = FALSE;
+    }
+#endif
   for (i = 0; (int) i < n_switches; i++)
     {
       const char *const *args;
-- 
2.12.2
394'>394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
# Copyright (C) 2006  OpenedHand LTD

# Point to an empty file so any user's custom settings don't break things
QUILTRCFILE ?= "${STAGING_BINDIR_NATIVE}/quiltrc"

def patch_init(d):
	import os, sys

	def md5sum(fname):
		import md5, sys

		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()

	class CmdError(Exception):
		def __init__(self, exitstatus, output):
			self.status = exitstatus
			self.output = output

		def __str__(self):
			return "Command Error: exit status: %d  Output:\n%s" % (self.status, self.output)

	class NotFoundError(Exception):
		def __init__(self, path):
			self.path = path
		def __str__(self):
			return "Error: %s not found." % self.path

	def runcmd(args, dir = None):
		import commands

		if dir:
			olddir = os.path.abspath(os.curdir)
			if not os.path.exists(dir):
				raise NotFoundError(dir)
			os.chdir(dir)
			# print("cwd: %s -> %s" % (olddir, self.dir))

		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

		finally:
			if dir:
				os.chdir(olddir)

	class PatchError(Exception):
		def __init__(self, msg):
			self.msg = msg

		def __str__(self):
			return "Patch Error: %s" % self.msg

	import bb, bb.data, bb.fetch

	class PatchSet(object):
		defaults = {
			"strippath": 1
		}

		def __init__(self, dir, d):
			self.dir = dir
			self.d = d
			self.patches = []
			self._current = None

		def current(self):
			return self._current

		def Clean(self):
			"""
			Clean out the patch set.  Generally includes unapplying all
			patches and wiping out all associated metadata.
			"""
			raise NotImplementedError()

		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)

			for param in PatchSet.defaults:
				if not patch.get(param):
					patch[param] = PatchSet.defaults[param]

			if patch.get("remote"):
				patch["file"] = bb.data.expand(bb.fetch.localpath(patch["remote"], self.d), self.d)

			patch["filemd5"] = md5sum(patch["file"])

		def Push(self, force):
			raise NotImplementedError()

		def Pop(self, force):
			raise NotImplementedError()

		def Refresh(self, remote = None, all = None):
			raise NotImplementedError()


	class PatchTree(PatchSet):
		def __init__(self, dir, d):
			PatchSet.__init__(self, dir, d)

		def Import(self, patch, force = None):
			""""""
			PatchSet.Import(self, patch, force)

			if self._current is not None:
				i = self._current + 1
			else:
				i = 0
			self.patches.insert(i, patch)

		def _applypatch(self, patch, force = None, reverse = None):
			shellcmd = ["cat", patch['file'], "|", "patch", "-p", patch['strippath']]
			if reverse:
				shellcmd.append('-R')

			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)
			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
					bb.note("applying patch %s" % i)
					self._applypatch(i, force)
			else:
				if self._current is not None:
					self._current = self._current + 1
				else:
					self._current = 0
				bb.note("applying patch %s" % self.patches[self._current])
				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):
			""""""

	class QuiltTree(PatchSet):
		def _runcmd(self, args):
			quiltrc = bb.data.getVar('QUILTRCFILE', self.d, 1)
			runcmd(["quilt"] + ["--quiltrc"] + [quiltrc] + args, self.dir)

		def _quiltpatchpath(self, file):
			return os.path.join(self.dir, "patches", os.path.basename(file))


		def __init__(self, dir, d):
			PatchSet.__init__(self, dir, d)
			self.initialized = False
			p = os.path.join(self.dir, 'patches')
			if not os.path.exists(p):
				os.makedirs(p)

		def Clean(self):
			try:
				self._runcmd(["pop", "-a", "-f"])
			except Exception:
				pass
			self.initialized = True

		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()

				# 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

		def Import(self, patch, force = None):
			if not self.initialized:
				self.InitFromDir()
			PatchSet.Import(self, patch, force)

			args = ["import", "-p", patch["strippath"]]
			if force:
				args.append("-f")
				args.append("-dn")
			args.append(patch["file"])

			self._runcmd(args)

			patch["quiltfile"] = self._quiltpatchpath(patch["file"])
			patch["quiltfilemd5"] = md5sum(patch["quiltfile"])

			# TODO: determine if the file being imported:
			#	   1) is already imported, and is the same
			#	   2) is already imported, but differs

			self.patches.insert(self._current or 0, patch)


		def Push(self, force = None, all = None):
			# quilt push [-f]

			args = ["push"]
			if force:
				args.append("-f")
			if all:
				args.append("-a")

			self._runcmd(args)

			if self._current is not None:
				self._current = self._current + 1
			else:
				self._current = 0

		def Pop(self, force = None, all = None):
			# quilt pop [-f]
			args = ["pop"]
			if force:
				args.append("-f")
			if all:
				args.append("-a")

			self._runcmd(args)

			if self._current == 0:
				self._current = None

			if self._current is not None:
				self._current = self._current - 1

		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)

					shutil.copyfile(patch["quiltfile"], patch["file"])
				else:
					raise PatchError("Unable to do a remote refresh of %s, unsupported remote url scheme %s." % (os.path.basename(patch["quiltfile"]), type))
			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)

	class Resolver(object):
		def __init__(self, patchset):
			raise NotImplementedError()

		def Resolve(self):
			raise NotImplementedError()

		def Revert(self):
			raise NotImplementedError()

		def Finalize(self):
			raise NotImplementedError()

	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

	# 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

		# Force a push in the patchset, then drop to a shell for the user to
		# resolve any rejected hunks
		def Resolve(self):

			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.')
				print('Press CTRL+D to exit.')

				os.system('/bin/sh')

				# 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)
				self.patchset.InitFromDir()

				for patch in self.patchset.patches:
					oldpatch = None
					for opatch in oldpatchset.patches:
						if opatch["quiltfile"] == patch["quiltfile"]:
							oldpatch = opatch

					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)

	g = globals()
	g["PatchSet"] = PatchSet
	g["PatchTree"] = PatchTree
	g["QuiltTree"] = QuiltTree
	g["Resolver"] = Resolver
	g["UserResolver"] = UserResolver
	g["NOOPResolver"] = NOOPResolver
	g["NotFoundError"] = NotFoundError
	g["CmdError"] = CmdError
	g["PatchError"] = PatchError

addtask patch after do_unpack
do_patch[dirs] = "${WORKDIR}"
do_patch[depends] = "${PATCHTOOL}-native:do_populate_staging"

python patch_do_patch() {
	import re
	import bb.fetch

	patch_init(d)

	src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split()
	if not src_uri:
		return

	patchsetmap = {
		"patch": PatchTree,
		"quilt": QuiltTree,
	}

	cls = patchsetmap[bb.data.getVar('PATCHTOOL', d, 1) or 'quilt']

	resolvermap = {
		"noop": NOOPResolver,
		"user": UserResolver,
	}

	rcls = resolvermap[bb.data.getVar('PATCHRESOLVE', d, 1) or 'noop']

	s = bb.data.getVar('S', d, 1)

	path = os.getenv('PATH')
	os.putenv('PATH', bb.data.getVar('PATH', d, 1))
	patchset = cls(s, d)
	patchset.Clean()

	resolver = rcls(patchset)

	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

		bb.fetch.init([url],d)
		url = bb.encodeurl((type, host, path, user, pswd, []))
		local = os.path.join('/', bb.fetch.localpath(url, 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]))
		else:
			unpacked = local
		unpacked = bb.data.expand(unpacked, d)

		if "pnum" in parm:
			pnum = parm["pnum"]
		else:
			pnum = "1"

		if "pname" in parm:
			pname = parm["pname"]
		else:
			pname = os.path.basename(unpacked)

                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)

			if srcdate == "now":
				srcdate = bb.data.getVar('DATE', d, 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 = 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

		bb.note("Applying patch '%s'" % pname)
		try:
			patchset.Import({"file":unpacked, "remote":url, "strippath": pnum}, True)
		except NotFoundError:
			import sys
			raise bb.build.FuncFailed(str(sys.exc_value))
		try:
			resolver.Resolve()
		except PatchError:
			import sys
			raise bb.build.FuncFailed(str(sys.exc_value))
}

EXPORT_FUNCTIONS do_patch