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