summaryrefslogtreecommitdiff
path: root/classes/patch.bbclass
diff options
context:
space:
mode:
authorMarcin Juszkiewicz <hrw@openembedded.org>2007-08-09 08:41:19 +0000
committerMarcin Juszkiewicz <hrw@openembedded.org>2007-08-09 08:41:19 +0000
commit9d829ed05c295df608b4fc108eb1c628fd06fd39 (patch)
treec1b27cfe4498f8abef1a61325922906f3e6a32ff /classes/patch.bbclass
parent1434b204e16e87b7f59f074f3036d5dcbcf0116f (diff)
parent6ccac10beeaaa02a86081bd6179fd57c208ad6b1 (diff)
merge of '76e1e69496801009ea0aa69c84f76e858978ab99'
and 'db976a98427dd6a195e2cf167e225de2d0206aea'
Diffstat (limited to 'classes/patch.bbclass')
-rw-r--r--classes/patch.bbclass135
1 files changed, 91 insertions, 44 deletions
diff --git a/classes/patch.bbclass b/classes/patch.bbclass
index 0a7b94cffc..0cc202820f 100644
--- a/classes/patch.bbclass
+++ b/classes/patch.bbclass
@@ -1,12 +1,25 @@
# 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
+ class NotFoundError(Exception):
+ def __init__(self, path):
+ self.path = path
+ def __str__(self):
+ return "Error: %s not found." % self.path
+
def md5sum(fname):
import md5, sys
- f = file(fname, 'rb')
+ try:
+ f = file(fname, 'rb')
+ except IOError:
+ raise NotFoundError(fname)
+
m = md5.new()
while True:
d = f.read(8096)
@@ -24,11 +37,6 @@ def patch_init(d):
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
@@ -123,11 +131,14 @@ def patch_init(d):
i = 0
self.patches.insert(i, patch)
- def _applypatch(self, patch, force = None, reverse = None):
+ def _applypatch(self, patch, force = False, reverse = False, run = True):
shellcmd = ["cat", patch['file'], "|", "patch", "-p", patch['strippath']]
if reverse:
shellcmd.append('-R')
+ if not run:
+ return "sh" + "-c" + " ".join(shellcmd)
+
if not force:
shellcmd.append('--dry-run')
@@ -140,7 +151,7 @@ def patch_init(d):
output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
return output
- def Push(self, force = None, all = None):
+ def Push(self, force = False, all = False, run = True):
bb.note("self._current is %s" % self._current)
bb.note("patches is %s" % self.patches)
if all:
@@ -157,7 +168,7 @@ def patch_init(d):
else:
self._current = 0
bb.note("applying patch %s" % self.patches[self._current])
- self._applypatch(self.patches[self._current], force)
+ return self._applypatch(self.patches[self._current], force)
def Pop(self, force = None, all = None):
@@ -171,8 +182,11 @@ def patch_init(d):
""""""
class QuiltTree(PatchSet):
- def _runcmd(self, args):
- runcmd(["quilt"] + args, self.dir)
+ def _runcmd(self, args, run = True):
+ quiltrc = bb.data.getVar('QUILTRCFILE', self.d, 1)
+ if not run:
+ return ["quilt"] + ["--quiltrc"] + [quiltrc] + args
+ runcmd(["quilt"] + ["--quiltrc"] + [quiltrc] + args, self.dir)
def _quiltpatchpath(self, file):
return os.path.join(self.dir, "patches", os.path.basename(file))
@@ -246,7 +260,7 @@ def patch_init(d):
self.patches.insert(self._current or 0, patch)
- def Push(self, force = None, all = None):
+ def Push(self, force = False, all = False, run = True):
# quilt push [-f]
args = ["push"]
@@ -254,6 +268,8 @@ def patch_init(d):
args.append("-f")
if all:
args.append("-a")
+ if not run:
+ return self._runcmd(args, run)
self._runcmd(args)
@@ -340,16 +356,34 @@ def patch_init(d):
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.')
-
- os.system('/bin/sh')
+ try:
+ self.patchset.Push(False)
+ except CmdError, v:
+ # Patch application failed
+ patchcmd = self.patchset.Push(True, False, False)
+
+ t = bb.data.getVar('T', d, 1)
+ if not t:
+ bb.msg.fatal(bb.msg.domain.Build, "T not set")
+ bb.mkdirhier(t)
+ import random
+ rcfile = "%s/bashrc.%s.%s" % (t, str(os.getpid()), random.random())
+ f = open(rcfile, "w")
+ f.write("echo '*** Manual patch resolution mode ***'\n")
+ f.write("echo 'Dropping to a shell, so patch rejects can be fixed manually.'\n")
+ f.write("echo 'Run \"quilt refresh\" when patch is corrected, press CTRL+D to exit.'\n")
+ f.write("echo ''\n")
+ f.write(" ".join(patchcmd) + "\n")
+ f.write("#" + bb.data.getVar('TERMCMDRUN', d, 1))
+ f.close()
+ os.chmod(rcfile, 0775)
+
+ os.environ['TERMWINDOWTITLE'] = "Bitbake: Please fix patch rejects manually"
+ os.environ['TERMRCFILE'] = rcfile
+ rc = os.system(bb.data.getVar('TERMCMDRUN', d, 1))
+ if os.WIFEXITED(rc) and os.WEXITSTATUS(rc) != 0:
+ bb.msg.fatal(bb.msg.domain.Build, ("Cannot proceed with manual patch resolution - '%s' not found. " \
+ + "Check TERMCMDRUN variable.") % bb.data.getVar('TERMCMDRUN', d, 1))
# Construct a new PatchSet after the user's changes, compare the
# sets, checking patches for modifications, and doing a remote
@@ -390,6 +424,17 @@ def patch_init(d):
addtask patch after do_unpack
do_patch[dirs] = "${WORKDIR}"
+
+python () {
+ import bb
+ # do_patch tasks require PATCHTOOL-native to have staged
+ patchdeps = bb.data.getVar("PATCHTOOL", d, True)
+ if patchdeps:
+ patchdeps = "%s-native" % patchdeps
+ if not patchdeps in bb.data.getVar("PROVIDES", d, True):
+ bb.data.setVarFlag('do_patch', 'depends', patchdeps + ":do_populate_staging", d)
+}
+
python patch_do_patch() {
import re
import bb.fetch
@@ -451,38 +496,40 @@ python patch_do_patch() {
else:
pname = os.path.basename(unpacked)
- if "mindate" in parm:
- mindate = parm["mindate"]
- else:
- mindate = 0
-
- if "maxdate" in parm:
- maxdate = parm["maxdate"]
- else:
- maxdate = "20711226"
-
- 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 "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 srcdate == "now":
+ srcdate = bb.data.getVar('DATE', d, 1)
- if (maxdate < srcdate) or (mindate > srcdate):
- if (maxdate < srcdate):
+ if "maxdate" in parm and parm["maxdate"] < srcdate:
bb.note("Patch '%s' is outdated" % pname)
+ continue
- if (mindate > srcdate):
+ if "mindate" in parm and parm["mindate"] > srcdate:
bb.note("Patch '%s' is predated" % pname)
+ continue
- 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:
+ except:
import sys
raise bb.build.FuncFailed(str(sys.exc_value))
resolver.Resolve()