blob: 5107ecde26264ecee8750249c72e55e30a7b43ae [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001class ClassExtender(object):
2 def __init__(self, extname, d):
3 self.extname = extname
4 self.d = d
5 self.pkgs_mapping = []
6
7 def extend_name(self, name):
8 if name.startswith("kernel-") or name == "virtual/kernel":
9 return name
10 if name.startswith("rtld"):
11 return name
12 if name.endswith("-crosssdk"):
13 return name
14 if name.endswith("-" + self.extname):
15 name = name.replace("-" + self.extname, "")
16 if name.startswith("virtual/"):
17 subs = name.split("/", 1)[1]
18 if not subs.startswith(self.extname):
19 return "virtual/" + self.extname + "-" + subs
20 return name
21 if not name.startswith(self.extname):
22 return self.extname + "-" + name
23 return name
24
25 def map_variable(self, varname, setvar = True):
26 var = self.d.getVar(varname, True)
27 if not var:
28 return ""
29 var = var.split()
30 newvar = []
31 for v in var:
32 newvar.append(self.extend_name(v))
33 newdata = " ".join(newvar)
34 if setvar:
35 self.d.setVar(varname, newdata)
36 return newdata
37
38 def map_regexp_variable(self, varname, setvar = True):
39 var = self.d.getVar(varname, True)
40 if not var:
41 return ""
42 var = var.split()
43 newvar = []
44 for v in var:
45 if v.startswith("^" + self.extname):
46 newvar.append(v)
47 elif v.startswith("^"):
48 newvar.append("^" + self.extname + "-" + v[1:])
49 else:
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_depends(self, dep):
57 if dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('cross-canadian' in dep) or ('-crosssdk-' in dep):
58 return dep
59 else:
60 # Do not extend for that already have multilib prefix
61 var = self.d.getVar("MULTILIB_VARIANTS", True)
62 if var:
63 var = var.split()
64 for v in var:
65 if dep.startswith(v):
66 return dep
67 return self.extend_name(dep)
68
69 def map_depends_variable(self, varname, suffix = ""):
70 # We need to preserve EXTENDPKGV so it can be expanded correctly later
71 if suffix:
72 varname = varname + "_" + suffix
73 orig = self.d.getVar("EXTENDPKGV", False)
74 self.d.setVar("EXTENDPKGV", "EXTENDPKGV")
75 deps = self.d.getVar(varname, True)
76 if not deps:
77 self.d.setVar("EXTENDPKGV", orig)
78 return
79 deps = bb.utils.explode_dep_versions2(deps)
80 newdeps = {}
81 for dep in deps:
82 newdeps[self.map_depends(dep)] = deps[dep]
83
84 self.d.setVar(varname, bb.utils.join_deps(newdeps, False).replace("EXTENDPKGV", "${EXTENDPKGV}"))
85 self.d.setVar("EXTENDPKGV", orig)
86
87 def map_packagevars(self):
88 for pkg in (self.d.getVar("PACKAGES", True).split() + [""]):
89 self.map_depends_variable("RDEPENDS", pkg)
90 self.map_depends_variable("RRECOMMENDS", pkg)
91 self.map_depends_variable("RSUGGESTS", pkg)
92 self.map_depends_variable("RPROVIDES", pkg)
93 self.map_depends_variable("RREPLACES", pkg)
94 self.map_depends_variable("RCONFLICTS", pkg)
95 self.map_depends_variable("PKG", pkg)
96
97 def rename_packages(self):
98 for pkg in (self.d.getVar("PACKAGES", True) or "").split():
99 if pkg.startswith(self.extname):
100 self.pkgs_mapping.append([pkg.split(self.extname + "-")[1], pkg])
101 continue
102 self.pkgs_mapping.append([pkg, self.extend_name(pkg)])
103
104 self.d.setVar("PACKAGES", " ".join([row[1] for row in self.pkgs_mapping]))
105
106 def rename_package_variables(self, variables):
107 for pkg_mapping in self.pkgs_mapping:
108 for subs in variables:
109 self.d.renameVar("%s_%s" % (subs, pkg_mapping[0]), "%s_%s" % (subs, pkg_mapping[1]))
110
111class NativesdkClassExtender(ClassExtender):
112 def map_depends(self, dep):
113 if dep.startswith(self.extname):
114 return dep
115 if dep.endswith(("-gcc-initial", "-gcc", "-g++")):
116 return dep + "-crosssdk"
117 elif dep.endswith(("-native", "-native-runtime")) or ('nativesdk-' in dep) or ('-cross-' in dep) or ('-crosssdk-' in dep):
118 return dep
119 else:
120 return self.extend_name(dep)