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