tar: Switch to INC_PR and fix native builds.
[openembedded.git] / classes / patch.bbclass
blob58b931f966e7a33c9f934341de4fd2c31154bcc1
1 # Copyright (C) 2006  OpenedHand LTD
3 # Point to an empty file so any user's custom settings don't break things
4 QUILTRCFILE ?= "${STAGING_BINDIR_NATIVE}/quiltrc"
6 PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot"
8 python patch_do_patch() {
9         import oe.patch
10         import oe.unpack
12         src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split()
13         if not src_uri:
14                 return
16         patchsetmap = {
17                 "patch": oe.patch.PatchTree,
18                 "quilt": oe.patch.QuiltTree,
19                 "git": oe.patch.GitApplyTree,
20         }
22         cls = patchsetmap[bb.data.getVar('PATCHTOOL', d, 1) or 'quilt']
24         resolvermap = {
25                 "noop": oe.patch.NOOPResolver,
26                 "user": oe.patch.UserResolver,
27         }
29         rcls = resolvermap[bb.data.getVar('PATCHRESOLVE', d, 1) or 'user']
31         s = bb.data.getVar('S', d, 1)
33         path = os.getenv('PATH')
34         os.putenv('PATH', bb.data.getVar('PATH', d, 1))
36         classes = {}
38         src_uri = d.getVar("SRC_URI", True).split()
39         srcurldata = bb.fetch.init(src_uri, d, True)
40         workdir = bb.data.getVar('WORKDIR', d, 1)
41         for url in d.getVar("SRC_URI", True).split():
42                 urldata = srcurldata[url]
44                 local = urldata.localpath
45                 if not local:
46                         raise bb.build.FuncFailed('Unable to locate local file for %s' % url)
48                 base, ext = os.path.splitext(os.path.basename(local))
49                 if ext in ('.gz', '.bz2', '.Z'):
50                         local = oe.path.join(workdir, base)
52                 if not oe.unpack.is_patch(local, urldata.parm):
53                         continue
55                 parm = urldata.parm
57                 if "striplevel" in parm:
58                         striplevel = parm["striplevel"]
59                 elif "pnum" in parm:
60                         bb.msg.warn(None, "Deprecated usage of 'pnum' url parameter in '%s', please use 'striplevel'" % url)
61                         striplevel = parm["pnum"]
62                 else:
63                         striplevel = '1'
65                 if "pname" in parm:
66                         pname = parm["pname"]
67                 else:
68                         pname = os.path.basename(local)
70                 if "mindate" in parm or "maxdate" in parm:
71                         pn = bb.data.getVar('PN', d, 1)
72                         srcdate = bb.data.getVar('SRCDATE_%s' % pn, d, 1)
73                         if not srcdate:
74                                 srcdate = bb.data.getVar('SRCDATE', d, 1)
76                         if srcdate == "now":
77                                 srcdate = bb.data.getVar('DATE', d, 1)
79                         if "maxdate" in parm and parm["maxdate"] < srcdate:
80                                 bb.note("Patch '%s' is outdated" % pname)
81                                 continue
83                         if "mindate" in parm and parm["mindate"] > srcdate:
84                                 bb.note("Patch '%s' is predated" % pname)
85                                 continue
88                 if "minrev" in parm:
89                         srcrev = bb.data.getVar('SRCREV', d, 1)
90                         if srcrev and srcrev < parm["minrev"]:
91                                 bb.note("Patch '%s' applies to later revisions" % pname)
92                                 continue
94                 if "maxrev" in parm:
95                         srcrev = bb.data.getVar('SRCREV', d, 1)         
96                         if srcrev and srcrev > parm["maxrev"]:
97                                 bb.note("Patch '%s' applies to earlier revisions" % pname)
98                                 continue
100                 if "patchdir" in parm:
101                         patchdir = parm["patchdir"]
102                         if not os.path.isabs(patchdir):
103                                 patchdir = os.path.join(s, patchdir)
104                 else:
105                         patchdir = s
107                 if not patchdir in classes:
108                         patchset = cls(patchdir, d)
109                         resolver = rcls(patchset)
110                         classes[patchdir] = (patchset, resolver)
111                         patchset.Clean()
112                 else:
113                         patchset, resolver = classes[patchdir]
115                 bb.note("Applying patch '%s' (%s)" % (pname, oe.path.format_display(local, d)))
116                 try:
117                         patchset.Import({"file":local, "remote":url, "strippath": striplevel}, True)
118                 except Exception:
119                         import sys
120                         raise bb.build.FuncFailed(str(sys.exc_value))
121                 resolver.Resolve()
124 addtask patch after do_unpack
125 do_patch[dirs] = "${WORKDIR}"
126 do_patch[depends] = "${PATCHDEPENDENCY}"
128 EXPORT_FUNCTIONS do_patch