blob: f02fbe9fbadd2347a9acdf6a5ab20422e300382f [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
Brad Bishopa34c0302019-09-23 22:34:48 -040027 if name.startswith("/"):
28 return name
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 if not name.startswith(self.extname):
30 return self.extname + "-" + name
31 return name
32
33 def map_variable(self, varname, setvar = True):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035 if not var:
36 return ""
37 var = var.split()
38 newvar = []
39 for v in var:
40 newvar.append(self.extend_name(v))
41 newdata = " ".join(newvar)
42 if setvar:
43 self.d.setVar(varname, newdata)
44 return newdata
45
46 def map_regexp_variable(self, varname, setvar = True):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047 var = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048 if not var:
49 return ""
50 var = var.split()
51 newvar = []
52 for v in var:
53 if v.startswith("^" + self.extname):
54 newvar.append(v)
55 elif v.startswith("^"):
56 newvar.append("^" + self.extname + "-" + v[1:])
57 else:
58 newvar.append(self.extend_name(v))
59 newdata = " ".join(newvar)
60 if setvar:
61 self.d.setVar(varname, newdata)
62 return newdata
63
64 def map_depends(self, dep):
65 if dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('cross-canadian' in dep) or ('-crosssdk-' in dep):
66 return dep
67 else:
68 # Do not extend for that already have multilib prefix
Brad Bishop6e60e8b2018-02-01 10:27:11 -050069 var = self.d.getVar("MULTILIB_VARIANTS")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070 if var:
71 var = var.split()
72 for v in var:
73 if dep.startswith(v):
74 return dep
75 return self.extend_name(dep)
76
77 def map_depends_variable(self, varname, suffix = ""):
78 # We need to preserve EXTENDPKGV so it can be expanded correctly later
79 if suffix:
80 varname = varname + "_" + suffix
81 orig = self.d.getVar("EXTENDPKGV", False)
82 self.d.setVar("EXTENDPKGV", "EXTENDPKGV")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050083 deps = self.d.getVar(varname)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 if not deps:
85 self.d.setVar("EXTENDPKGV", orig)
86 return
87 deps = bb.utils.explode_dep_versions2(deps)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060088 newdeps = collections.OrderedDict()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089 for dep in deps:
90 newdeps[self.map_depends(dep)] = deps[dep]
91
92 self.d.setVar(varname, bb.utils.join_deps(newdeps, False).replace("EXTENDPKGV", "${EXTENDPKGV}"))
93 self.d.setVar("EXTENDPKGV", orig)
94
95 def map_packagevars(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050096 for pkg in (self.d.getVar("PACKAGES").split() + [""]):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 self.map_depends_variable("RDEPENDS", pkg)
98 self.map_depends_variable("RRECOMMENDS", pkg)
99 self.map_depends_variable("RSUGGESTS", pkg)
100 self.map_depends_variable("RPROVIDES", pkg)
101 self.map_depends_variable("RREPLACES", pkg)
102 self.map_depends_variable("RCONFLICTS", pkg)
103 self.map_depends_variable("PKG", pkg)
104
105 def rename_packages(self):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500106 for pkg in (self.d.getVar("PACKAGES") or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 if pkg.startswith(self.extname):
108 self.pkgs_mapping.append([pkg.split(self.extname + "-")[1], pkg])
109 continue
110 self.pkgs_mapping.append([pkg, self.extend_name(pkg)])
111
112 self.d.setVar("PACKAGES", " ".join([row[1] for row in self.pkgs_mapping]))
113
114 def rename_package_variables(self, variables):
115 for pkg_mapping in self.pkgs_mapping:
116 for subs in variables:
117 self.d.renameVar("%s_%s" % (subs, pkg_mapping[0]), "%s_%s" % (subs, pkg_mapping[1]))
118
119class NativesdkClassExtender(ClassExtender):
120 def map_depends(self, dep):
121 if dep.startswith(self.extname):
122 return dep
Brad Bishop19323692019-04-05 15:28:33 -0400123 if dep.endswith(("-gcc", "-g++")):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500124 return dep + "-crosssdk"
125 elif dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('-cross-' in dep) or ('-crosssdk-' in dep):
126 return dep
127 else:
128 return self.extend_name(dep)