blob: e25122e815b6312bd9d469cb1a73b24c77433936 [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007class ClassExtender(object):
8 def __init__(self, extname, d):
9 self.extname = extname
10 self.d = d
11 self.pkgs_mapping = []
12
13 def extend_name(self, name):
14 if name.startswith("kernel-") or name == "virtual/kernel":
15 return name
16 if name.startswith("rtld"):
17 return name
18 if name.endswith("-crosssdk"):
19 return name
20 if name.endswith("-" + self.extname):
21 name = name.replace("-" + self.extname, "")
22 if name.startswith("virtual/"):
23 subs = name.split("/", 1)[1]
24 if not subs.startswith(self.extname):
25 return "virtual/" + self.extname + "-" + subs
26 return name
27 if not name.startswith(self.extname):
28 return self.extname + "-" + name
29 return name
30
31 def map_variable(self, varname, setvar = True):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 if not var:
34 return ""
35 var = var.split()
36 newvar = []
37 for v in var:
38 newvar.append(self.extend_name(v))
39 newdata = " ".join(newvar)
40 if setvar:
41 self.d.setVar(varname, newdata)
42 return newdata
43
44 def map_regexp_variable(self, varname, setvar = True):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050045 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 if not var:
47 return ""
48 var = var.split()
49 newvar = []
50 for v in var:
51 if v.startswith("^" + self.extname):
52 newvar.append(v)
53 elif v.startswith("^"):
54 newvar.append("^" + self.extname + "-" + v[1:])
55 else:
56 newvar.append(self.extend_name(v))
57 newdata = " ".join(newvar)
58 if setvar:
59 self.d.setVar(varname, newdata)
60 return newdata
61
62 def map_depends(self, dep):
63 if dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('cross-canadian' in dep) or ('-crosssdk-' in dep):
64 return dep
65 else:
66 # Do not extend for that already have multilib prefix
Brad Bishop6e60e8b2018-02-01 10:27:11 -050067 var = self.d.getVar("MULTILIB_VARIANTS")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 if var:
69 var = var.split()
70 for v in var:
71 if dep.startswith(v):
72 return dep
73 return self.extend_name(dep)
74
75 def map_depends_variable(self, varname, suffix = ""):
76 # We need to preserve EXTENDPKGV so it can be expanded correctly later
77 if suffix:
78 varname = varname + "_" + suffix
79 orig = self.d.getVar("EXTENDPKGV", False)
80 self.d.setVar("EXTENDPKGV", "EXTENDPKGV")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050081 deps = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082 if not deps:
83 self.d.setVar("EXTENDPKGV", orig)
84 return
85 deps = bb.utils.explode_dep_versions2(deps)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060086 newdeps = collections.OrderedDict()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050087 for dep in deps:
88 newdeps[self.map_depends(dep)] = deps[dep]
89
90 self.d.setVar(varname, bb.utils.join_deps(newdeps, False).replace("EXTENDPKGV", "${EXTENDPKGV}"))
91 self.d.setVar("EXTENDPKGV", orig)
92
93 def map_packagevars(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 for pkg in (self.d.getVar("PACKAGES").split() + [""]):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 self.map_depends_variable("RDEPENDS", pkg)
96 self.map_depends_variable("RRECOMMENDS", pkg)
97 self.map_depends_variable("RSUGGESTS", pkg)
98 self.map_depends_variable("RPROVIDES", pkg)
99 self.map_depends_variable("RREPLACES", pkg)
100 self.map_depends_variable("RCONFLICTS", pkg)
101 self.map_depends_variable("PKG", pkg)
102
103 def rename_packages(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500104 for pkg in (self.d.getVar("PACKAGES") or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 if pkg.startswith(self.extname):
106 self.pkgs_mapping.append([pkg.split(self.extname + "-")[1], pkg])
107 continue
108 self.pkgs_mapping.append([pkg, self.extend_name(pkg)])
109
110 self.d.setVar("PACKAGES", " ".join([row[1] for row in self.pkgs_mapping]))
111
112 def rename_package_variables(self, variables):
113 for pkg_mapping in self.pkgs_mapping:
114 for subs in variables:
115 self.d.renameVar("%s_%s" % (subs, pkg_mapping[0]), "%s_%s" % (subs, pkg_mapping[1]))
116
117class NativesdkClassExtender(ClassExtender):
118 def map_depends(self, dep):
119 if dep.startswith(self.extname):
120 return dep
Brad Bishop19323692019-04-05 15:28:33 -0400121 if dep.endswith(("-gcc", "-g++")):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 return dep + "-crosssdk"
123 elif dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('-cross-' in dep) or ('-crosssdk-' in dep):
124 return dep
125 else:
126 return self.extend_name(dep)