summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/patch.bbclass203
1 files changed, 109 insertions, 94 deletions
diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
index ac6c1ce1e5..335d02ec71 100644
--- a/meta/classes/patch.bbclass
+++ b/meta/classes/patch.bbclass
@@ -7,115 +7,131 @@ PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot"
7 7
8inherit terminal 8inherit terminal
9 9
10python patch_do_patch() { 10def src_patches(d):
11 import oe.patch 11 workdir = d.getVar('WORKDIR', True)
12 fetch = bb.fetch2.Fetch([], d)
13 patches = []
14 for url in fetch.urls:
15 local = patch_path(url, fetch, workdir)
16 if not local:
17 continue
18
19 urldata = fetch.ud[url]
20 parm = urldata.parm
21 patchname = parm.get('pname') or os.path.basename(local)
22
23 apply, reason = should_apply(parm, d)
24 if not apply:
25 if reason:
26 bb.note("Patch %s %s" % (patchname, reason))
27 continue
12 28
13 src_uri = (d.getVar('SRC_URI', 1) or '').split() 29 patchparm = {'patchname': patchname}
14 if not src_uri: 30 if "striplevel" in parm:
31 striplevel = parm["striplevel"]
32 elif "pnum" in parm:
33 #bb.msg.warn(None, "Deprecated usage of 'pnum' url parameter in '%s', please use 'striplevel'" % url)
34 striplevel = parm["pnum"]
35 else:
36 striplevel = '1'
37 patchparm['striplevel'] = striplevel
38
39 patchdir = parm.get('patchdir')
40 if patchdir:
41 patchparm['patchdir'] = patchdir
42
43 localurl = bb.encodeurl(('file', '', local, '', '', patchparm))
44 patches.append(localurl)
45
46 return patches
47
48def patch_path(url, fetch, workdir):
49 """Return the local path of a patch, or None if this isn't a patch"""
50
51 local = fetch.localpath(url)
52 base, ext = os.path.splitext(os.path.basename(local))
53 if ext in ('.gz', '.bz2', '.Z'):
54 local = os.path.join(workdir, base)
55 ext = os.path.splitext(base)[1]
56
57 urldata = fetch.ud[url]
58 if "apply" in urldata.parm:
59 apply = oe.types.boolean(urldata.parm["apply"])
60 if not apply:
61 return
62 elif ext not in (".diff", ".patch"):
15 return 63 return
16 64
65 return local
66
67def should_apply(parm, d):
68 """Determine if we should apply the given patch"""
69
70 if "mindate" in parm or "maxdate" in parm:
71 pn = d.getVar('PN', True)
72 srcdate = d.getVar('SRCDATE_%s' % pn, True)
73 if not srcdate:
74 srcdate = d.getVar('SRCDATE', True)
75
76 if srcdate == "now":
77 srcdate = d.getVar('DATE', True)
78
79 if "maxdate" in parm and parm["maxdate"] < srcdate:
80 return False, 'is outdated'
81
82 if "mindate" in parm and parm["mindate"] > srcdate:
83 return False, 'is predated'
84
85
86 if "minrev" in parm:
87 srcrev = d.getVar('SRCREV', True)
88 if srcrev and srcrev < parm["minrev"]:
89 return False, 'applies to later revisions'
90
91 if "maxrev" in parm:
92 srcrev = d.getVar('SRCREV', True)
93 if srcrev and srcrev > parm["maxrev"]:
94 return False, 'applies to earlier revisions'
95
96 if "rev" in parm:
97 srcrev = d.getVar('SRCREV', True)
98 if srcrev and parm["rev"] not in srcrev:
99 return False, "doesn't apply to revision"
100
101 if "notrev" in parm:
102 srcrev = d.getVar('SRCREV', True)
103 if srcrev and parm["notrev"] in srcrev:
104 return False, "doesn't apply to revision"
105
106 return True, None
107
108python patch_do_patch() {
109 import oe.patch
110
17 patchsetmap = { 111 patchsetmap = {
18 "patch": oe.patch.PatchTree, 112 "patch": oe.patch.PatchTree,
19 "quilt": oe.patch.QuiltTree, 113 "quilt": oe.patch.QuiltTree,
20 "git": oe.patch.GitApplyTree, 114 "git": oe.patch.GitApplyTree,
21 } 115 }
22 116
23 cls = patchsetmap[d.getVar('PATCHTOOL', 1) or 'quilt'] 117 cls = patchsetmap[d.getVar('PATCHTOOL', True) or 'quilt']
24 118
25 resolvermap = { 119 resolvermap = {
26 "noop": oe.patch.NOOPResolver, 120 "noop": oe.patch.NOOPResolver,
27 "user": oe.patch.UserResolver, 121 "user": oe.patch.UserResolver,
28 } 122 }
29 123
30 rcls = resolvermap[d.getVar('PATCHRESOLVE', 1) or 'user'] 124 rcls = resolvermap[d.getVar('PATCHRESOLVE', True) or 'user']
31
32 s = d.getVar('S', 1)
33
34 path = os.getenv('PATH')
35 os.putenv('PATH', d.getVar('PATH', 1))
36 125
37 classes = {} 126 classes = {}
38 127
39 workdir = d.getVar('WORKDIR', 1) 128 s = d.getVar('S', True)
40 for url in src_uri:
41 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
42
43 local = None
44 base, ext = os.path.splitext(os.path.basename(path))
45 if ext in ('.gz', '.bz2', '.Z'):
46 local = os.path.join(workdir, base)
47 ext = os.path.splitext(base)[1]
48
49 if "apply" in parm:
50 apply = parm["apply"]
51 if apply != "yes":
52 if apply != "no":
53 bb.msg.warn(None, "Unsupported value '%s' for 'apply' url param in '%s', please use 'yes' or 'no'" % (apply, url))
54 continue
55 #elif "patch" in parm:
56 #bb.msg.warn(None, "Deprecated usage of 'patch' url param in '%s', please use 'apply={yes,no}'" % url)
57 elif ext not in (".diff", ".patch"):
58 continue
59
60 if not local:
61 url = bb.encodeurl((type, host, path, user, pswd, []))
62 local = os.path.join('/', bb.fetch2.localpath(url, d))
63 local = bb.data.expand(local, d)
64 129
65 if "striplevel" in parm: 130 path = os.getenv('PATH')
66 striplevel = parm["striplevel"] 131 os.putenv('PATH', d.getVar('PATH', True))
67 elif "pnum" in parm:
68 #bb.msg.warn(None, "Deprecated usage of 'pnum' url parameter in '%s', please use 'striplevel'" % url)
69 striplevel = parm["pnum"]
70 else:
71 striplevel = '1'
72 132
73 if "pname" in parm: 133 for patch in src_patches(d):
74 pname = parm["pname"] 134 _, _, local, _, _, parm = bb.decodeurl(patch)
75 else:
76 pname = os.path.basename(local)
77
78 if "mindate" in parm or "maxdate" in parm:
79 pn = d.getVar('PN', 1)
80 srcdate = d.getVar('SRCDATE_%s' % pn, 1)
81 if not srcdate:
82 srcdate = d.getVar('SRCDATE', 1)
83
84 if srcdate == "now":
85 srcdate = d.getVar('DATE', 1)
86
87 if "maxdate" in parm and parm["maxdate"] < srcdate:
88 bb.note("Patch '%s' is outdated" % pname)
89 continue
90
91 if "mindate" in parm and parm["mindate"] > srcdate:
92 bb.note("Patch '%s' is predated" % pname)
93 continue
94
95
96 if "minrev" in parm:
97 srcrev = d.getVar('SRCREV', 1)
98 if srcrev and srcrev < parm["minrev"]:
99 bb.note("Patch '%s' applies to later revisions" % pname)
100 continue
101
102 if "maxrev" in parm:
103 srcrev = d.getVar('SRCREV', 1)
104 if srcrev and srcrev > parm["maxrev"]:
105 bb.note("Patch '%s' applies to earlier revisions" % pname)
106 continue
107
108 if "rev" in parm:
109 srcrev = d.getVar('SRCREV', 1)
110 if srcrev and parm["rev"] not in srcrev:
111 bb.note("Patch '%s' doesn't apply to revision" % pname)
112 continue
113
114 if "notrev" in parm:
115 srcrev = d.getVar('SRCREV', 1)
116 if srcrev and parm["notrev"] in srcrev:
117 bb.note("Patch '%s' doesn't apply to revision" % pname)
118 continue
119 135
120 if "patchdir" in parm: 136 if "patchdir" in parm:
121 patchdir = parm["patchdir"] 137 patchdir = parm["patchdir"]
@@ -132,12 +148,11 @@ python patch_do_patch() {
132 else: 148 else:
133 patchset, resolver = classes[patchdir] 149 patchset, resolver = classes[patchdir]
134 150
135 bb.note("Applying patch '%s' (%s)" % (pname, oe.path.format_display(local, d))) 151 bb.note("Applying patch '%s' (%s)" % (parm['patchname'], oe.path.format_display(local, d)))
136 try: 152 try:
137 patchset.Import({"file":local, "remote":url, "strippath": striplevel}, True) 153 patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
138 except Exception: 154 except Exception as exc:
139 import sys 155 bb.fatal(str(exc))
140 raise bb.build.FuncFailed(str(sys.exc_value))
141 resolver.Resolve() 156 resolver.Resolve()
142} 157}
143patch_do_patch[vardepsexclude] = "DATE SRCDATE PATCHRESOLVE" 158patch_do_patch[vardepsexclude] = "DATE SRCDATE PATCHRESOLVE"