Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | def preferred_ml_updates(d): |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 8 | # 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 11 | multilibs = d.getVar('MULTILIBS') or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | 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 Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 21 | required_versions = [] |
| 22 | preferred_versions = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | providers = [] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 24 | rproviders = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | for v in d.keys(): |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 26 | if v.startswith("REQUIRED_VERSION_"): |
| 27 | required_versions.append(v) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | if v.startswith("PREFERRED_VERSION_"): |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 29 | preferred_versions.append(v) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | if v.startswith("PREFERRED_PROVIDER_"): |
| 31 | providers.append(v) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 32 | if v.startswith("PREFERRED_RPROVIDER_"): |
| 33 | rproviders.append(v) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 35 | 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 Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 48 | newtune = localdata.getVar("DEFAULTTUNE:" + "virtclass-multilib-" + p, False) |
| 49 | if newtune: |
| 50 | localdata.setVar("DEFAULTTUNE", newtune) |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 51 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | for p in prefixes: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 63 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 94 | newval = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 108 | if not d.getVar(newname, False) and newval != None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | 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 Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 115 | 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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 138 | def translate_provide(prefix, prov): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 139 | # Really need to know if kernel modules class is inherited somehow |
| 140 | if prov == "lttng-modules": |
| 141 | return prov |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 142 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 148 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 149 | mp = (d.getVar("BB_MULTI_PROVIDER_ALLOWED") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | for pref in prefixes: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 155 | extramp.append(translate_provide(pref, p)) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 156 | d.setVar("BB_MULTI_PROVIDER_ALLOWED", " ".join(mp + extramp)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 158 | abisafe = (d.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split() |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 159 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 165 | siggen_exclude = (d.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split() |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 166 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 173 | python multilib_virtclass_handler_vendor () { |
| 174 | if isinstance(e, bb.event.ConfigParsed): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 175 | for v in e.data.getVar("MULTILIB_VARIANTS").split(): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 176 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 178 | preferred_ml_updates(e.data) |
| 179 | } |
| 180 | addhandler multilib_virtclass_handler_vendor |
| 181 | multilib_virtclass_handler_vendor[eventmask] = "bb.event.ConfigParsed" |
| 182 | |
| 183 | python multilib_virtclass_handler_global () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 184 | variant = e.data.getVar("BBEXTENDVARIANT") |
| 185 | if variant: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | return |
| 187 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 188 | non_ml_recipes = d.getVar('NON_MULTILIB_RECIPES').split() |
| 189 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 190 | if bb.data.inherits_class('kernel', e.data) or \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | bb.data.inherits_class('module-base', e.data) or \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 192 | d.getVar('BPN') in non_ml_recipes: |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 193 | |
| 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") |
| 198 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 199 | variants = (e.data.getVar("MULTILIB_VARIANTS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | |
| 201 | import oe.classextend |
| 202 | clsextends = [] |
| 203 | for variant in variants: |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 204 | clsextends.append(oe.classextend.ClassExtender(variant, localdata)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 205 | |
| 206 | # Process PROVIDES |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 207 | origprovs = provs = localdata.getVar("PROVIDES") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 208 | for clsextend in clsextends: |
| 209 | provs = provs + " " + clsextend.map_variable("PROVIDES", setvar=False) |
| 210 | e.data.setVar("PROVIDES", provs) |
| 211 | |
| 212 | # Process RPROVIDES |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 213 | origrprovs = rprovs = localdata.getVar("RPROVIDES") or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | for clsextend in clsextends: |
| 215 | rprovs = rprovs + " " + clsextend.map_variable("RPROVIDES", setvar=False) |
| 216 | if rprovs.strip(): |
| 217 | e.data.setVar("RPROVIDES", rprovs) |
| 218 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 219 | # Process RPROVIDES:${PN}... |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 220 | for pkg in (e.data.getVar("PACKAGES") or "").split(): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 221 | origrprovs = rprovs = localdata.getVar("RPROVIDES:%s" % pkg) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 222 | for clsextend in clsextends: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 223 | rprovs = rprovs + " " + clsextend.map_variable("RPROVIDES:%s" % pkg, setvar=False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | rprovs = rprovs + " " + clsextend.extname + "-" + pkg |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 225 | e.data.setVar("RPROVIDES:%s" % pkg, rprovs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | addhandler multilib_virtclass_handler_global |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 229 | multilib_virtclass_handler_global[eventmask] = "bb.event.RecipeTaskPreProcess" |