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