Update drivers
[vuplus_openembedded] / classes / patch.bbclass
index 12657fa..33184df 100644 (file)
@@ -1,8 +1,9 @@
 # Copyright (C) 2006  OpenedHand LTD
 
-def patch_init(d):
-       import os, sys
+# Point to an empty file so any user's custom settings don't break things
+QUILTRCFILE ?= "${STAGING_BINDIR_NATIVE}/quiltrc"
 
+def patch_init(d):
        class NotFoundError(Exception):
                def __init__(self, path):
                        self.path = path
@@ -10,14 +11,20 @@ def patch_init(d):
                        return "Error: %s not found." % self.path
 
        def md5sum(fname):
-               import md5, sys
+               # when we move to Python 2.5 as minimal supported
+               # we can kill that try/except as hashlib is 2.5+
+               try:
+                       import hashlib
+                       m = hashlib.md5()
+               except ImportError:
+                       import md5
+                       m = md5.new()
 
                try:
                        f = file(fname, 'rb')
                except IOError:
                        raise NotFoundError(fname)
 
-               m = md5.new()
                while True:
                        d = f.read(8096)
                        if not d:
@@ -65,8 +72,6 @@ def patch_init(d):
                def __str__(self):
                        return "Patch Error: %s" % self.msg
 
-       import bb, bb.data, bb.fetch
-
        class PatchSet(object):
                defaults = {
                        "strippath": 1
@@ -178,11 +183,30 @@ def patch_init(d):
                def Clean(self):
                        """"""
 
+       class GitApplyTree(PatchTree):
+               def __init__(self, dir, d):
+                       PatchTree.__init__(self, dir, d)
+
+               def _applypatch(self, patch, force = False, reverse = False, run = True):
+                       shellcmd = ["git", "--git-dir=.", "apply", "-p%s" % patch['strippath']]
+
+                       if reverse:
+                               shellcmd.append('-R')
+
+                       shellcmd.append(patch['file'])
+
+                       if not run:
+                               return "sh" + "-c" + " ".join(shellcmd)
+
+                       return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+
+
        class QuiltTree(PatchSet):
                def _runcmd(self, args, run = True):
+                       quiltrc = bb.data.getVar('QUILTRCFILE', self.d, 1)
                        if not run:
-                               return ["quilt"] + args
-                       runcmd(["quilt"] + args, self.dir)
+                               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))
@@ -223,6 +247,7 @@ def patch_init(d):
                                try:
                                        output = runcmd(["quilt", "applied"], self.dir)
                                except CmdError:
+                                       import sys
                                        if sys.exc_value.output.strip() == "No patches applied":
                                                return
                                        else:
@@ -336,6 +361,7 @@ def patch_init(d):
                        try:
                                self.patchset.Push()
                        except Exception:
+                               import sys
                                os.chdir(olddir)
                                raise sys.exc_value
 
@@ -412,6 +438,7 @@ def patch_init(d):
        g["PatchSet"] = PatchSet
        g["PatchTree"] = PatchTree
        g["QuiltTree"] = QuiltTree
+       g["GitApplyTree"] = GitApplyTree
        g["Resolver"] = Resolver
        g["UserResolver"] = UserResolver
        g["NOOPResolver"] = NOOPResolver
@@ -421,20 +448,10 @@ 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)
-}
+PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_staging"
+do_patch[depends] = "${PATCHDEPENDENCY}"
 
 python patch_do_patch() {
-       import re
-       import bb.fetch
-
        patch_init(d)
 
        src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split()
@@ -444,6 +461,7 @@ python patch_do_patch() {
        patchsetmap = {
                "patch": PatchTree,
                "quilt": QuiltTree,
+               "git": GitApplyTree,
        }
 
        cls = patchsetmap[bb.data.getVar('PATCHTOOL', d, 1) or 'quilt']
@@ -492,35 +510,37 @@ python patch_do_patch() {
                else:
                        pname = os.path.basename(unpacked)
 
-               if "mindate" in parm:
-                       mindate = parm["mindate"]
-               else:
-                       mindate = 0
+                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 "maxdate" in parm:
-                       maxdate = parm["maxdate"]
-               else:
-                       maxdate = "20711226"
+                       if srcdate == "now":
+                               srcdate = bb.data.getVar('DATE', d, 1)
 
-               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 < 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
 
-               bb.note("Applying patch '%s'" % pname)
+               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' (%s)" % (pname, base_path_out(unpacked, d)))
                try:
                        patchset.Import({"file":unpacked, "remote":url, "strippath": pnum}, True)
                except: