blob: 5161d33d2d2fcc204c065885f4ec14892267ad1f [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: GPL-2.0-only
5#
6
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007import collections
8
Andrew Geissler1e34c2d2020-05-29 16:02:59 -05009def get_packages(d):
10 pkgs = d.getVar("PACKAGES_NONML")
11 extcls = d.getVar("EXTENDERCLASS")
12 return extcls.rename_packages_internal(pkgs)
13
14def get_depends(varprefix, d):
15 extcls = d.getVar("EXTENDERCLASS")
16 return extcls.map_depends_variable(varprefix + "_NONML")
17
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018class ClassExtender(object):
19 def __init__(self, extname, d):
20 self.extname = extname
21 self.d = d
22 self.pkgs_mapping = []
Andrew Geissler1e34c2d2020-05-29 16:02:59 -050023 self.d.setVar("EXTENDERCLASS", self)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024
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 Geissler028142b2023-05-05 11:29:21 -050035 # 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 Williamsc124f4f2015-09-15 14:41:29 -050038 subs = name.split("/", 1)[1]
39 if not subs.startswith(self.extname):
40 return "virtual/" + self.extname + "-" + subs
41 return name
Andrew Geissler1e34c2d2020-05-29 16:02:59 -050042 if name.startswith("/") or (name.startswith("${") and name.endswith("}")):
Brad Bishopa34c0302019-09-23 22:34:48 -040043 return name
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044 if not name.startswith(self.extname):
45 return self.extname + "-" + name
46 return name
47
48 def map_variable(self, varname, setvar = True):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050 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 Bishop6e60e8b2018-02-01 10:27:11 -050062 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063 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 Bishop6e60e8b2018-02-01 10:27:11 -050084 var = self.d.getVar("MULTILIB_VARIANTS")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085 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 Williams213cb262021-08-07 19:21:33 -050095 varname = varname + ":" + suffix
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096 orig = self.d.getVar("EXTENDPKGV", False)
97 self.d.setVar("EXTENDPKGV", "EXTENDPKGV")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 deps = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050099 if not deps:
100 self.d.setVar("EXTENDPKGV", orig)
101 return
102 deps = bb.utils.explode_dep_versions2(deps)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600103 newdeps = collections.OrderedDict()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 for dep in deps:
105 newdeps[self.map_depends(dep)] = deps[dep]
106
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500107 if not varname.endswith("_NONML"):
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500108 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 Williamsc124f4f2015-09-15 14:41:29 -0500112 self.d.setVar("EXTENDPKGV", orig)
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500113 return ret
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114
115 def map_packagevars(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500116 for pkg in (self.d.getVar("PACKAGES").split() + [""]):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117 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 Bishop6e60e8b2018-02-01 10:27:11 -0500126 for pkg in (self.d.getVar("PACKAGES") or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127 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 Geissler1e34c2d2020-05-29 16:02:59 -0500132 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 Williamsc124f4f2015-09-15 14:41:29 -0500144
145 def rename_package_variables(self, variables):
146 for pkg_mapping in self.pkgs_mapping:
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500147 if pkg_mapping[0].startswith("${") and pkg_mapping[0].endswith("}"):
148 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500149 for subs in variables:
Patrick Williams213cb262021-08-07 19:21:33 -0500150 self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151
152class NativesdkClassExtender(ClassExtender):
153 def map_depends(self, dep):
154 if dep.startswith(self.extname):
155 return dep
Andrew Geissler028142b2023-05-05 11:29:21 -0500156 if dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('-cross-' in dep) or ('-crosssdk-' in dep):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 return dep
158 else:
159 return self.extend_name(dep)