Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | import collections |
| 8 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 9 | def get_packages(d): |
| 10 | pkgs = d.getVar("PACKAGES_NONML") |
| 11 | extcls = d.getVar("EXTENDERCLASS") |
| 12 | return extcls.rename_packages_internal(pkgs) |
| 13 | |
| 14 | def get_depends(varprefix, d): |
| 15 | extcls = d.getVar("EXTENDERCLASS") |
| 16 | return extcls.map_depends_variable(varprefix + "_NONML") |
| 17 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | class ClassExtender(object): |
| 19 | def __init__(self, extname, d): |
| 20 | self.extname = extname |
| 21 | self.d = d |
| 22 | self.pkgs_mapping = [] |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 23 | self.d.setVar("EXTENDERCLASS", self) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | |
| 25 | def extend_name(self, name): |
| 26 | if name.startswith("kernel-") or name == "virtual/kernel": |
| 27 | return name |
| 28 | if name.startswith("rtld"): |
| 29 | return name |
| 30 | if name.endswith("-crosssdk"): |
| 31 | return name |
| 32 | if name.endswith("-" + self.extname): |
| 33 | name = name.replace("-" + self.extname, "") |
| 34 | if name.startswith("virtual/"): |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 35 | # Assume large numbers of dashes means a triplet is present and we don't need to convert |
| 36 | if name.count("-") >= 3 and name.endswith(("-go", "-binutils", "-gcc", "-g++")): |
| 37 | return name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | subs = name.split("/", 1)[1] |
| 39 | if not subs.startswith(self.extname): |
| 40 | return "virtual/" + self.extname + "-" + subs |
| 41 | return name |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 42 | if name.startswith("/") or (name.startswith("${") and name.endswith("}")): |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 43 | return name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | if not name.startswith(self.extname): |
| 45 | return self.extname + "-" + name |
| 46 | return name |
| 47 | |
| 48 | def map_variable(self, varname, setvar = True): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 49 | var = self.d.getVar(varname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | if not var: |
| 51 | return "" |
| 52 | var = var.split() |
| 53 | newvar = [] |
| 54 | for v in var: |
| 55 | newvar.append(self.extend_name(v)) |
| 56 | newdata = " ".join(newvar) |
| 57 | if setvar: |
| 58 | self.d.setVar(varname, newdata) |
| 59 | return newdata |
| 60 | |
| 61 | def map_regexp_variable(self, varname, setvar = True): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 62 | var = self.d.getVar(varname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | if not var: |
| 64 | return "" |
| 65 | var = var.split() |
| 66 | newvar = [] |
| 67 | for v in var: |
| 68 | if v.startswith("^" + self.extname): |
| 69 | newvar.append(v) |
| 70 | elif v.startswith("^"): |
| 71 | newvar.append("^" + self.extname + "-" + v[1:]) |
| 72 | else: |
| 73 | newvar.append(self.extend_name(v)) |
| 74 | newdata = " ".join(newvar) |
| 75 | if setvar: |
| 76 | self.d.setVar(varname, newdata) |
| 77 | return newdata |
| 78 | |
| 79 | def map_depends(self, dep): |
| 80 | if dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('cross-canadian' in dep) or ('-crosssdk-' in dep): |
| 81 | return dep |
| 82 | else: |
| 83 | # Do not extend for that already have multilib prefix |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 84 | var = self.d.getVar("MULTILIB_VARIANTS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | if var: |
| 86 | var = var.split() |
| 87 | for v in var: |
| 88 | if dep.startswith(v): |
| 89 | return dep |
| 90 | return self.extend_name(dep) |
| 91 | |
| 92 | def map_depends_variable(self, varname, suffix = ""): |
| 93 | # We need to preserve EXTENDPKGV so it can be expanded correctly later |
| 94 | if suffix: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 95 | varname = varname + ":" + suffix |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | orig = self.d.getVar("EXTENDPKGV", False) |
| 97 | self.d.setVar("EXTENDPKGV", "EXTENDPKGV") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | deps = self.d.getVar(varname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | if not deps: |
| 100 | self.d.setVar("EXTENDPKGV", orig) |
| 101 | return |
| 102 | deps = bb.utils.explode_dep_versions2(deps) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 103 | newdeps = collections.OrderedDict() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | for dep in deps: |
| 105 | newdeps[self.map_depends(dep)] = deps[dep] |
| 106 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 107 | if not varname.endswith("_NONML"): |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 108 | self.d.renameVar(varname, varname + "_NONML") |
| 109 | self.d.setVar(varname, "${@oe.classextend.get_depends('%s', d)}" % varname) |
| 110 | self.d.appendVarFlag(varname, "vardeps", " " + varname + "_NONML") |
| 111 | ret = bb.utils.join_deps(newdeps, False).replace("EXTENDPKGV", "${EXTENDPKGV}") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | self.d.setVar("EXTENDPKGV", orig) |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 113 | return ret |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | |
| 115 | def map_packagevars(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 116 | for pkg in (self.d.getVar("PACKAGES").split() + [""]): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | self.map_depends_variable("RDEPENDS", pkg) |
| 118 | self.map_depends_variable("RRECOMMENDS", pkg) |
| 119 | self.map_depends_variable("RSUGGESTS", pkg) |
| 120 | self.map_depends_variable("RPROVIDES", pkg) |
| 121 | self.map_depends_variable("RREPLACES", pkg) |
| 122 | self.map_depends_variable("RCONFLICTS", pkg) |
| 123 | self.map_depends_variable("PKG", pkg) |
| 124 | |
| 125 | def rename_packages(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 126 | for pkg in (self.d.getVar("PACKAGES") or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | if pkg.startswith(self.extname): |
| 128 | self.pkgs_mapping.append([pkg.split(self.extname + "-")[1], pkg]) |
| 129 | continue |
| 130 | self.pkgs_mapping.append([pkg, self.extend_name(pkg)]) |
| 131 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 132 | self.d.renameVar("PACKAGES", "PACKAGES_NONML") |
| 133 | self.d.setVar("PACKAGES", "${@oe.classextend.get_packages(d)}") |
| 134 | |
| 135 | def rename_packages_internal(self, pkgs): |
| 136 | self.pkgs_mapping = [] |
| 137 | for pkg in (self.d.expand(pkgs) or "").split(): |
| 138 | if pkg.startswith(self.extname): |
| 139 | self.pkgs_mapping.append([pkg.split(self.extname + "-")[1], pkg]) |
| 140 | continue |
| 141 | self.pkgs_mapping.append([pkg, self.extend_name(pkg)]) |
| 142 | |
| 143 | return " ".join([row[1] for row in self.pkgs_mapping]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | |
| 145 | def rename_package_variables(self, variables): |
| 146 | for pkg_mapping in self.pkgs_mapping: |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 147 | if pkg_mapping[0].startswith("${") and pkg_mapping[0].endswith("}"): |
| 148 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 149 | for subs in variables: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 150 | self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | |
| 152 | class NativesdkClassExtender(ClassExtender): |
| 153 | def map_depends(self, dep): |
| 154 | if dep.startswith(self.extname): |
| 155 | return dep |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 156 | if dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('-cross-' in dep) or ('-crosssdk-' in dep): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | return dep |
| 158 | else: |
| 159 | return self.extend_name(dep) |