Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # |
| 4 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 5 | import collections |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | class 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 Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 27 | if name.startswith("/"): |
| 28 | return name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | if not name.startswith(self.extname): |
| 30 | return self.extname + "-" + name |
| 31 | return name |
| 32 | |
| 33 | def map_variable(self, varname, setvar = True): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | var = self.d.getVar(varname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | var = self.d.getVar(varname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 69 | var = self.d.getVar("MULTILIB_VARIANTS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 83 | deps = self.d.getVar(varname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | if not deps: |
| 85 | self.d.setVar("EXTENDPKGV", orig) |
| 86 | return |
| 87 | deps = bb.utils.explode_dep_versions2(deps) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 88 | newdeps = collections.OrderedDict() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 96 | for pkg in (self.d.getVar("PACKAGES").split() + [""]): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 97 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | for pkg in (self.d.getVar("PACKAGES") or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | 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 | |
| 119 | class NativesdkClassExtender(ClassExtender): |
| 120 | def map_depends(self, dep): |
| 121 | if dep.startswith(self.extname): |
| 122 | return dep |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 123 | if dep.endswith(("-gcc", "-g++")): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | 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) |