blob: 6095d278dd08eb47f9bcc6f0c7ad2d9f011e9fc5 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007def preferred_ml_updates(d):
Andrew Geissler95ac1b82021-03-31 14:34:31 -05008 # If any of PREFERRED_PROVIDER, PREFERRED_RPROVIDER, REQUIRED_VERSION
9 # or PREFERRED_VERSION are set, we need to mirror these variables in
10 # the multilib case;
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011 multilibs = d.getVar('MULTILIBS') or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012 if not multilibs:
13 return
14
15 prefixes = []
16 for ext in multilibs.split():
17 eext = ext.split(':')
18 if len(eext) > 1 and eext[0] == 'multilib':
19 prefixes.append(eext[1])
20
Andrew Geissler95ac1b82021-03-31 14:34:31 -050021 required_versions = []
22 preferred_versions = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 providers = []
Brad Bishop316dfdd2018-06-25 12:45:53 -040024 rproviders = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025 for v in d.keys():
Andrew Geissler95ac1b82021-03-31 14:34:31 -050026 if v.startswith("REQUIRED_VERSION_"):
27 required_versions.append(v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 if v.startswith("PREFERRED_VERSION_"):
Andrew Geissler95ac1b82021-03-31 14:34:31 -050029 preferred_versions.append(v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030 if v.startswith("PREFERRED_PROVIDER_"):
31 providers.append(v)
Brad Bishop316dfdd2018-06-25 12:45:53 -040032 if v.startswith("PREFERRED_RPROVIDER_"):
33 rproviders.append(v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034
Andrew Geissler95ac1b82021-03-31 14:34:31 -050035 def sort_versions(versions, keyword):
36 version_str = "_".join([keyword, "VERSION", ""])
37 for v in versions:
38 val = d.getVar(v, False)
39 pkg = v.replace(version_str, "")
40 if pkg.endswith("-native") or "-crosssdk-" in pkg or pkg.startswith(("nativesdk-", "virtual/nativesdk-")):
41 continue
42 if '-cross-' in pkg and '${' in pkg:
43 for p in prefixes:
44 localdata = bb.data.createCopy(d)
45 override = ":virtclass-multilib-" + p
46 localdata.setVar("OVERRIDES", localdata.getVar("OVERRIDES", False) + override)
47 if "-canadian-" in pkg:
Andrew Geissler9aee5002022-03-30 16:27:02 +000048 newtune = localdata.getVar("DEFAULTTUNE:" + "virtclass-multilib-" + p, False)
49 if newtune:
50 localdata.setVar("DEFAULTTUNE", newtune)
Andrew Geissler95ac1b82021-03-31 14:34:31 -050051 newname = localdata.expand(v)
52 else:
53 newname = localdata.expand(v).replace(version_str, version_str + p + '-')
54 if newname != v:
55 newval = localdata.expand(val)
56 d.setVar(newname, newval)
57 # Avoid future variable key expansion
58 vexp = d.expand(v)
59 if v != vexp and d.getVar(v, False):
60 d.renameVar(v, vexp)
61 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062 for p in prefixes:
Andrew Geissler95ac1b82021-03-31 14:34:31 -050063 newname = version_str + p + "-" + pkg
64 if not d.getVar(newname, False):
65 d.setVar(newname, val)
66
67 sort_versions(required_versions, "REQUIRED")
68 sort_versions(preferred_versions, "PREFERRED")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069
70 for prov in providers:
71 val = d.getVar(prov, False)
72 pkg = prov.replace("PREFERRED_PROVIDER_", "")
73 if pkg.endswith("-native") or "-crosssdk-" in pkg or pkg.startswith(("nativesdk-", "virtual/nativesdk-")):
74 continue
75 if 'cross-canadian' in pkg:
76 for p in prefixes:
77 localdata = bb.data.createCopy(d)
78 override = ":virtclass-multilib-" + p
79 localdata.setVar("OVERRIDES", localdata.getVar("OVERRIDES", False) + override)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080 newname = localdata.expand(prov)
81 if newname != prov:
82 newval = localdata.expand(val)
83 d.setVar(newname, newval)
84 # Avoid future variable key expansion
85 provexp = d.expand(prov)
86 if prov != provexp and d.getVar(prov, False):
87 d.renameVar(prov, provexp)
88 continue
89 virt = ""
90 if pkg.startswith("virtual/"):
91 pkg = pkg.replace("virtual/", "")
92 virt = "virtual/"
93 for p in prefixes:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060094 newval = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 if pkg != "kernel":
96 newval = p + "-" + val
97
98 # implement variable keys
99 localdata = bb.data.createCopy(d)
100 override = ":virtclass-multilib-" + p
101 localdata.setVar("OVERRIDES", localdata.getVar("OVERRIDES", False) + override)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 newname = localdata.expand(prov)
103 if newname != prov and not d.getVar(newname, False):
104 d.setVar(newname, localdata.expand(newval))
105
106 # implement alternative multilib name
107 newname = localdata.expand("PREFERRED_PROVIDER_" + virt + p + "-" + pkg)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 if not d.getVar(newname, False) and newval != None:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 d.setVar(newname, localdata.expand(newval))
110 # Avoid future variable key expansion
111 provexp = d.expand(prov)
112 if prov != provexp and d.getVar(prov, False):
113 d.renameVar(prov, provexp)
114
Brad Bishop316dfdd2018-06-25 12:45:53 -0400115 for prov in rproviders:
116 val = d.getVar(prov, False)
117 pkg = prov.replace("PREFERRED_RPROVIDER_", "")
118 for p in prefixes:
119 newval = p + "-" + val
120
121 # implement variable keys
122 localdata = bb.data.createCopy(d)
123 override = ":virtclass-multilib-" + p
124 localdata.setVar("OVERRIDES", localdata.getVar("OVERRIDES", False) + override)
125 newname = localdata.expand(prov)
126 if newname != prov and not d.getVar(newname, False):
127 d.setVar(newname, localdata.expand(newval))
128
129 # implement alternative multilib name
130 newname = localdata.expand("PREFERRED_RPROVIDER_" + p + "-" + pkg)
131 if not d.getVar(newname, False) and newval != None:
132 d.setVar(newname, localdata.expand(newval))
133 # Avoid future variable key expansion
134 provexp = d.expand(prov)
135 if prov != provexp and d.getVar(prov, False):
136 d.renameVar(prov, provexp)
137
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500138 def translate_provide(prefix, prov):
Brad Bishop15ae2502019-06-18 21:44:24 -0400139 # Really need to know if kernel modules class is inherited somehow
140 if prov == "lttng-modules":
141 return prov
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500142 if not prov.startswith("virtual/"):
143 return prefix + "-" + prov
144 if prov == "virtual/kernel":
145 return prov
146 prov = prov.replace("virtual/", "")
147 return "virtual/" + prefix + "-" + prov
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000149 mp = (d.getVar("BB_MULTI_PROVIDER_ALLOWED") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 extramp = []
151 for p in mp:
152 if p.endswith("-native") or "-crosssdk-" in p or p.startswith(("nativesdk-", "virtual/nativesdk-")) or 'cross-canadian' in p:
153 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 for pref in prefixes:
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500155 extramp.append(translate_provide(pref, p))
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000156 d.setVar("BB_MULTI_PROVIDER_ALLOWED", " ".join(mp + extramp))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500158 abisafe = (d.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split()
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500159 extras = []
160 for p in prefixes:
161 for a in abisafe:
162 extras.append(p + "-" + a)
163 d.appendVar("SIGGEN_EXCLUDERECIPES_ABISAFE", " " + " ".join(extras))
164
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500165 siggen_exclude = (d.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split()
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500166 extras = []
167 for p in prefixes:
168 for a in siggen_exclude:
169 a1, a2 = a.split("->")
170 extras.append(translate_provide(p, a1) + "->" + translate_provide(p, a2))
171 d.appendVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", " " + " ".join(extras))
172
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173python multilib_virtclass_handler_vendor () {
174 if isinstance(e, bb.event.ConfigParsed):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500175 for v in e.data.getVar("MULTILIB_VARIANTS").split():
Patrick Williams213cb262021-08-07 19:21:33 -0500176 if e.data.getVar("TARGET_VENDOR:virtclass-multilib-" + v, False) is None:
177 e.data.setVar("TARGET_VENDOR:virtclass-multilib-" + v, e.data.getVar("TARGET_VENDOR", False) + "ml" + v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 preferred_ml_updates(e.data)
179}
180addhandler multilib_virtclass_handler_vendor
181multilib_virtclass_handler_vendor[eventmask] = "bb.event.ConfigParsed"
182
183python multilib_virtclass_handler_global () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500184 variant = e.data.getVar("BBEXTENDVARIANT")
185 if variant:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186 return
187
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800188 non_ml_recipes = d.getVar('NON_MULTILIB_RECIPES').split()
189
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500190 if bb.data.inherits_class('kernel', e.data) or \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 bb.data.inherits_class('module-base', e.data) or \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800192 d.getVar('BPN') in non_ml_recipes:
Brad Bishop96ff1982019-08-19 13:50:42 -0400193
194 # We need to avoid expanding KERNEL_VERSION which we can do by deleting it
195 # from a copy of the datastore
196 localdata = bb.data.createCopy(d)
197 localdata.delVar("KERNEL_VERSION")
Patrick Williams73bd93f2024-02-20 08:07:48 -0600198 localdata.delVar("KERNEL_VERSION_PKG_NAME")
Brad Bishop96ff1982019-08-19 13:50:42 -0400199
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500200 variants = (e.data.getVar("MULTILIB_VARIANTS") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500201
202 import oe.classextend
203 clsextends = []
204 for variant in variants:
Brad Bishop96ff1982019-08-19 13:50:42 -0400205 clsextends.append(oe.classextend.ClassExtender(variant, localdata))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206
207 # Process PROVIDES
Brad Bishop96ff1982019-08-19 13:50:42 -0400208 origprovs = provs = localdata.getVar("PROVIDES") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500209 for clsextend in clsextends:
210 provs = provs + " " + clsextend.map_variable("PROVIDES", setvar=False)
211 e.data.setVar("PROVIDES", provs)
212
213 # Process RPROVIDES
Brad Bishop96ff1982019-08-19 13:50:42 -0400214 origrprovs = rprovs = localdata.getVar("RPROVIDES") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215 for clsextend in clsextends:
216 rprovs = rprovs + " " + clsextend.map_variable("RPROVIDES", setvar=False)
217 if rprovs.strip():
218 e.data.setVar("RPROVIDES", rprovs)
219
Patrick Williams213cb262021-08-07 19:21:33 -0500220 # Process RPROVIDES:${PN}...
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500221 for pkg in (e.data.getVar("PACKAGES") or "").split():
Patrick Williams213cb262021-08-07 19:21:33 -0500222 origrprovs = rprovs = localdata.getVar("RPROVIDES:%s" % pkg) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223 for clsextend in clsextends:
Patrick Williams213cb262021-08-07 19:21:33 -0500224 rprovs = rprovs + " " + clsextend.map_variable("RPROVIDES:%s" % pkg, setvar=False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500225 rprovs = rprovs + " " + clsextend.extname + "-" + pkg
Patrick Williams213cb262021-08-07 19:21:33 -0500226 e.data.setVar("RPROVIDES:%s" % pkg, rprovs)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227}
228
229addhandler multilib_virtclass_handler_global
Brad Bishop96ff1982019-08-19 13:50:42 -0400230multilib_virtclass_handler_global[eventmask] = "bb.event.RecipeTaskPreProcess"