blob: 2013b29711b0d2262c9338e98a9989a92ab88aa7 [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/"):
35 subs = name.split("/", 1)[1]
36 if not subs.startswith(self.extname):
37 return "virtual/" + self.extname + "-" + subs
38 return name
Andrew Geissler1e34c2d2020-05-29 16:02:59 -050039 if name.startswith("/") or (name.startswith("${") and name.endswith("}")):
Brad Bishopa34c0302019-09-23 22:34:48 -040040 return name
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041 if not name.startswith(self.extname):
42 return self.extname + "-" + name
43 return name
44
45 def map_variable(self, varname, setvar = True):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 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 Bishop6e60e8b2018-02-01 10:27:11 -050059 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 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 Bishop6e60e8b2018-02-01 10:27:11 -050081 var = self.d.getVar("MULTILIB_VARIANTS")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082 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 Williams213cb262021-08-07 19:21:33 -050092 varname = varname + ":" + suffix
Patrick Williamsc124f4f2015-09-15 14:41:29 -050093 orig = self.d.getVar("EXTENDPKGV", False)
94 self.d.setVar("EXTENDPKGV", "EXTENDPKGV")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050095 deps = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096 if not deps:
97 self.d.setVar("EXTENDPKGV", orig)
98 return
99 deps = bb.utils.explode_dep_versions2(deps)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600100 newdeps = collections.OrderedDict()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101 for dep in deps:
102 newdeps[self.map_depends(dep)] = deps[dep]
103
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500104 if not varname.endswith("_NONML"):
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500105 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 Williamsc124f4f2015-09-15 14:41:29 -0500109 self.d.setVar("EXTENDPKGV", orig)
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500110 return ret
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111
112 def map_packagevars(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500113 for pkg in (self.d.getVar("PACKAGES").split() + [""]):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 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 Bishop6e60e8b2018-02-01 10:27:11 -0500123 for pkg in (self.d.getVar("PACKAGES") or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500124 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 Geissler1e34c2d2020-05-29 16:02:59 -0500129 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 Williamsc124f4f2015-09-15 14:41:29 -0500141
142 def rename_package_variables(self, variables):
143 for pkg_mapping in self.pkgs_mapping:
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500144 if pkg_mapping[0].startswith("${") and pkg_mapping[0].endswith("}"):
145 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146 for subs in variables:
Patrick Williams213cb262021-08-07 19:21:33 -0500147 self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148
149class NativesdkClassExtender(ClassExtender):
150 def map_depends(self, dep):
151 if dep.startswith(self.extname):
152 return dep
Brad Bishop19323692019-04-05 15:28:33 -0400153 if dep.endswith(("-gcc", "-g++")):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 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)