blob: d3d8fbe7244e7e10e299defa66e102d28c1c4828 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: GPL-2.0-only
3#
4
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005import collections
6
Andrew Geissler1e34c2d2020-05-29 16:02:59 -05007def get_packages(d):
8 pkgs = d.getVar("PACKAGES_NONML")
9 extcls = d.getVar("EXTENDERCLASS")
10 return extcls.rename_packages_internal(pkgs)
11
12def get_depends(varprefix, d):
13 extcls = d.getVar("EXTENDERCLASS")
14 return extcls.map_depends_variable(varprefix + "_NONML")
15
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016class ClassExtender(object):
17 def __init__(self, extname, d):
18 self.extname = extname
19 self.d = d
20 self.pkgs_mapping = []
Andrew Geissler1e34c2d2020-05-29 16:02:59 -050021 self.d.setVar("EXTENDERCLASS", self)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
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 Geissler1e34c2d2020-05-29 16:02:59 -050037 if name.startswith("/") or (name.startswith("${") and name.endswith("}")):
Brad Bishopa34c0302019-09-23 22:34:48 -040038 return name
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 if not name.startswith(self.extname):
40 return self.extname + "-" + name
41 return name
42
43 def map_variable(self, varname, setvar = True):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 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 Bishop6e60e8b2018-02-01 10:27:11 -050057 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 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 Bishop6e60e8b2018-02-01 10:27:11 -050079 var = self.d.getVar("MULTILIB_VARIANTS")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080 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:
90 varname = varname + "_" + suffix
91 orig = self.d.getVar("EXTENDPKGV", False)
92 self.d.setVar("EXTENDPKGV", "EXTENDPKGV")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 deps = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094 if not deps:
95 self.d.setVar("EXTENDPKGV", orig)
96 return
97 deps = bb.utils.explode_dep_versions2(deps)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060098 newdeps = collections.OrderedDict()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050099 for dep in deps:
100 newdeps[self.map_depends(dep)] = deps[dep]
101
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500102 if not varname.endswith("_NONML"):
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500103 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 Williamsc124f4f2015-09-15 14:41:29 -0500107 self.d.setVar("EXTENDPKGV", orig)
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500108 return ret
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109
110 def map_packagevars(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500111 for pkg in (self.d.getVar("PACKAGES").split() + [""]):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 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 Bishop6e60e8b2018-02-01 10:27:11 -0500121 for pkg in (self.d.getVar("PACKAGES") or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 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 Geissler1e34c2d2020-05-29 16:02:59 -0500127 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 Williamsc124f4f2015-09-15 14:41:29 -0500139
140 def rename_package_variables(self, variables):
141 for pkg_mapping in self.pkgs_mapping:
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500142 if pkg_mapping[0].startswith("${") and pkg_mapping[0].endswith("}"):
143 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 for subs in variables:
145 self.d.renameVar("%s_%s" % (subs, pkg_mapping[0]), "%s_%s" % (subs, pkg_mapping[1]))
146
147class NativesdkClassExtender(ClassExtender):
148 def map_depends(self, dep):
149 if dep.startswith(self.extname):
150 return dep
Brad Bishop19323692019-04-05 15:28:33 -0400151 if dep.endswith(("-gcc", "-g++")):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152 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)