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 | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | from abc import ABCMeta, abstractmethod |
| 6 | import os |
| 7 | import glob |
| 8 | import subprocess |
| 9 | import shutil |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | import re |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | import collections |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | import bb |
| 13 | import tempfile |
| 14 | import oe.utils |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 15 | import oe.path |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 16 | import string |
| 17 | from oe.gpg_sign import get_signer |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 18 | import hashlib |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 19 | import fnmatch |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | |
| 21 | # this can be used by all PM backends to create the index files in parallel |
| 22 | def create_index(arg): |
| 23 | index_cmd = arg |
| 24 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 25 | bb.note("Executing '%s' ..." % index_cmd) |
| 26 | result = subprocess.check_output(index_cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | if result: |
| 28 | bb.note(result) |
| 29 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 30 | def opkg_query(cmd_output): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 31 | """ |
| 32 | This method parse the output from the package managerand return |
| 33 | a dictionary with the information of the packages. This is used |
| 34 | when the packages are in deb or ipk format. |
| 35 | """ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | verregex = re.compile(r' \([=<>]* [^ )]*\)') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 37 | output = dict() |
| 38 | pkg = "" |
| 39 | arch = "" |
| 40 | ver = "" |
| 41 | filename = "" |
| 42 | dep = [] |
| 43 | pkgarch = "" |
| 44 | for line in cmd_output.splitlines(): |
| 45 | line = line.rstrip() |
| 46 | if ':' in line: |
| 47 | if line.startswith("Package: "): |
| 48 | pkg = line.split(": ")[1] |
| 49 | elif line.startswith("Architecture: "): |
| 50 | arch = line.split(": ")[1] |
| 51 | elif line.startswith("Version: "): |
| 52 | ver = line.split(": ")[1] |
| 53 | elif line.startswith("File: ") or line.startswith("Filename:"): |
| 54 | filename = line.split(": ")[1] |
| 55 | if "/" in filename: |
| 56 | filename = os.path.basename(filename) |
| 57 | elif line.startswith("Depends: "): |
| 58 | depends = verregex.sub('', line.split(": ")[1]) |
| 59 | for depend in depends.split(", "): |
| 60 | dep.append(depend) |
| 61 | elif line.startswith("Recommends: "): |
| 62 | recommends = verregex.sub('', line.split(": ")[1]) |
| 63 | for recommend in recommends.split(", "): |
| 64 | dep.append("%s [REC]" % recommend) |
| 65 | elif line.startswith("PackageArch: "): |
| 66 | pkgarch = line.split(": ")[1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 68 | # When there is a blank line save the package information |
| 69 | elif not line: |
| 70 | # IPK doesn't include the filename |
| 71 | if not filename: |
| 72 | filename = "%s_%s_%s.ipk" % (pkg, ver, arch) |
| 73 | if pkg: |
| 74 | output[pkg] = {"arch":arch, "ver":ver, |
| 75 | "filename":filename, "deps": dep, "pkgarch":pkgarch } |
| 76 | pkg = "" |
| 77 | arch = "" |
| 78 | ver = "" |
| 79 | filename = "" |
| 80 | dep = [] |
| 81 | pkgarch = "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 83 | if pkg: |
| 84 | if not filename: |
| 85 | filename = "%s_%s_%s.ipk" % (pkg, ver, arch) |
| 86 | output[pkg] = {"arch":arch, "ver":ver, |
| 87 | "filename":filename, "deps": dep } |
| 88 | |
| 89 | return output |
| 90 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 91 | def failed_postinsts_abort(pkgs, log_path): |
| 92 | bb.fatal("""Postinstall scriptlets of %s have failed. If the intention is to defer them to first boot, |
| 93 | then please place them into pkg_postinst_ontarget_${PN} (). |
| 94 | Deferring to first boot via 'exit 1' is no longer supported. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 95 | Details of the failure are in %s.""" %(pkgs, log_path)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 96 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 97 | def generate_locale_archive(d, rootfs, target_arch, localedir): |
| 98 | # Pretty sure we don't need this for locale archive generation but |
| 99 | # keeping it to be safe... |
| 100 | locale_arch_options = { \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 101 | "arc": ["--uint32-align=4", "--little-endian"], |
| 102 | "arceb": ["--uint32-align=4", "--big-endian"], |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 103 | "arm": ["--uint32-align=4", "--little-endian"], |
| 104 | "armeb": ["--uint32-align=4", "--big-endian"], |
| 105 | "aarch64": ["--uint32-align=4", "--little-endian"], |
| 106 | "aarch64_be": ["--uint32-align=4", "--big-endian"], |
| 107 | "sh4": ["--uint32-align=4", "--big-endian"], |
| 108 | "powerpc": ["--uint32-align=4", "--big-endian"], |
| 109 | "powerpc64": ["--uint32-align=4", "--big-endian"], |
| 110 | "mips": ["--uint32-align=4", "--big-endian"], |
| 111 | "mipsisa32r6": ["--uint32-align=4", "--big-endian"], |
| 112 | "mips64": ["--uint32-align=4", "--big-endian"], |
| 113 | "mipsisa64r6": ["--uint32-align=4", "--big-endian"], |
| 114 | "mipsel": ["--uint32-align=4", "--little-endian"], |
| 115 | "mipsisa32r6el": ["--uint32-align=4", "--little-endian"], |
| 116 | "mips64el": ["--uint32-align=4", "--little-endian"], |
| 117 | "mipsisa64r6el": ["--uint32-align=4", "--little-endian"], |
| 118 | "riscv64": ["--uint32-align=4", "--little-endian"], |
| 119 | "riscv32": ["--uint32-align=4", "--little-endian"], |
| 120 | "i586": ["--uint32-align=4", "--little-endian"], |
| 121 | "i686": ["--uint32-align=4", "--little-endian"], |
| 122 | "x86_64": ["--uint32-align=4", "--little-endian"] |
| 123 | } |
| 124 | if target_arch in locale_arch_options: |
| 125 | arch_options = locale_arch_options[target_arch] |
| 126 | else: |
| 127 | bb.error("locale_arch_options not found for target_arch=" + target_arch) |
| 128 | bb.fatal("unknown arch:" + target_arch + " for locale_arch_options") |
| 129 | |
| 130 | # Need to set this so cross-localedef knows where the archive is |
| 131 | env = dict(os.environ) |
| 132 | env["LOCALEARCHIVE"] = oe.path.join(localedir, "locale-archive") |
| 133 | |
| 134 | for name in os.listdir(localedir): |
| 135 | path = os.path.join(localedir, name) |
| 136 | if os.path.isdir(path): |
| 137 | cmd = ["cross-localedef", "--verbose"] |
| 138 | cmd += arch_options |
| 139 | cmd += ["--add-to-archive", path] |
| 140 | subprocess.check_output(cmd, env=env, stderr=subprocess.STDOUT) |
| 141 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 142 | class Indexer(object, metaclass=ABCMeta): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | def __init__(self, d, deploy_dir): |
| 144 | self.d = d |
| 145 | self.deploy_dir = deploy_dir |
| 146 | |
| 147 | @abstractmethod |
| 148 | def write_index(self): |
| 149 | pass |
| 150 | |
| 151 | |
| 152 | class RpmIndexer(Indexer): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 153 | def write_index(self): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 154 | self.do_write_index(self.deploy_dir) |
| 155 | |
| 156 | def do_write_index(self, deploy_dir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 157 | if self.d.getVar('PACKAGE_FEED_SIGN') == '1': |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 158 | signer = get_signer(self.d, self.d.getVar('PACKAGE_FEED_GPG_BACKEND')) |
| 159 | else: |
| 160 | signer = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 162 | createrepo_c = bb.utils.which(os.environ['PATH'], "createrepo_c") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 163 | result = create_index("%s --update -q %s" % (createrepo_c, deploy_dir)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | if result: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 165 | bb.fatal(result) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 167 | # Sign repomd |
| 168 | if signer: |
| 169 | sig_type = self.d.getVar('PACKAGE_FEED_GPG_SIGNATURE_TYPE') |
| 170 | is_ascii_sig = (sig_type.upper() != "BIN") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 171 | signer.detach_sign(os.path.join(deploy_dir, 'repodata', 'repomd.xml'), |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 172 | self.d.getVar('PACKAGE_FEED_GPG_NAME'), |
| 173 | self.d.getVar('PACKAGE_FEED_GPG_PASSPHRASE_FILE'), |
| 174 | armor=is_ascii_sig) |
| 175 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 176 | class RpmSubdirIndexer(RpmIndexer): |
| 177 | def write_index(self): |
| 178 | bb.note("Generating package index for %s" %(self.deploy_dir)) |
| 179 | self.do_write_index(self.deploy_dir) |
| 180 | for entry in os.walk(self.deploy_dir): |
| 181 | if os.path.samefile(self.deploy_dir, entry[0]): |
| 182 | for dir in entry[1]: |
| 183 | if dir != 'repodata': |
| 184 | dir_path = oe.path.join(self.deploy_dir, dir) |
| 185 | bb.note("Generating package index for %s" %(dir_path)) |
| 186 | self.do_write_index(dir_path) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 187 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 188 | class OpkgIndexer(Indexer): |
| 189 | def write_index(self): |
| 190 | arch_vars = ["ALL_MULTILIB_PACKAGE_ARCHS", |
| 191 | "SDK_PACKAGE_ARCHS", |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 192 | ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 193 | |
| 194 | opkg_index_cmd = bb.utils.which(os.getenv('PATH'), "opkg-make-index") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 195 | if self.d.getVar('PACKAGE_FEED_SIGN') == '1': |
| 196 | signer = get_signer(self.d, self.d.getVar('PACKAGE_FEED_GPG_BACKEND')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 197 | else: |
| 198 | signer = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | |
| 200 | if not os.path.exists(os.path.join(self.deploy_dir, "Packages")): |
| 201 | open(os.path.join(self.deploy_dir, "Packages"), "w").close() |
| 202 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 203 | index_cmds = set() |
| 204 | index_sign_files = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 205 | for arch_var in arch_vars: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 206 | archs = self.d.getVar(arch_var) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 207 | if archs is None: |
| 208 | continue |
| 209 | |
| 210 | for arch in archs.split(): |
| 211 | pkgs_dir = os.path.join(self.deploy_dir, arch) |
| 212 | pkgs_file = os.path.join(pkgs_dir, "Packages") |
| 213 | |
| 214 | if not os.path.isdir(pkgs_dir): |
| 215 | continue |
| 216 | |
| 217 | if not os.path.exists(pkgs_file): |
| 218 | open(pkgs_file, "w").close() |
| 219 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 220 | index_cmds.add('%s -r %s -p %s -m %s' % |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 221 | (opkg_index_cmd, pkgs_file, pkgs_file, pkgs_dir)) |
| 222 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 223 | index_sign_files.add(pkgs_file) |
| 224 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | if len(index_cmds) == 0: |
| 226 | bb.note("There are no packages in %s!" % self.deploy_dir) |
| 227 | return |
| 228 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 229 | oe.utils.multiprocess_launch(create_index, index_cmds, self.d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 231 | if signer: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 232 | feed_sig_type = self.d.getVar('PACKAGE_FEED_GPG_SIGNATURE_TYPE') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 233 | is_ascii_sig = (feed_sig_type.upper() != "BIN") |
| 234 | for f in index_sign_files: |
| 235 | signer.detach_sign(f, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 236 | self.d.getVar('PACKAGE_FEED_GPG_NAME'), |
| 237 | self.d.getVar('PACKAGE_FEED_GPG_PASSPHRASE_FILE'), |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 238 | armor=is_ascii_sig) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | |
| 240 | |
| 241 | class DpkgIndexer(Indexer): |
| 242 | def _create_configs(self): |
| 243 | bb.utils.mkdirhier(self.apt_conf_dir) |
| 244 | bb.utils.mkdirhier(os.path.join(self.apt_conf_dir, "lists", "partial")) |
| 245 | bb.utils.mkdirhier(os.path.join(self.apt_conf_dir, "apt.conf.d")) |
| 246 | bb.utils.mkdirhier(os.path.join(self.apt_conf_dir, "preferences.d")) |
| 247 | |
| 248 | with open(os.path.join(self.apt_conf_dir, "preferences"), |
| 249 | "w") as prefs_file: |
| 250 | pass |
| 251 | with open(os.path.join(self.apt_conf_dir, "sources.list"), |
| 252 | "w+") as sources_file: |
| 253 | pass |
| 254 | |
| 255 | with open(self.apt_conf_file, "w") as apt_conf: |
| 256 | with open(os.path.join(self.d.expand("${STAGING_ETCDIR_NATIVE}"), |
| 257 | "apt", "apt.conf.sample")) as apt_conf_sample: |
| 258 | for line in apt_conf_sample.read().split("\n"): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 259 | line = re.sub(r"#ROOTFS#", "/dev/null", line) |
| 260 | line = re.sub(r"#APTCONF#", self.apt_conf_dir, line) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 261 | apt_conf.write(line + "\n") |
| 262 | |
| 263 | def write_index(self): |
| 264 | self.apt_conf_dir = os.path.join(self.d.expand("${APTCONF_TARGET}"), |
| 265 | "apt-ftparchive") |
| 266 | self.apt_conf_file = os.path.join(self.apt_conf_dir, "apt.conf") |
| 267 | self._create_configs() |
| 268 | |
| 269 | os.environ['APT_CONFIG'] = self.apt_conf_file |
| 270 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 271 | pkg_archs = self.d.getVar('PACKAGE_ARCHS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 272 | if pkg_archs is not None: |
| 273 | arch_list = pkg_archs.split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 274 | sdk_pkg_archs = self.d.getVar('SDK_PACKAGE_ARCHS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | if sdk_pkg_archs is not None: |
| 276 | for a in sdk_pkg_archs.split(): |
| 277 | if a not in pkg_archs: |
| 278 | arch_list.append(a) |
| 279 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 280 | all_mlb_pkg_arch_list = (self.d.getVar('ALL_MULTILIB_PACKAGE_ARCHS') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | arch_list.extend(arch for arch in all_mlb_pkg_arch_list if arch not in arch_list) |
| 282 | |
| 283 | apt_ftparchive = bb.utils.which(os.getenv('PATH'), "apt-ftparchive") |
| 284 | gzip = bb.utils.which(os.getenv('PATH'), "gzip") |
| 285 | |
| 286 | index_cmds = [] |
| 287 | deb_dirs_found = False |
| 288 | for arch in arch_list: |
| 289 | arch_dir = os.path.join(self.deploy_dir, arch) |
| 290 | if not os.path.isdir(arch_dir): |
| 291 | continue |
| 292 | |
| 293 | cmd = "cd %s; PSEUDO_UNLOAD=1 %s packages . > Packages;" % (arch_dir, apt_ftparchive) |
| 294 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 295 | cmd += "%s -fcn Packages > Packages.gz;" % gzip |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 296 | |
| 297 | with open(os.path.join(arch_dir, "Release"), "w+") as release: |
| 298 | release.write("Label: %s\n" % arch) |
| 299 | |
| 300 | cmd += "PSEUDO_UNLOAD=1 %s release . >> Release" % apt_ftparchive |
| 301 | |
| 302 | index_cmds.append(cmd) |
| 303 | |
| 304 | deb_dirs_found = True |
| 305 | |
| 306 | if not deb_dirs_found: |
| 307 | bb.note("There are no packages in %s" % self.deploy_dir) |
| 308 | return |
| 309 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 310 | oe.utils.multiprocess_launch(create_index, index_cmds, self.d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 311 | if self.d.getVar('PACKAGE_FEED_SIGN') == '1': |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 312 | raise NotImplementedError('Package feed signing not implementd for dpkg') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | |
| 314 | |
| 315 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 316 | class PkgsList(object, metaclass=ABCMeta): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 317 | def __init__(self, d, rootfs_dir): |
| 318 | self.d = d |
| 319 | self.rootfs_dir = rootfs_dir |
| 320 | |
| 321 | @abstractmethod |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 322 | def list_pkgs(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 323 | pass |
| 324 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | class RpmPkgsList(PkgsList): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 326 | def list_pkgs(self): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 327 | return RpmPM(self.d, self.rootfs_dir, self.d.getVar('TARGET_VENDOR'), needfeed=False).list_installed() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 328 | |
| 329 | class OpkgPkgsList(PkgsList): |
| 330 | def __init__(self, d, rootfs_dir, config_file): |
| 331 | super(OpkgPkgsList, self).__init__(d, rootfs_dir) |
| 332 | |
| 333 | self.opkg_cmd = bb.utils.which(os.getenv('PATH'), "opkg") |
| 334 | self.opkg_args = "-f %s -o %s " % (config_file, rootfs_dir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 335 | self.opkg_args += self.d.getVar("OPKG_ARGS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 336 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 337 | def list_pkgs(self, format=None): |
| 338 | cmd = "%s %s status" % (self.opkg_cmd, self.opkg_args) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 339 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 340 | # opkg returns success even when it printed some |
| 341 | # "Collected errors:" report to stderr. Mixing stderr into |
| 342 | # stdout then leads to random failures later on when |
| 343 | # parsing the output. To avoid this we need to collect both |
| 344 | # output streams separately and check for empty stderr. |
| 345 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) |
| 346 | cmd_output, cmd_stderr = p.communicate() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 347 | cmd_output = cmd_output.decode("utf-8") |
| 348 | cmd_stderr = cmd_stderr.decode("utf-8") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 349 | if p.returncode or cmd_stderr: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 350 | bb.fatal("Cannot get the installed packages list. Command '%s' " |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 351 | "returned %d and stderr:\n%s" % (cmd, p.returncode, cmd_stderr)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 352 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 353 | return opkg_query(cmd_output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 354 | |
| 355 | |
| 356 | class DpkgPkgsList(PkgsList): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 357 | |
| 358 | def list_pkgs(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 359 | cmd = [bb.utils.which(os.getenv('PATH'), "dpkg-query"), |
| 360 | "--admindir=%s/var/lib/dpkg" % self.rootfs_dir, |
| 361 | "-W"] |
| 362 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 363 | cmd.append("-f=Package: ${Package}\nArchitecture: ${PackageArch}\nVersion: ${Version}\nFile: ${Package}_${Version}_${Architecture}.deb\nDepends: ${Depends}\nRecommends: ${Recommends}\n\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 364 | |
| 365 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 366 | cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip().decode("utf-8") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | except subprocess.CalledProcessError as e: |
| 368 | bb.fatal("Cannot get the installed packages list. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 369 | "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 370 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 371 | return opkg_query(cmd_output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | |
| 373 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 374 | class PackageManager(object, metaclass=ABCMeta): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 375 | """ |
| 376 | This is an abstract class. Do not instantiate this directly. |
| 377 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 378 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 379 | def __init__(self, d, target_rootfs): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 380 | self.d = d |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 381 | self.target_rootfs = target_rootfs |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 382 | self.deploy_dir = None |
| 383 | self.deploy_lock = None |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 384 | self._initialize_intercepts() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 385 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 386 | def _initialize_intercepts(self): |
| 387 | bb.note("Initializing intercept dir for %s" % self.target_rootfs) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 388 | # As there might be more than one instance of PackageManager operating at the same time |
| 389 | # we need to isolate the intercept_scripts directories from each other, |
| 390 | # hence the ugly hash digest in dir name. |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 391 | self.intercepts_dir = os.path.join(self.d.getVar('WORKDIR'), "intercept_scripts-%s" % |
| 392 | (hashlib.sha256(self.target_rootfs.encode()).hexdigest())) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 393 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 394 | postinst_intercepts = (self.d.getVar("POSTINST_INTERCEPTS") or "").split() |
| 395 | if not postinst_intercepts: |
| 396 | postinst_intercepts_path = self.d.getVar("POSTINST_INTERCEPTS_PATH") |
| 397 | if not postinst_intercepts_path: |
| 398 | postinst_intercepts_path = self.d.getVar("POSTINST_INTERCEPTS_DIR") or self.d.expand("${COREBASE}/scripts/postinst-intercepts") |
| 399 | postinst_intercepts = oe.path.which_wild('*', postinst_intercepts_path) |
| 400 | |
| 401 | bb.debug(1, 'Collected intercepts:\n%s' % ''.join(' %s\n' % i for i in postinst_intercepts)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 402 | bb.utils.remove(self.intercepts_dir, True) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 403 | bb.utils.mkdirhier(self.intercepts_dir) |
| 404 | for intercept in postinst_intercepts: |
| 405 | bb.utils.copyfile(intercept, os.path.join(self.intercepts_dir, os.path.basename(intercept))) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 406 | |
| 407 | @abstractmethod |
| 408 | def _handle_intercept_failure(self, failed_script): |
| 409 | pass |
| 410 | |
| 411 | def _postpone_to_first_boot(self, postinst_intercept_hook): |
| 412 | with open(postinst_intercept_hook) as intercept: |
| 413 | registered_pkgs = None |
| 414 | for line in intercept.read().split("\n"): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 415 | m = re.match(r"^##PKGS:(.*)", line) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 416 | if m is not None: |
| 417 | registered_pkgs = m.group(1).strip() |
| 418 | break |
| 419 | |
| 420 | if registered_pkgs is not None: |
| 421 | bb.note("If an image is being built, the postinstalls for the following packages " |
| 422 | "will be postponed for first boot: %s" % |
| 423 | registered_pkgs) |
| 424 | |
| 425 | # call the backend dependent handler |
| 426 | self._handle_intercept_failure(registered_pkgs) |
| 427 | |
| 428 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 429 | def run_intercepts(self, populate_sdk=None): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 430 | intercepts_dir = self.intercepts_dir |
| 431 | |
| 432 | bb.note("Running intercept scripts:") |
| 433 | os.environ['D'] = self.target_rootfs |
| 434 | os.environ['STAGING_DIR_NATIVE'] = self.d.getVar('STAGING_DIR_NATIVE') |
| 435 | for script in os.listdir(intercepts_dir): |
| 436 | script_full = os.path.join(intercepts_dir, script) |
| 437 | |
| 438 | if script == "postinst_intercept" or not os.access(script_full, os.X_OK): |
| 439 | continue |
| 440 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 441 | # we do not want to run any multilib variant of this |
| 442 | if script.startswith("delay_to_first_boot"): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 443 | self._postpone_to_first_boot(script_full) |
| 444 | continue |
| 445 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 446 | if populate_sdk == 'host' and self.d.getVar('SDK_OS') == 'mingw32': |
| 447 | bb.note("The postinstall intercept hook '%s' could not be executed due to missing wine support, details in %s/log.do_%s" |
| 448 | % (script, self.d.getVar('T'), self.d.getVar('BB_CURRENTTASK'))) |
| 449 | continue |
| 450 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 451 | bb.note("> Executing %s intercept ..." % script) |
| 452 | |
| 453 | try: |
| 454 | output = subprocess.check_output(script_full, stderr=subprocess.STDOUT) |
| 455 | if output: bb.note(output.decode("utf-8")) |
| 456 | except subprocess.CalledProcessError as e: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 457 | bb.note("Exit code %d. Output:\n%s" % (e.returncode, e.output.decode("utf-8"))) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 458 | if populate_sdk == 'host': |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 459 | bb.fatal("The postinstall intercept hook '%s' failed, details in %s/log.do_%s" % (script, self.d.getVar('T'), self.d.getVar('BB_CURRENTTASK'))) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 460 | elif populate_sdk == 'target': |
| 461 | if "qemuwrapper: qemu usermode is not supported" in e.output.decode("utf-8"): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 462 | bb.note("The postinstall intercept hook '%s' could not be executed due to missing qemu usermode support, details in %s/log.do_%s" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 463 | % (script, self.d.getVar('T'), self.d.getVar('BB_CURRENTTASK'))) |
| 464 | else: |
| 465 | bb.fatal("The postinstall intercept hook '%s' failed, details in %s/log.do_%s" % (script, self.d.getVar('T'), self.d.getVar('BB_CURRENTTASK'))) |
| 466 | else: |
| 467 | if "qemuwrapper: qemu usermode is not supported" in e.output.decode("utf-8"): |
| 468 | bb.note("The postinstall intercept hook '%s' could not be executed due to missing qemu usermode support, details in %s/log.do_%s" |
| 469 | % (script, self.d.getVar('T'), self.d.getVar('BB_CURRENTTASK'))) |
| 470 | self._postpone_to_first_boot(script_full) |
| 471 | else: |
| 472 | bb.fatal("The postinstall intercept hook '%s' failed, details in %s/log.do_%s" % (script, self.d.getVar('T'), self.d.getVar('BB_CURRENTTASK'))) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 473 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 474 | @abstractmethod |
| 475 | def update(self): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 476 | """ |
| 477 | Update the package manager package database. |
| 478 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 479 | pass |
| 480 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 481 | @abstractmethod |
| 482 | def install(self, pkgs, attempt_only=False): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 483 | """ |
| 484 | Install a list of packages. 'pkgs' is a list object. If 'attempt_only' is |
| 485 | True, installation failures are ignored. |
| 486 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 487 | pass |
| 488 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 489 | @abstractmethod |
| 490 | def remove(self, pkgs, with_dependencies=True): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 491 | """ |
| 492 | Remove a list of packages. 'pkgs' is a list object. If 'with_dependencies' |
| 493 | is False, then any dependencies are left in place. |
| 494 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 495 | pass |
| 496 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 497 | @abstractmethod |
| 498 | def write_index(self): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 499 | """ |
| 500 | This function creates the index files |
| 501 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 502 | pass |
| 503 | |
| 504 | @abstractmethod |
| 505 | def remove_packaging_data(self): |
| 506 | pass |
| 507 | |
| 508 | @abstractmethod |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 509 | def list_installed(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 510 | pass |
| 511 | |
| 512 | @abstractmethod |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 513 | def extract(self, pkg): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 514 | """ |
| 515 | Returns the path to a tmpdir where resides the contents of a package. |
| 516 | Deleting the tmpdir is responsability of the caller. |
| 517 | """ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 518 | pass |
| 519 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 520 | @abstractmethod |
| 521 | def insert_feeds_uris(self, feed_uris, feed_base_paths, feed_archs): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 522 | """ |
| 523 | Add remote package feeds into repository manager configuration. The parameters |
| 524 | for the feeds are set by feed_uris, feed_base_paths and feed_archs. |
| 525 | See http://www.yoctoproject.org/docs/current/ref-manual/ref-manual.html#var-PACKAGE_FEED_URIS |
| 526 | for their description. |
| 527 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 528 | pass |
| 529 | |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 530 | def install_glob(self, globs, sdk=False): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 531 | """ |
| 532 | Install all packages that match a glob. |
| 533 | """ |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 534 | # TODO don't have sdk here but have a property on the superclass |
| 535 | # (and respect in install_complementary) |
| 536 | if sdk: |
| 537 | pkgdatadir = self.d.expand("${TMPDIR}/pkgdata/${SDK_SYS}") |
| 538 | else: |
| 539 | pkgdatadir = self.d.getVar("PKGDATA_DIR") |
| 540 | |
| 541 | try: |
| 542 | bb.note("Installing globbed packages...") |
| 543 | cmd = ["oe-pkgdata-util", "-p", pkgdatadir, "list-pkgs", globs] |
| 544 | pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8") |
| 545 | self.install(pkgs.split(), attempt_only=True) |
| 546 | except subprocess.CalledProcessError as e: |
| 547 | # Return code 1 means no packages matched |
| 548 | if e.returncode != 1: |
| 549 | bb.fatal("Could not compute globbed packages list. Command " |
| 550 | "'%s' returned %d:\n%s" % |
| 551 | (' '.join(cmd), e.returncode, e.output.decode("utf-8"))) |
| 552 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 553 | def install_complementary(self, globs=None): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 554 | """ |
| 555 | Install complementary packages based upon the list of currently installed |
| 556 | packages e.g. locales, *-dev, *-dbg, etc. This will only attempt to install |
| 557 | these packages, if they don't exist then no error will occur. Note: every |
| 558 | backend needs to call this function explicitly after the normal package |
| 559 | installation |
| 560 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 561 | if globs is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 562 | globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 563 | split_linguas = set() |
| 564 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 565 | for translation in self.d.getVar('IMAGE_LINGUAS').split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 566 | split_linguas.add(translation) |
| 567 | split_linguas.add(translation.split('-')[0]) |
| 568 | |
| 569 | split_linguas = sorted(split_linguas) |
| 570 | |
| 571 | for lang in split_linguas: |
| 572 | globs += " *-locale-%s" % lang |
| 573 | |
| 574 | if globs is None: |
| 575 | return |
| 576 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 577 | # we need to write the list of installed packages to a file because the |
| 578 | # oe-pkgdata-util reads it from a file |
| 579 | with tempfile.NamedTemporaryFile(mode="w+", prefix="installed-pkgs") as installed_pkgs: |
| 580 | pkgs = self.list_installed() |
| 581 | output = oe.utils.format_pkg_list(pkgs, "arch") |
| 582 | installed_pkgs.write(output) |
| 583 | installed_pkgs.flush() |
| 584 | |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 585 | cmd = ["oe-pkgdata-util", |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 586 | "-p", self.d.getVar('PKGDATA_DIR'), "glob", installed_pkgs.name, |
| 587 | globs] |
| 588 | exclude = self.d.getVar('PACKAGE_EXCLUDE_COMPLEMENTARY') |
| 589 | if exclude: |
| 590 | cmd.extend(['--exclude=' + '|'.join(exclude.split())]) |
| 591 | try: |
| 592 | bb.note("Installing complementary packages ...") |
| 593 | bb.note('Running %s' % cmd) |
| 594 | complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8") |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 595 | self.install(complementary_pkgs.split(), attempt_only=True) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 596 | except subprocess.CalledProcessError as e: |
| 597 | bb.fatal("Could not compute complementary packages list. Command " |
| 598 | "'%s' returned %d:\n%s" % |
| 599 | (' '.join(cmd), e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 600 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 601 | target_arch = self.d.getVar('TARGET_ARCH') |
| 602 | localedir = oe.path.join(self.target_rootfs, self.d.getVar("libdir"), "locale") |
| 603 | if os.path.exists(localedir) and os.listdir(localedir): |
| 604 | generate_locale_archive(self.d, self.target_rootfs, target_arch, localedir) |
| 605 | # And now delete the binary locales |
| 606 | self.remove(fnmatch.filter(self.list_installed(), "glibc-binary-localedata-*"), False) |
| 607 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 608 | def deploy_dir_lock(self): |
| 609 | if self.deploy_dir is None: |
| 610 | raise RuntimeError("deploy_dir is not set!") |
| 611 | |
| 612 | lock_file_name = os.path.join(self.deploy_dir, "deploy.lock") |
| 613 | |
| 614 | self.deploy_lock = bb.utils.lockfile(lock_file_name) |
| 615 | |
| 616 | def deploy_dir_unlock(self): |
| 617 | if self.deploy_lock is None: |
| 618 | return |
| 619 | |
| 620 | bb.utils.unlockfile(self.deploy_lock) |
| 621 | |
| 622 | self.deploy_lock = None |
| 623 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 624 | def construct_uris(self, uris, base_paths): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 625 | """ |
| 626 | Construct URIs based on the following pattern: uri/base_path where 'uri' |
| 627 | and 'base_path' correspond to each element of the corresponding array |
| 628 | argument leading to len(uris) x len(base_paths) elements on the returned |
| 629 | array |
| 630 | """ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 631 | def _append(arr1, arr2, sep='/'): |
| 632 | res = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 633 | narr1 = [a.rstrip(sep) for a in arr1] |
| 634 | narr2 = [a.rstrip(sep).lstrip(sep) for a in arr2] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 635 | for a1 in narr1: |
| 636 | if arr2: |
| 637 | for a2 in narr2: |
| 638 | res.append("%s%s%s" % (a1, sep, a2)) |
| 639 | else: |
| 640 | res.append(a1) |
| 641 | return res |
| 642 | return _append(uris, base_paths) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 643 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 644 | def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencies): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 645 | """ |
| 646 | Go through our do_package_write_X dependencies and hardlink the packages we depend |
| 647 | upon into the repo directory. This prevents us seeing other packages that may |
| 648 | have been built that we don't depend upon and also packages for architectures we don't |
| 649 | support. |
| 650 | """ |
| 651 | import errno |
| 652 | |
| 653 | taskdepdata = d.getVar("BB_TASKDEPDATA", False) |
| 654 | mytaskname = d.getVar("BB_RUNTASK") |
| 655 | pn = d.getVar("PN") |
| 656 | seendirs = set() |
| 657 | multilibs = {} |
| 658 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 659 | bb.utils.remove(subrepo_dir, recurse=True) |
| 660 | bb.utils.mkdirhier(subrepo_dir) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 661 | |
| 662 | # Detect bitbake -b usage |
| 663 | nodeps = d.getVar("BB_LIMITEDDEPS") or False |
| 664 | if nodeps or not filterbydependencies: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 665 | oe.path.symlink(deploydir, subrepo_dir, True) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 666 | return |
| 667 | |
| 668 | start = None |
| 669 | for dep in taskdepdata: |
| 670 | data = taskdepdata[dep] |
| 671 | if data[1] == mytaskname and data[0] == pn: |
| 672 | start = dep |
| 673 | break |
| 674 | if start is None: |
| 675 | bb.fatal("Couldn't find ourself in BB_TASKDEPDATA?") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 676 | pkgdeps = set() |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 677 | start = [start] |
| 678 | seen = set(start) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 679 | # Support direct dependencies (do_rootfs -> do_package_write_X) |
| 680 | # or indirect dependencies within PN (do_populate_sdk_ext -> do_rootfs -> do_package_write_X) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 681 | while start: |
| 682 | next = [] |
| 683 | for dep2 in start: |
| 684 | for dep in taskdepdata[dep2][3]: |
| 685 | if taskdepdata[dep][0] != pn: |
| 686 | if "do_" + taskname in dep: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 687 | pkgdeps.add(dep) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 688 | elif dep not in seen: |
| 689 | next.append(dep) |
| 690 | seen.add(dep) |
| 691 | start = next |
| 692 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 693 | for dep in pkgdeps: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 694 | c = taskdepdata[dep][0] |
| 695 | manifest, d2 = oe.sstatesig.find_sstate_manifest(c, taskdepdata[dep][2], taskname, d, multilibs) |
| 696 | if not manifest: |
| 697 | bb.fatal("No manifest generated from: %s in %s" % (c, taskdepdata[dep][2])) |
| 698 | if not os.path.exists(manifest): |
| 699 | continue |
| 700 | with open(manifest, "r") as f: |
| 701 | for l in f: |
| 702 | l = l.strip() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 703 | deploydir = os.path.normpath(deploydir) |
| 704 | if bb.data.inherits_class('packagefeed-stability', d): |
| 705 | dest = l.replace(deploydir + "-prediff", "") |
| 706 | else: |
| 707 | dest = l.replace(deploydir, "") |
| 708 | dest = subrepo_dir + dest |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 709 | if l.endswith("/"): |
| 710 | if dest not in seendirs: |
| 711 | bb.utils.mkdirhier(dest) |
| 712 | seendirs.add(dest) |
| 713 | continue |
| 714 | # Try to hardlink the file, copy if that fails |
| 715 | destdir = os.path.dirname(dest) |
| 716 | if destdir not in seendirs: |
| 717 | bb.utils.mkdirhier(destdir) |
| 718 | seendirs.add(destdir) |
| 719 | try: |
| 720 | os.link(l, dest) |
| 721 | except OSError as err: |
| 722 | if err.errno == errno.EXDEV: |
| 723 | bb.utils.copyfile(l, dest) |
| 724 | else: |
| 725 | raise |
| 726 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 727 | class RpmPM(PackageManager): |
| 728 | def __init__(self, |
| 729 | d, |
| 730 | target_rootfs, |
| 731 | target_vendor, |
| 732 | task_name='target', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 733 | arch_var=None, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 734 | os_var=None, |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 735 | rpm_repo_workdir="oe-rootfs-repo", |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 736 | filterbydependencies=True, |
| 737 | needfeed=True): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 738 | super(RpmPM, self).__init__(d, target_rootfs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 739 | self.target_vendor = target_vendor |
| 740 | self.task_name = task_name |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 741 | if arch_var == None: |
| 742 | self.archs = self.d.getVar('ALL_MULTILIB_PACKAGE_ARCHS').replace("-","_") |
| 743 | else: |
| 744 | self.archs = self.d.getVar(arch_var).replace("-","_") |
| 745 | if task_name == "host": |
| 746 | self.primary_arch = self.d.getVar('SDK_ARCH') |
| 747 | else: |
| 748 | self.primary_arch = self.d.getVar('MACHINE_ARCH') |
| 749 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 750 | if needfeed: |
| 751 | self.rpm_repo_dir = oe.path.join(self.d.getVar('WORKDIR'), rpm_repo_workdir) |
| 752 | create_packages_dir(self.d, oe.path.join(self.rpm_repo_dir, "rpm"), d.getVar("DEPLOY_DIR_RPM"), "package_write_rpm", filterbydependencies) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 753 | |
| 754 | self.saved_packaging_data = self.d.expand('${T}/saved_packaging_data/%s' % self.task_name) |
| 755 | if not os.path.exists(self.d.expand('${T}/saved_packaging_data')): |
| 756 | bb.utils.mkdirhier(self.d.expand('${T}/saved_packaging_data')) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 757 | self.packaging_data_dirs = ['etc/rpm', 'etc/rpmrc', 'etc/dnf', 'var/lib/rpm', 'var/lib/dnf', 'var/cache/dnf'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 758 | self.solution_manifest = self.d.expand('${T}/saved/%s_solution' % |
| 759 | self.task_name) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 760 | if not os.path.exists(self.d.expand('${T}/saved')): |
| 761 | bb.utils.mkdirhier(self.d.expand('${T}/saved')) |
| 762 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 763 | def _configure_dnf(self): |
| 764 | # libsolv handles 'noarch' internally, we don't need to specify it explicitly |
| 765 | archs = [i for i in reversed(self.archs.split()) if i not in ["any", "all", "noarch"]] |
| 766 | # This prevents accidental matching against libsolv's built-in policies |
| 767 | if len(archs) <= 1: |
| 768 | archs = archs + ["bogusarch"] |
| 769 | confdir = "%s/%s" %(self.target_rootfs, "etc/dnf/vars/") |
| 770 | bb.utils.mkdirhier(confdir) |
| 771 | open(confdir + "arch", 'w').write(":".join(archs)) |
| 772 | distro_codename = self.d.getVar('DISTRO_CODENAME') |
| 773 | open(confdir + "releasever", 'w').write(distro_codename if distro_codename is not None else '') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 774 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 775 | open(oe.path.join(self.target_rootfs, "etc/dnf/dnf.conf"), 'w').write("") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 776 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 777 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 778 | def _configure_rpm(self): |
| 779 | # We need to configure rpm to use our primary package architecture as the installation architecture, |
| 780 | # and to make it compatible with other package architectures that we use. |
| 781 | # Otherwise it will refuse to proceed with packages installation. |
| 782 | platformconfdir = "%s/%s" %(self.target_rootfs, "etc/rpm/") |
| 783 | rpmrcconfdir = "%s/%s" %(self.target_rootfs, "etc/") |
| 784 | bb.utils.mkdirhier(platformconfdir) |
| 785 | open(platformconfdir + "platform", 'w').write("%s-pc-linux" % self.primary_arch) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 786 | with open(rpmrcconfdir + "rpmrc", 'w') as f: |
| 787 | f.write("arch_compat: %s: %s\n" % (self.primary_arch, self.archs if len(self.archs) > 0 else self.primary_arch)) |
| 788 | f.write("buildarch_compat: %s: noarch\n" % self.primary_arch) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 789 | |
| 790 | open(platformconfdir + "macros", 'w').write("%_transaction_color 7\n") |
| 791 | if self.d.getVar('RPM_PREFER_ELF_ARCH'): |
| 792 | open(platformconfdir + "macros", 'a').write("%%_prefer_color %s" % (self.d.getVar('RPM_PREFER_ELF_ARCH'))) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 793 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 794 | open(platformconfdir + "macros", 'a').write("%_prefer_color 7") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 795 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 796 | if self.d.getVar('RPM_SIGN_PACKAGES') == '1': |
| 797 | signer = get_signer(self.d, self.d.getVar('RPM_GPG_BACKEND')) |
| 798 | pubkey_path = oe.path.join(self.d.getVar('B'), 'rpm-key') |
| 799 | signer.export_pubkey(pubkey_path, self.d.getVar('RPM_GPG_NAME')) |
| 800 | rpm_bin = bb.utils.which(os.getenv('PATH'), "rpmkeys") |
| 801 | cmd = [rpm_bin, '--root=%s' % self.target_rootfs, '--import', pubkey_path] |
| 802 | try: |
| 803 | subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
| 804 | except subprocess.CalledProcessError as e: |
| 805 | bb.fatal("Importing GPG key failed. Command '%s' " |
| 806 | "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 807 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 808 | def create_configs(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 809 | self._configure_dnf() |
| 810 | self._configure_rpm() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 811 | |
| 812 | def write_index(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 813 | lockfilename = self.d.getVar('DEPLOY_DIR_RPM') + "/rpm.lock" |
| 814 | lf = bb.utils.lockfile(lockfilename, False) |
| 815 | RpmIndexer(self.d, self.rpm_repo_dir).write_index() |
| 816 | bb.utils.unlockfile(lf) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 817 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 818 | def insert_feeds_uris(self, feed_uris, feed_base_paths, feed_archs): |
| 819 | from urllib.parse import urlparse |
| 820 | |
| 821 | if feed_uris == "": |
| 822 | return |
| 823 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 824 | gpg_opts = '' |
| 825 | if self.d.getVar('PACKAGE_FEED_SIGN') == '1': |
| 826 | gpg_opts += 'repo_gpgcheck=1\n' |
| 827 | gpg_opts += 'gpgkey=file://%s/pki/packagefeed-gpg/PACKAGEFEED-GPG-KEY-%s-%s\n' % (self.d.getVar('sysconfdir'), self.d.getVar('DISTRO'), self.d.getVar('DISTRO_CODENAME')) |
| 828 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 829 | if self.d.getVar('RPM_SIGN_PACKAGES') != '1': |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 830 | gpg_opts += 'gpgcheck=0\n' |
| 831 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 832 | bb.utils.mkdirhier(oe.path.join(self.target_rootfs, "etc", "yum.repos.d")) |
| 833 | remote_uris = self.construct_uris(feed_uris.split(), feed_base_paths.split()) |
| 834 | for uri in remote_uris: |
| 835 | repo_base = "oe-remote-repo" + "-".join(urlparse(uri).path.split("/")) |
| 836 | if feed_archs is not None: |
| 837 | for arch in feed_archs.split(): |
| 838 | repo_uri = uri + "/" + arch |
| 839 | repo_id = "oe-remote-repo" + "-".join(urlparse(repo_uri).path.split("/")) |
| 840 | repo_name = "OE Remote Repo:" + " ".join(urlparse(repo_uri).path.split("/")) |
| 841 | open(oe.path.join(self.target_rootfs, "etc", "yum.repos.d", repo_base + ".repo"), 'a').write( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 842 | "[%s]\nname=%s\nbaseurl=%s\n%s\n" % (repo_id, repo_name, repo_uri, gpg_opts)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 843 | else: |
| 844 | repo_name = "OE Remote Repo:" + " ".join(urlparse(uri).path.split("/")) |
| 845 | repo_uri = uri |
| 846 | open(oe.path.join(self.target_rootfs, "etc", "yum.repos.d", repo_base + ".repo"), 'w').write( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 847 | "[%s]\nname=%s\nbaseurl=%s\n%s" % (repo_base, repo_name, repo_uri, gpg_opts)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 848 | |
| 849 | def _prepare_pkg_transaction(self): |
| 850 | os.environ['D'] = self.target_rootfs |
| 851 | os.environ['OFFLINE_ROOT'] = self.target_rootfs |
| 852 | os.environ['IPKG_OFFLINE_ROOT'] = self.target_rootfs |
| 853 | os.environ['OPKG_OFFLINE_ROOT'] = self.target_rootfs |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 854 | os.environ['INTERCEPT_DIR'] = self.intercepts_dir |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 855 | os.environ['NATIVE_ROOT'] = self.d.getVar('STAGING_DIR_NATIVE') |
| 856 | |
| 857 | |
| 858 | def install(self, pkgs, attempt_only = False): |
| 859 | if len(pkgs) == 0: |
| 860 | return |
| 861 | self._prepare_pkg_transaction() |
| 862 | |
| 863 | bad_recommendations = self.d.getVar('BAD_RECOMMENDATIONS') |
| 864 | package_exclude = self.d.getVar('PACKAGE_EXCLUDE') |
| 865 | exclude_pkgs = (bad_recommendations.split() if bad_recommendations else []) + (package_exclude.split() if package_exclude else []) |
| 866 | |
| 867 | output = self._invoke_dnf((["--skip-broken"] if attempt_only else []) + |
| 868 | (["-x", ",".join(exclude_pkgs)] if len(exclude_pkgs) > 0 else []) + |
| 869 | (["--setopt=install_weak_deps=False"] if self.d.getVar('NO_RECOMMENDATIONS') == "1" else []) + |
| 870 | (["--nogpgcheck"] if self.d.getVar('RPM_SIGN_PACKAGES') != '1' else ["--setopt=gpgcheck=True"]) + |
| 871 | ["install"] + |
| 872 | pkgs) |
| 873 | |
| 874 | failed_scriptlets_pkgnames = collections.OrderedDict() |
| 875 | for line in output.splitlines(): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 876 | if line.startswith("Error in POSTIN scriptlet in rpm package"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 877 | failed_scriptlets_pkgnames[line.split()[-1]] = True |
| 878 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 879 | if len(failed_scriptlets_pkgnames) > 0: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 880 | failed_postinsts_abort(list(failed_scriptlets_pkgnames.keys()), self.d.expand("${T}/log.do_${BB_CURRENTTASK}")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 881 | |
| 882 | def remove(self, pkgs, with_dependencies = True): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 883 | if not pkgs: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 884 | return |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 885 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 886 | self._prepare_pkg_transaction() |
| 887 | |
| 888 | if with_dependencies: |
| 889 | self._invoke_dnf(["remove"] + pkgs) |
| 890 | else: |
| 891 | cmd = bb.utils.which(os.getenv('PATH'), "rpm") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 892 | args = ["-e", "-v", "--nodeps", "--root=%s" %self.target_rootfs] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 893 | |
| 894 | try: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 895 | bb.note("Running %s" % ' '.join([cmd] + args + pkgs)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 896 | output = subprocess.check_output([cmd] + args + pkgs, stderr=subprocess.STDOUT).decode("utf-8") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 897 | bb.note(output) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 898 | except subprocess.CalledProcessError as e: |
| 899 | bb.fatal("Could not invoke rpm. Command " |
| 900 | "'%s' returned %d:\n%s" % (' '.join([cmd] + args + pkgs), e.returncode, e.output.decode("utf-8"))) |
| 901 | |
| 902 | def upgrade(self): |
| 903 | self._prepare_pkg_transaction() |
| 904 | self._invoke_dnf(["upgrade"]) |
| 905 | |
| 906 | def autoremove(self): |
| 907 | self._prepare_pkg_transaction() |
| 908 | self._invoke_dnf(["autoremove"]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 909 | |
| 910 | def remove_packaging_data(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 911 | self._invoke_dnf(["clean", "all"]) |
| 912 | for dir in self.packaging_data_dirs: |
| 913 | bb.utils.remove(oe.path.join(self.target_rootfs, dir), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 914 | |
| 915 | def backup_packaging_data(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 916 | # Save the packaging dirs for increment rpm image generation |
| 917 | if os.path.exists(self.saved_packaging_data): |
| 918 | bb.utils.remove(self.saved_packaging_data, True) |
| 919 | for i in self.packaging_data_dirs: |
| 920 | source_dir = oe.path.join(self.target_rootfs, i) |
| 921 | target_dir = oe.path.join(self.saved_packaging_data, i) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 922 | if os.path.isdir(source_dir): |
| 923 | shutil.copytree(source_dir, target_dir, symlinks=True) |
| 924 | elif os.path.isfile(source_dir): |
| 925 | shutil.copy2(source_dir, target_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 926 | |
| 927 | def recovery_packaging_data(self): |
| 928 | # Move the rpmlib back |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 929 | if os.path.exists(self.saved_packaging_data): |
| 930 | for i in self.packaging_data_dirs: |
| 931 | target_dir = oe.path.join(self.target_rootfs, i) |
| 932 | if os.path.exists(target_dir): |
| 933 | bb.utils.remove(target_dir, True) |
| 934 | source_dir = oe.path.join(self.saved_packaging_data, i) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 935 | if os.path.isdir(source_dir): |
| 936 | shutil.copytree(source_dir, target_dir, symlinks=True) |
| 937 | elif os.path.isfile(source_dir): |
| 938 | shutil.copy2(source_dir, target_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 939 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 940 | def list_installed(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 941 | output = self._invoke_dnf(["repoquery", "--installed", "--queryformat", "Package: %{name} %{arch} %{version} %{name}-%{version}-%{release}.%{arch}.rpm\nDependencies:\n%{requires}\nRecommendations:\n%{recommends}\nDependenciesEndHere:\n"], |
| 942 | print_output = False) |
| 943 | packages = {} |
| 944 | current_package = None |
| 945 | current_deps = None |
| 946 | current_state = "initial" |
| 947 | for line in output.splitlines(): |
| 948 | if line.startswith("Package:"): |
| 949 | package_info = line.split(" ")[1:] |
| 950 | current_package = package_info[0] |
| 951 | package_arch = package_info[1] |
| 952 | package_version = package_info[2] |
| 953 | package_rpm = package_info[3] |
| 954 | packages[current_package] = {"arch":package_arch, "ver":package_version, "filename":package_rpm} |
| 955 | current_deps = [] |
| 956 | elif line.startswith("Dependencies:"): |
| 957 | current_state = "dependencies" |
| 958 | elif line.startswith("Recommendations"): |
| 959 | current_state = "recommendations" |
| 960 | elif line.startswith("DependenciesEndHere:"): |
| 961 | current_state = "initial" |
| 962 | packages[current_package]["deps"] = current_deps |
| 963 | elif len(line) > 0: |
| 964 | if current_state == "dependencies": |
| 965 | current_deps.append(line) |
| 966 | elif current_state == "recommendations": |
| 967 | current_deps.append("%s [REC]" % line) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 968 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 969 | return packages |
| 970 | |
| 971 | def update(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 972 | self._invoke_dnf(["makecache", "--refresh"]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 973 | |
| 974 | def _invoke_dnf(self, dnf_args, fatal = True, print_output = True ): |
| 975 | os.environ['RPM_ETCCONFIGDIR'] = self.target_rootfs |
| 976 | |
| 977 | dnf_cmd = bb.utils.which(os.getenv('PATH'), "dnf") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 978 | standard_dnf_args = ["-v", "--rpmverbosity=info", "-y", |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 979 | "-c", oe.path.join(self.target_rootfs, "etc/dnf/dnf.conf"), |
| 980 | "--setopt=reposdir=%s" %(oe.path.join(self.target_rootfs, "etc/yum.repos.d")), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 981 | "--installroot=%s" % (self.target_rootfs), |
| 982 | "--setopt=logdir=%s" % (self.d.getVar('T')) |
| 983 | ] |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 984 | if hasattr(self, "rpm_repo_dir"): |
| 985 | standard_dnf_args.append("--repofrompath=oe-repo,%s" % (self.rpm_repo_dir)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 986 | cmd = [dnf_cmd] + standard_dnf_args + dnf_args |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 987 | bb.note('Running %s' % ' '.join(cmd)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 988 | try: |
| 989 | output = subprocess.check_output(cmd,stderr=subprocess.STDOUT).decode("utf-8") |
| 990 | if print_output: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 991 | bb.debug(1, output) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 992 | return output |
| 993 | except subprocess.CalledProcessError as e: |
| 994 | if print_output: |
| 995 | (bb.note, bb.fatal)[fatal]("Could not invoke dnf. Command " |
| 996 | "'%s' returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output.decode("utf-8"))) |
| 997 | else: |
| 998 | (bb.note, bb.fatal)[fatal]("Could not invoke dnf. Command " |
| 999 | "'%s' returned %d:" % (' '.join(cmd), e.returncode)) |
| 1000 | return e.output.decode("utf-8") |
| 1001 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1002 | def dump_install_solution(self, pkgs): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1003 | open(self.solution_manifest, 'w').write(" ".join(pkgs)) |
| 1004 | return pkgs |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1005 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1006 | def load_old_install_solution(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1007 | if not os.path.exists(self.solution_manifest): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1008 | return [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1009 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1010 | return open(self.solution_manifest, 'r').read().split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1011 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1012 | def _script_num_prefix(self, path): |
| 1013 | files = os.listdir(path) |
| 1014 | numbers = set() |
| 1015 | numbers.add(99) |
| 1016 | for f in files: |
| 1017 | numbers.add(int(f.split("-")[0])) |
| 1018 | return max(numbers) + 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1019 | |
| 1020 | def save_rpmpostinst(self, pkg): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1021 | bb.note("Saving postinstall script of %s" % (pkg)) |
| 1022 | cmd = bb.utils.which(os.getenv('PATH'), "rpm") |
| 1023 | args = ["-q", "--root=%s" % self.target_rootfs, "--queryformat", "%{postin}", pkg] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1024 | |
| 1025 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1026 | output = subprocess.check_output([cmd] + args,stderr=subprocess.STDOUT).decode("utf-8") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1027 | except subprocess.CalledProcessError as e: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1028 | bb.fatal("Could not invoke rpm. Command " |
| 1029 | "'%s' returned %d:\n%s" % (' '.join([cmd] + args), e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1030 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1031 | # may need to prepend #!/bin/sh to output |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1032 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1033 | target_path = oe.path.join(self.target_rootfs, self.d.expand('${sysconfdir}/rpm-postinsts/')) |
| 1034 | bb.utils.mkdirhier(target_path) |
| 1035 | num = self._script_num_prefix(target_path) |
| 1036 | saved_script_name = oe.path.join(target_path, "%d-%s" % (num, pkg)) |
| 1037 | open(saved_script_name, 'w').write(output) |
| 1038 | os.chmod(saved_script_name, 0o755) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1039 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1040 | def _handle_intercept_failure(self, registered_pkgs): |
| 1041 | rpm_postinsts_dir = self.target_rootfs + self.d.expand('${sysconfdir}/rpm-postinsts/') |
| 1042 | bb.utils.mkdirhier(rpm_postinsts_dir) |
| 1043 | |
| 1044 | # Save the package postinstalls in /etc/rpm-postinsts |
| 1045 | for pkg in registered_pkgs.split(): |
| 1046 | self.save_rpmpostinst(pkg) |
| 1047 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1048 | def extract(self, pkg): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1049 | output = self._invoke_dnf(["repoquery", "--queryformat", "%{location}", pkg]) |
| 1050 | pkg_name = output.splitlines()[-1] |
| 1051 | if not pkg_name.endswith(".rpm"): |
| 1052 | bb.fatal("dnf could not find package %s in repository: %s" %(pkg, output)) |
| 1053 | pkg_path = oe.path.join(self.rpm_repo_dir, pkg_name) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1054 | |
| 1055 | cpio_cmd = bb.utils.which(os.getenv("PATH"), "cpio") |
| 1056 | rpm2cpio_cmd = bb.utils.which(os.getenv("PATH"), "rpm2cpio") |
| 1057 | |
| 1058 | if not os.path.isfile(pkg_path): |
| 1059 | bb.fatal("Unable to extract package for '%s'." |
| 1060 | "File %s doesn't exists" % (pkg, pkg_path)) |
| 1061 | |
| 1062 | tmp_dir = tempfile.mkdtemp() |
| 1063 | current_dir = os.getcwd() |
| 1064 | os.chdir(tmp_dir) |
| 1065 | |
| 1066 | try: |
| 1067 | cmd = "%s %s | %s -idmv" % (rpm2cpio_cmd, pkg_path, cpio_cmd) |
| 1068 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) |
| 1069 | except subprocess.CalledProcessError as e: |
| 1070 | bb.utils.remove(tmp_dir, recurse=True) |
| 1071 | bb.fatal("Unable to extract %s package. Command '%s' " |
| 1072 | "returned %d:\n%s" % (pkg_path, cmd, e.returncode, e.output.decode("utf-8"))) |
| 1073 | except OSError as e: |
| 1074 | bb.utils.remove(tmp_dir, recurse=True) |
| 1075 | bb.fatal("Unable to extract %s package. Command '%s' " |
| 1076 | "returned %d:\n%s at %s" % (pkg_path, cmd, e.errno, e.strerror, e.filename)) |
| 1077 | |
| 1078 | bb.note("Extracted %s to %s" % (pkg_path, tmp_dir)) |
| 1079 | os.chdir(current_dir) |
| 1080 | |
| 1081 | return tmp_dir |
| 1082 | |
| 1083 | |
| 1084 | class OpkgDpkgPM(PackageManager): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1085 | def __init__(self, d, target_rootfs): |
| 1086 | """ |
| 1087 | This is an abstract class. Do not instantiate this directly. |
| 1088 | """ |
| 1089 | super(OpkgDpkgPM, self).__init__(d, target_rootfs) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1090 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1091 | def package_info(self, pkg, cmd): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1092 | """ |
| 1093 | Returns a dictionary with the package info. |
| 1094 | |
| 1095 | This method extracts the common parts for Opkg and Dpkg |
| 1096 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1097 | |
| 1098 | try: |
| 1099 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") |
| 1100 | except subprocess.CalledProcessError as e: |
| 1101 | bb.fatal("Unable to list available packages. Command '%s' " |
| 1102 | "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) |
| 1103 | return opkg_query(output) |
| 1104 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1105 | def extract(self, pkg, pkg_info): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1106 | """ |
| 1107 | Returns the path to a tmpdir where resides the contents of a package. |
| 1108 | |
| 1109 | Deleting the tmpdir is responsability of the caller. |
| 1110 | |
| 1111 | This method extracts the common parts for Opkg and Dpkg |
| 1112 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1113 | |
| 1114 | ar_cmd = bb.utils.which(os.getenv("PATH"), "ar") |
| 1115 | tar_cmd = bb.utils.which(os.getenv("PATH"), "tar") |
| 1116 | pkg_path = pkg_info[pkg]["filepath"] |
| 1117 | |
| 1118 | if not os.path.isfile(pkg_path): |
| 1119 | bb.fatal("Unable to extract package for '%s'." |
| 1120 | "File %s doesn't exists" % (pkg, pkg_path)) |
| 1121 | |
| 1122 | tmp_dir = tempfile.mkdtemp() |
| 1123 | current_dir = os.getcwd() |
| 1124 | os.chdir(tmp_dir) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1125 | data_tar = 'data.tar.xz' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1126 | |
| 1127 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1128 | cmd = [ar_cmd, 'x', pkg_path] |
| 1129 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
| 1130 | cmd = [tar_cmd, 'xf', data_tar] |
| 1131 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1132 | except subprocess.CalledProcessError as e: |
| 1133 | bb.utils.remove(tmp_dir, recurse=True) |
| 1134 | bb.fatal("Unable to extract %s package. Command '%s' " |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1135 | "returned %d:\n%s" % (pkg_path, ' '.join(cmd), e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1136 | except OSError as e: |
| 1137 | bb.utils.remove(tmp_dir, recurse=True) |
| 1138 | bb.fatal("Unable to extract %s package. Command '%s' " |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1139 | "returned %d:\n%s at %s" % (pkg_path, ' '.join(cmd), e.errno, e.strerror, e.filename)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1140 | |
| 1141 | bb.note("Extracted %s to %s" % (pkg_path, tmp_dir)) |
| 1142 | bb.utils.remove(os.path.join(tmp_dir, "debian-binary")) |
| 1143 | bb.utils.remove(os.path.join(tmp_dir, "control.tar.gz")) |
| 1144 | os.chdir(current_dir) |
| 1145 | |
| 1146 | return tmp_dir |
| 1147 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1148 | def _handle_intercept_failure(self, registered_pkgs): |
| 1149 | self.mark_packages("unpacked", registered_pkgs.split()) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1150 | |
| 1151 | class OpkgPM(OpkgDpkgPM): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1152 | def __init__(self, d, target_rootfs, config_file, archs, task_name='target', ipk_repo_workdir="oe-rootfs-repo", filterbydependencies=True, prepare_index=True): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1153 | super(OpkgPM, self).__init__(d, target_rootfs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1154 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1155 | self.config_file = config_file |
| 1156 | self.pkg_archs = archs |
| 1157 | self.task_name = task_name |
| 1158 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1159 | self.deploy_dir = oe.path.join(self.d.getVar('WORKDIR'), ipk_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1160 | self.deploy_lock_file = os.path.join(self.deploy_dir, "deploy.lock") |
| 1161 | self.opkg_cmd = bb.utils.which(os.getenv('PATH'), "opkg") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1162 | self.opkg_args = "--volatile-cache -f %s -t %s -o %s " % (self.config_file, self.d.expand('${T}/ipktemp/') ,target_rootfs) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1163 | self.opkg_args += self.d.getVar("OPKG_ARGS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1164 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1165 | if prepare_index: |
| 1166 | create_packages_dir(self.d, self.deploy_dir, d.getVar("DEPLOY_DIR_IPK"), "package_write_ipk", filterbydependencies) |
| 1167 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1168 | opkg_lib_dir = self.d.getVar('OPKGLIBDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1169 | if opkg_lib_dir[0] == "/": |
| 1170 | opkg_lib_dir = opkg_lib_dir[1:] |
| 1171 | |
| 1172 | self.opkg_dir = os.path.join(target_rootfs, opkg_lib_dir, "opkg") |
| 1173 | |
| 1174 | bb.utils.mkdirhier(self.opkg_dir) |
| 1175 | |
| 1176 | self.saved_opkg_dir = self.d.expand('${T}/saved/%s' % self.task_name) |
| 1177 | if not os.path.exists(self.d.expand('${T}/saved')): |
| 1178 | bb.utils.mkdirhier(self.d.expand('${T}/saved')) |
| 1179 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1180 | self.from_feeds = (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") == "1" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1181 | if self.from_feeds: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1182 | self._create_custom_config() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1183 | else: |
| 1184 | self._create_config() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1185 | |
| 1186 | self.indexer = OpkgIndexer(self.d, self.deploy_dir) |
| 1187 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1188 | def mark_packages(self, status_tag, packages=None): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1189 | """ |
| 1190 | This function will change a package's status in /var/lib/opkg/status file. |
| 1191 | If 'packages' is None then the new_status will be applied to all |
| 1192 | packages |
| 1193 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1194 | status_file = os.path.join(self.opkg_dir, "status") |
| 1195 | |
| 1196 | with open(status_file, "r") as sf: |
| 1197 | with open(status_file + ".tmp", "w+") as tmp_sf: |
| 1198 | if packages is None: |
| 1199 | tmp_sf.write(re.sub(r"Package: (.*?)\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)", |
| 1200 | r"Package: \1\n\2Status: \3%s" % status_tag, |
| 1201 | sf.read())) |
| 1202 | else: |
| 1203 | if type(packages).__name__ != "list": |
| 1204 | raise TypeError("'packages' should be a list object") |
| 1205 | |
| 1206 | status = sf.read() |
| 1207 | for pkg in packages: |
| 1208 | status = re.sub(r"Package: %s\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)" % pkg, |
| 1209 | r"Package: %s\n\1Status: \2%s" % (pkg, status_tag), |
| 1210 | status) |
| 1211 | |
| 1212 | tmp_sf.write(status) |
| 1213 | |
| 1214 | os.rename(status_file + ".tmp", status_file) |
| 1215 | |
| 1216 | def _create_custom_config(self): |
| 1217 | bb.note("Building from feeds activated!") |
| 1218 | |
| 1219 | with open(self.config_file, "w+") as config_file: |
| 1220 | priority = 1 |
| 1221 | for arch in self.pkg_archs.split(): |
| 1222 | config_file.write("arch %s %d\n" % (arch, priority)) |
| 1223 | priority += 5 |
| 1224 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1225 | for line in (self.d.getVar('IPK_FEED_URIS') or "").split(): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1226 | feed_match = re.match(r"^[ \t]*(.*)##([^ \t]*)[ \t]*$", line) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1227 | |
| 1228 | if feed_match is not None: |
| 1229 | feed_name = feed_match.group(1) |
| 1230 | feed_uri = feed_match.group(2) |
| 1231 | |
| 1232 | bb.note("Add %s feed with URL %s" % (feed_name, feed_uri)) |
| 1233 | |
| 1234 | config_file.write("src/gz %s %s\n" % (feed_name, feed_uri)) |
| 1235 | |
| 1236 | """ |
| 1237 | Allow to use package deploy directory contents as quick devel-testing |
| 1238 | feed. This creates individual feed configs for each arch subdir of those |
| 1239 | specified as compatible for the current machine. |
| 1240 | NOTE: Development-helper feature, NOT a full-fledged feed. |
| 1241 | """ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1242 | if (self.d.getVar('FEED_DEPLOYDIR_BASE_URI') or "") != "": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1243 | for arch in self.pkg_archs.split(): |
| 1244 | cfg_file_name = os.path.join(self.target_rootfs, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1245 | self.d.getVar("sysconfdir"), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1246 | "opkg", |
| 1247 | "local-%s-feed.conf" % arch) |
| 1248 | |
| 1249 | with open(cfg_file_name, "w+") as cfg_file: |
| 1250 | cfg_file.write("src/gz local-%s %s/%s" % |
| 1251 | (arch, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1252 | self.d.getVar('FEED_DEPLOYDIR_BASE_URI'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1253 | arch)) |
| 1254 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1255 | if self.d.getVar('OPKGLIBDIR') != '/var/lib': |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1256 | # There is no command line option for this anymore, we need to add |
| 1257 | # info_dir and status_file to config file, if OPKGLIBDIR doesn't have |
| 1258 | # the default value of "/var/lib" as defined in opkg: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1259 | # libopkg/opkg_conf.h:#define OPKG_CONF_DEFAULT_LISTS_DIR VARDIR "/lib/opkg/lists" |
| 1260 | # libopkg/opkg_conf.h:#define OPKG_CONF_DEFAULT_INFO_DIR VARDIR "/lib/opkg/info" |
| 1261 | # libopkg/opkg_conf.h:#define OPKG_CONF_DEFAULT_STATUS_FILE VARDIR "/lib/opkg/status" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1262 | cfg_file.write("option info_dir %s\n" % os.path.join(self.d.getVar('OPKGLIBDIR'), 'opkg', 'info')) |
| 1263 | cfg_file.write("option lists_dir %s\n" % os.path.join(self.d.getVar('OPKGLIBDIR'), 'opkg', 'lists')) |
| 1264 | cfg_file.write("option status_file %s\n" % os.path.join(self.d.getVar('OPKGLIBDIR'), 'opkg', 'status')) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1265 | |
| 1266 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1267 | def _create_config(self): |
| 1268 | with open(self.config_file, "w+") as config_file: |
| 1269 | priority = 1 |
| 1270 | for arch in self.pkg_archs.split(): |
| 1271 | config_file.write("arch %s %d\n" % (arch, priority)) |
| 1272 | priority += 5 |
| 1273 | |
| 1274 | config_file.write("src oe file:%s\n" % self.deploy_dir) |
| 1275 | |
| 1276 | for arch in self.pkg_archs.split(): |
| 1277 | pkgs_dir = os.path.join(self.deploy_dir, arch) |
| 1278 | if os.path.isdir(pkgs_dir): |
| 1279 | config_file.write("src oe-%s file:%s\n" % |
| 1280 | (arch, pkgs_dir)) |
| 1281 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1282 | if self.d.getVar('OPKGLIBDIR') != '/var/lib': |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1283 | # There is no command line option for this anymore, we need to add |
| 1284 | # info_dir and status_file to config file, if OPKGLIBDIR doesn't have |
| 1285 | # the default value of "/var/lib" as defined in opkg: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1286 | # libopkg/opkg_conf.h:#define OPKG_CONF_DEFAULT_LISTS_DIR VARDIR "/lib/opkg/lists" |
| 1287 | # libopkg/opkg_conf.h:#define OPKG_CONF_DEFAULT_INFO_DIR VARDIR "/lib/opkg/info" |
| 1288 | # libopkg/opkg_conf.h:#define OPKG_CONF_DEFAULT_STATUS_FILE VARDIR "/lib/opkg/status" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1289 | config_file.write("option info_dir %s\n" % os.path.join(self.d.getVar('OPKGLIBDIR'), 'opkg', 'info')) |
| 1290 | config_file.write("option lists_dir %s\n" % os.path.join(self.d.getVar('OPKGLIBDIR'), 'opkg', 'lists')) |
| 1291 | config_file.write("option status_file %s\n" % os.path.join(self.d.getVar('OPKGLIBDIR'), 'opkg', 'status')) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1292 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1293 | def insert_feeds_uris(self, feed_uris, feed_base_paths, feed_archs): |
| 1294 | if feed_uris == "": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1295 | return |
| 1296 | |
| 1297 | rootfs_config = os.path.join('%s/etc/opkg/base-feeds.conf' |
| 1298 | % self.target_rootfs) |
| 1299 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1300 | feed_uris = self.construct_uris(feed_uris.split(), feed_base_paths.split()) |
| 1301 | archs = self.pkg_archs.split() if feed_archs is None else feed_archs.split() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1302 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1303 | with open(rootfs_config, "w+") as config_file: |
| 1304 | uri_iterator = 0 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1305 | for uri in feed_uris: |
| 1306 | if archs: |
| 1307 | for arch in archs: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1308 | if (feed_archs is None) and (not os.path.exists(oe.path.join(self.deploy_dir, arch))): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1309 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1310 | bb.note('Adding opkg feed url-%s-%d (%s)' % |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1311 | (arch, uri_iterator, uri)) |
| 1312 | config_file.write("src/gz uri-%s-%d %s/%s\n" % |
| 1313 | (arch, uri_iterator, uri, arch)) |
| 1314 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1315 | bb.note('Adding opkg feed url-%d (%s)' % |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1316 | (uri_iterator, uri)) |
| 1317 | config_file.write("src/gz uri-%d %s\n" % |
| 1318 | (uri_iterator, uri)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1319 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1320 | uri_iterator += 1 |
| 1321 | |
| 1322 | def update(self): |
| 1323 | self.deploy_dir_lock() |
| 1324 | |
| 1325 | cmd = "%s %s update" % (self.opkg_cmd, self.opkg_args) |
| 1326 | |
| 1327 | try: |
| 1328 | subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) |
| 1329 | except subprocess.CalledProcessError as e: |
| 1330 | self.deploy_dir_unlock() |
| 1331 | bb.fatal("Unable to update the package index files. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1332 | "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1333 | |
| 1334 | self.deploy_dir_unlock() |
| 1335 | |
| 1336 | def install(self, pkgs, attempt_only=False): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1337 | if not pkgs: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1338 | return |
| 1339 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1340 | cmd = "%s %s" % (self.opkg_cmd, self.opkg_args) |
| 1341 | for exclude in (self.d.getVar("PACKAGE_EXCLUDE") or "").split(): |
| 1342 | cmd += " --add-exclude %s" % exclude |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1343 | for bad_recommendation in (self.d.getVar("BAD_RECOMMENDATIONS") or "").split(): |
| 1344 | cmd += " --add-ignore-recommends %s" % bad_recommendation |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1345 | cmd += " install " |
| 1346 | cmd += " ".join(pkgs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1347 | |
| 1348 | os.environ['D'] = self.target_rootfs |
| 1349 | os.environ['OFFLINE_ROOT'] = self.target_rootfs |
| 1350 | os.environ['IPKG_OFFLINE_ROOT'] = self.target_rootfs |
| 1351 | os.environ['OPKG_OFFLINE_ROOT'] = self.target_rootfs |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1352 | os.environ['INTERCEPT_DIR'] = self.intercepts_dir |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1353 | os.environ['NATIVE_ROOT'] = self.d.getVar('STAGING_DIR_NATIVE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1354 | |
| 1355 | try: |
| 1356 | bb.note("Installing the following packages: %s" % ' '.join(pkgs)) |
| 1357 | bb.note(cmd) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1358 | output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).decode("utf-8") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1359 | bb.note(output) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1360 | failed_pkgs = [] |
| 1361 | for line in output.split('\n'): |
| 1362 | if line.endswith("configuration required on target."): |
| 1363 | bb.warn(line) |
| 1364 | failed_pkgs.append(line.split(".")[0]) |
| 1365 | if failed_pkgs: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1366 | failed_postinsts_abort(failed_pkgs, self.d.expand("${T}/log.do_${BB_CURRENTTASK}")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1367 | except subprocess.CalledProcessError as e: |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 1368 | (bb.fatal, bb.warn)[attempt_only]("Unable to install packages. " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1369 | "Command '%s' returned %d:\n%s" % |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1370 | (cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1371 | |
| 1372 | def remove(self, pkgs, with_dependencies=True): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1373 | if not pkgs: |
| 1374 | return |
| 1375 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1376 | if with_dependencies: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1377 | cmd = "%s %s --force-remove --force-removal-of-dependent-packages remove %s" % \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1378 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) |
| 1379 | else: |
| 1380 | cmd = "%s %s --force-depends remove %s" % \ |
| 1381 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) |
| 1382 | |
| 1383 | try: |
| 1384 | bb.note(cmd) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1385 | output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).decode("utf-8") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1386 | bb.note(output) |
| 1387 | except subprocess.CalledProcessError as e: |
| 1388 | bb.fatal("Unable to remove packages. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1389 | "returned %d:\n%s" % (e.cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1390 | |
| 1391 | def write_index(self): |
| 1392 | self.deploy_dir_lock() |
| 1393 | |
| 1394 | result = self.indexer.write_index() |
| 1395 | |
| 1396 | self.deploy_dir_unlock() |
| 1397 | |
| 1398 | if result is not None: |
| 1399 | bb.fatal(result) |
| 1400 | |
| 1401 | def remove_packaging_data(self): |
| 1402 | bb.utils.remove(self.opkg_dir, True) |
| 1403 | # create the directory back, it's needed by PM lock |
| 1404 | bb.utils.mkdirhier(self.opkg_dir) |
| 1405 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1406 | def remove_lists(self): |
| 1407 | if not self.from_feeds: |
| 1408 | bb.utils.remove(os.path.join(self.opkg_dir, "lists"), True) |
| 1409 | |
| 1410 | def list_installed(self): |
| 1411 | return OpkgPkgsList(self.d, self.target_rootfs, self.config_file).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1412 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1413 | def dummy_install(self, pkgs): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1414 | """ |
| 1415 | The following function dummy installs pkgs and returns the log of output. |
| 1416 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1417 | if len(pkgs) == 0: |
| 1418 | return |
| 1419 | |
| 1420 | # Create an temp dir as opkg root for dummy installation |
| 1421 | temp_rootfs = self.d.expand('${T}/opkg') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1422 | opkg_lib_dir = self.d.getVar('OPKGLIBDIR') |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1423 | if opkg_lib_dir[0] == "/": |
| 1424 | opkg_lib_dir = opkg_lib_dir[1:] |
| 1425 | temp_opkg_dir = os.path.join(temp_rootfs, opkg_lib_dir, 'opkg') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1426 | bb.utils.mkdirhier(temp_opkg_dir) |
| 1427 | |
| 1428 | opkg_args = "-f %s -o %s " % (self.config_file, temp_rootfs) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1429 | opkg_args += self.d.getVar("OPKG_ARGS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1430 | |
| 1431 | cmd = "%s %s update" % (self.opkg_cmd, opkg_args) |
| 1432 | try: |
| 1433 | subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) |
| 1434 | except subprocess.CalledProcessError as e: |
| 1435 | bb.fatal("Unable to update. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1436 | "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1437 | |
| 1438 | # Dummy installation |
| 1439 | cmd = "%s %s --noaction install %s " % (self.opkg_cmd, |
| 1440 | opkg_args, |
| 1441 | ' '.join(pkgs)) |
| 1442 | try: |
| 1443 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) |
| 1444 | except subprocess.CalledProcessError as e: |
| 1445 | bb.fatal("Unable to dummy install packages. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1446 | "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1447 | |
| 1448 | bb.utils.remove(temp_rootfs, True) |
| 1449 | |
| 1450 | return output |
| 1451 | |
| 1452 | def backup_packaging_data(self): |
| 1453 | # Save the opkglib for increment ipk image generation |
| 1454 | if os.path.exists(self.saved_opkg_dir): |
| 1455 | bb.utils.remove(self.saved_opkg_dir, True) |
| 1456 | shutil.copytree(self.opkg_dir, |
| 1457 | self.saved_opkg_dir, |
| 1458 | symlinks=True) |
| 1459 | |
| 1460 | def recover_packaging_data(self): |
| 1461 | # Move the opkglib back |
| 1462 | if os.path.exists(self.saved_opkg_dir): |
| 1463 | if os.path.exists(self.opkg_dir): |
| 1464 | bb.utils.remove(self.opkg_dir, True) |
| 1465 | |
| 1466 | bb.note('Recover packaging data') |
| 1467 | shutil.copytree(self.saved_opkg_dir, |
| 1468 | self.opkg_dir, |
| 1469 | symlinks=True) |
| 1470 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1471 | def package_info(self, pkg): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1472 | """ |
| 1473 | Returns a dictionary with the package info. |
| 1474 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1475 | cmd = "%s %s info %s" % (self.opkg_cmd, self.opkg_args, pkg) |
| 1476 | pkg_info = super(OpkgPM, self).package_info(pkg, cmd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1477 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1478 | pkg_arch = pkg_info[pkg]["arch"] |
| 1479 | pkg_filename = pkg_info[pkg]["filename"] |
| 1480 | pkg_info[pkg]["filepath"] = \ |
| 1481 | os.path.join(self.deploy_dir, pkg_arch, pkg_filename) |
| 1482 | |
| 1483 | return pkg_info |
| 1484 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1485 | def extract(self, pkg): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1486 | """ |
| 1487 | Returns the path to a tmpdir where resides the contents of a package. |
| 1488 | |
| 1489 | Deleting the tmpdir is responsability of the caller. |
| 1490 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1491 | pkg_info = self.package_info(pkg) |
| 1492 | if not pkg_info: |
| 1493 | bb.fatal("Unable to get information for package '%s' while " |
| 1494 | "trying to extract the package." % pkg) |
| 1495 | |
| 1496 | tmp_dir = super(OpkgPM, self).extract(pkg, pkg_info) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1497 | bb.utils.remove(os.path.join(tmp_dir, "data.tar.xz")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1498 | |
| 1499 | return tmp_dir |
| 1500 | |
| 1501 | class DpkgPM(OpkgDpkgPM): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1502 | def __init__(self, d, target_rootfs, archs, base_archs, apt_conf_dir=None, deb_repo_workdir="oe-rootfs-repo", filterbydependencies=True): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1503 | super(DpkgPM, self).__init__(d, target_rootfs) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1504 | self.deploy_dir = oe.path.join(self.d.getVar('WORKDIR'), deb_repo_workdir) |
| 1505 | |
| 1506 | create_packages_dir(self.d, self.deploy_dir, d.getVar("DEPLOY_DIR_DEB"), "package_write_deb", filterbydependencies) |
| 1507 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1508 | if apt_conf_dir is None: |
| 1509 | self.apt_conf_dir = self.d.expand("${APTCONF_TARGET}/apt") |
| 1510 | else: |
| 1511 | self.apt_conf_dir = apt_conf_dir |
| 1512 | self.apt_conf_file = os.path.join(self.apt_conf_dir, "apt.conf") |
| 1513 | self.apt_get_cmd = bb.utils.which(os.getenv('PATH'), "apt-get") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1514 | self.apt_cache_cmd = bb.utils.which(os.getenv('PATH'), "apt-cache") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1515 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1516 | self.apt_args = d.getVar("APT_ARGS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1517 | |
| 1518 | self.all_arch_list = archs.split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1519 | all_mlb_pkg_arch_list = (self.d.getVar('ALL_MULTILIB_PACKAGE_ARCHS') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1520 | self.all_arch_list.extend(arch for arch in all_mlb_pkg_arch_list if arch not in self.all_arch_list) |
| 1521 | |
| 1522 | self._create_configs(archs, base_archs) |
| 1523 | |
| 1524 | self.indexer = DpkgIndexer(self.d, self.deploy_dir) |
| 1525 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1526 | def mark_packages(self, status_tag, packages=None): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1527 | """ |
| 1528 | This function will change a package's status in /var/lib/dpkg/status file. |
| 1529 | If 'packages' is None then the new_status will be applied to all |
| 1530 | packages |
| 1531 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1532 | status_file = self.target_rootfs + "/var/lib/dpkg/status" |
| 1533 | |
| 1534 | with open(status_file, "r") as sf: |
| 1535 | with open(status_file + ".tmp", "w+") as tmp_sf: |
| 1536 | if packages is None: |
| 1537 | tmp_sf.write(re.sub(r"Package: (.*?)\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)", |
| 1538 | r"Package: \1\n\2Status: \3%s" % status_tag, |
| 1539 | sf.read())) |
| 1540 | else: |
| 1541 | if type(packages).__name__ != "list": |
| 1542 | raise TypeError("'packages' should be a list object") |
| 1543 | |
| 1544 | status = sf.read() |
| 1545 | for pkg in packages: |
| 1546 | status = re.sub(r"Package: %s\n((?:[^\n]+\n)*?)Status: (.*)(?:unpacked|installed)" % pkg, |
| 1547 | r"Package: %s\n\1Status: \2%s" % (pkg, status_tag), |
| 1548 | status) |
| 1549 | |
| 1550 | tmp_sf.write(status) |
| 1551 | |
| 1552 | os.rename(status_file + ".tmp", status_file) |
| 1553 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1554 | def run_pre_post_installs(self, package_name=None): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1555 | """ |
| 1556 | Run the pre/post installs for package "package_name". If package_name is |
| 1557 | None, then run all pre/post install scriptlets. |
| 1558 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1559 | info_dir = self.target_rootfs + "/var/lib/dpkg/info" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1560 | ControlScript = collections.namedtuple("ControlScript", ["suffix", "name", "argument"]) |
| 1561 | control_scripts = [ |
| 1562 | ControlScript(".preinst", "Preinstall", "install"), |
| 1563 | ControlScript(".postinst", "Postinstall", "configure")] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1564 | status_file = self.target_rootfs + "/var/lib/dpkg/status" |
| 1565 | installed_pkgs = [] |
| 1566 | |
| 1567 | with open(status_file, "r") as status: |
| 1568 | for line in status.read().split('\n'): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1569 | m = re.match(r"^Package: (.*)", line) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1570 | if m is not None: |
| 1571 | installed_pkgs.append(m.group(1)) |
| 1572 | |
| 1573 | if package_name is not None and not package_name in installed_pkgs: |
| 1574 | return |
| 1575 | |
| 1576 | os.environ['D'] = self.target_rootfs |
| 1577 | os.environ['OFFLINE_ROOT'] = self.target_rootfs |
| 1578 | os.environ['IPKG_OFFLINE_ROOT'] = self.target_rootfs |
| 1579 | os.environ['OPKG_OFFLINE_ROOT'] = self.target_rootfs |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1580 | os.environ['INTERCEPT_DIR'] = self.intercepts_dir |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1581 | os.environ['NATIVE_ROOT'] = self.d.getVar('STAGING_DIR_NATIVE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1582 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1583 | for pkg_name in installed_pkgs: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1584 | for control_script in control_scripts: |
| 1585 | p_full = os.path.join(info_dir, pkg_name + control_script.suffix) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1586 | if os.path.exists(p_full): |
| 1587 | try: |
| 1588 | bb.note("Executing %s for package: %s ..." % |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1589 | (control_script.name.lower(), pkg_name)) |
| 1590 | output = subprocess.check_output([p_full, control_script.argument], |
| 1591 | stderr=subprocess.STDOUT).decode("utf-8") |
| 1592 | bb.note(output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1593 | except subprocess.CalledProcessError as e: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1594 | bb.warn("%s for package %s failed with %d:\n%s" % |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1595 | (control_script.name, pkg_name, e.returncode, |
| 1596 | e.output.decode("utf-8"))) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1597 | failed_postinsts_abort([pkg_name], self.d.expand("${T}/log.do_${BB_CURRENTTASK}")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1598 | |
| 1599 | def update(self): |
| 1600 | os.environ['APT_CONFIG'] = self.apt_conf_file |
| 1601 | |
| 1602 | self.deploy_dir_lock() |
| 1603 | |
| 1604 | cmd = "%s update" % self.apt_get_cmd |
| 1605 | |
| 1606 | try: |
| 1607 | subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) |
| 1608 | except subprocess.CalledProcessError as e: |
| 1609 | bb.fatal("Unable to update the package index files. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1610 | "returned %d:\n%s" % (e.cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1611 | |
| 1612 | self.deploy_dir_unlock() |
| 1613 | |
| 1614 | def install(self, pkgs, attempt_only=False): |
| 1615 | if attempt_only and len(pkgs) == 0: |
| 1616 | return |
| 1617 | |
| 1618 | os.environ['APT_CONFIG'] = self.apt_conf_file |
| 1619 | |
| 1620 | cmd = "%s %s install --force-yes --allow-unauthenticated %s" % \ |
| 1621 | (self.apt_get_cmd, self.apt_args, ' '.join(pkgs)) |
| 1622 | |
| 1623 | try: |
| 1624 | bb.note("Installing the following packages: %s" % ' '.join(pkgs)) |
| 1625 | subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) |
| 1626 | except subprocess.CalledProcessError as e: |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 1627 | (bb.fatal, bb.warn)[attempt_only]("Unable to install packages. " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1628 | "Command '%s' returned %d:\n%s" % |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1629 | (cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1630 | |
| 1631 | # rename *.dpkg-new files/dirs |
| 1632 | for root, dirs, files in os.walk(self.target_rootfs): |
| 1633 | for dir in dirs: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1634 | new_dir = re.sub(r"\.dpkg-new", "", dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1635 | if dir != new_dir: |
| 1636 | os.rename(os.path.join(root, dir), |
| 1637 | os.path.join(root, new_dir)) |
| 1638 | |
| 1639 | for file in files: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1640 | new_file = re.sub(r"\.dpkg-new", "", file) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1641 | if file != new_file: |
| 1642 | os.rename(os.path.join(root, file), |
| 1643 | os.path.join(root, new_file)) |
| 1644 | |
| 1645 | |
| 1646 | def remove(self, pkgs, with_dependencies=True): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1647 | if not pkgs: |
| 1648 | return |
| 1649 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1650 | if with_dependencies: |
| 1651 | os.environ['APT_CONFIG'] = self.apt_conf_file |
| 1652 | cmd = "%s purge %s" % (self.apt_get_cmd, ' '.join(pkgs)) |
| 1653 | else: |
| 1654 | cmd = "%s --admindir=%s/var/lib/dpkg --instdir=%s" \ |
| 1655 | " -P --force-depends %s" % \ |
| 1656 | (bb.utils.which(os.getenv('PATH'), "dpkg"), |
| 1657 | self.target_rootfs, self.target_rootfs, ' '.join(pkgs)) |
| 1658 | |
| 1659 | try: |
| 1660 | subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) |
| 1661 | except subprocess.CalledProcessError as e: |
| 1662 | bb.fatal("Unable to remove packages. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1663 | "returned %d:\n%s" % (e.cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1664 | |
| 1665 | def write_index(self): |
| 1666 | self.deploy_dir_lock() |
| 1667 | |
| 1668 | result = self.indexer.write_index() |
| 1669 | |
| 1670 | self.deploy_dir_unlock() |
| 1671 | |
| 1672 | if result is not None: |
| 1673 | bb.fatal(result) |
| 1674 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1675 | def insert_feeds_uris(self, feed_uris, feed_base_paths, feed_archs): |
| 1676 | if feed_uris == "": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1677 | return |
| 1678 | |
| 1679 | sources_conf = os.path.join("%s/etc/apt/sources.list" |
| 1680 | % self.target_rootfs) |
| 1681 | arch_list = [] |
| 1682 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1683 | if feed_archs is None: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1684 | for arch in self.all_arch_list: |
| 1685 | if not os.path.exists(os.path.join(self.deploy_dir, arch)): |
| 1686 | continue |
| 1687 | arch_list.append(arch) |
| 1688 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1689 | arch_list = feed_archs.split() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1690 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1691 | feed_uris = self.construct_uris(feed_uris.split(), feed_base_paths.split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1692 | |
| 1693 | with open(sources_conf, "w+") as sources_file: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1694 | for uri in feed_uris: |
| 1695 | if arch_list: |
| 1696 | for arch in arch_list: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1697 | bb.note('Adding dpkg channel at (%s)' % uri) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1698 | sources_file.write("deb %s/%s ./\n" % |
| 1699 | (uri, arch)) |
| 1700 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1701 | bb.note('Adding dpkg channel at (%s)' % uri) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1702 | sources_file.write("deb %s ./\n" % uri) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1703 | |
| 1704 | def _create_configs(self, archs, base_archs): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1705 | base_archs = re.sub(r"_", r"-", base_archs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1706 | |
| 1707 | if os.path.exists(self.apt_conf_dir): |
| 1708 | bb.utils.remove(self.apt_conf_dir, True) |
| 1709 | |
| 1710 | bb.utils.mkdirhier(self.apt_conf_dir) |
| 1711 | bb.utils.mkdirhier(self.apt_conf_dir + "/lists/partial/") |
| 1712 | bb.utils.mkdirhier(self.apt_conf_dir + "/apt.conf.d/") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1713 | bb.utils.mkdirhier(self.apt_conf_dir + "/preferences.d/") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1714 | |
| 1715 | arch_list = [] |
| 1716 | for arch in self.all_arch_list: |
| 1717 | if not os.path.exists(os.path.join(self.deploy_dir, arch)): |
| 1718 | continue |
| 1719 | arch_list.append(arch) |
| 1720 | |
| 1721 | with open(os.path.join(self.apt_conf_dir, "preferences"), "w+") as prefs_file: |
| 1722 | priority = 801 |
| 1723 | for arch in arch_list: |
| 1724 | prefs_file.write( |
| 1725 | "Package: *\n" |
| 1726 | "Pin: release l=%s\n" |
| 1727 | "Pin-Priority: %d\n\n" % (arch, priority)) |
| 1728 | |
| 1729 | priority += 5 |
| 1730 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1731 | pkg_exclude = self.d.getVar('PACKAGE_EXCLUDE') or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1732 | for pkg in pkg_exclude.split(): |
| 1733 | prefs_file.write( |
| 1734 | "Package: %s\n" |
| 1735 | "Pin: release *\n" |
| 1736 | "Pin-Priority: -1\n\n" % pkg) |
| 1737 | |
| 1738 | arch_list.reverse() |
| 1739 | |
| 1740 | with open(os.path.join(self.apt_conf_dir, "sources.list"), "w+") as sources_file: |
| 1741 | for arch in arch_list: |
| 1742 | sources_file.write("deb file:%s/ ./\n" % |
| 1743 | os.path.join(self.deploy_dir, arch)) |
| 1744 | |
| 1745 | base_arch_list = base_archs.split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1746 | multilib_variants = self.d.getVar("MULTILIB_VARIANTS"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1747 | for variant in multilib_variants.split(): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1748 | localdata = bb.data.createCopy(self.d) |
| 1749 | variant_tune = localdata.getVar("DEFAULTTUNE_virtclass-multilib-" + variant, False) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1750 | orig_arch = localdata.getVar("DPKG_ARCH") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1751 | localdata.setVar("DEFAULTTUNE", variant_tune) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1752 | variant_arch = localdata.getVar("DPKG_ARCH") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1753 | if variant_arch not in base_arch_list: |
| 1754 | base_arch_list.append(variant_arch) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1755 | |
| 1756 | with open(self.apt_conf_file, "w+") as apt_conf: |
| 1757 | with open(self.d.expand("${STAGING_ETCDIR_NATIVE}/apt/apt.conf.sample")) as apt_conf_sample: |
| 1758 | for line in apt_conf_sample.read().split("\n"): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1759 | match_arch = re.match(r" Architecture \".*\";$", line) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1760 | architectures = "" |
| 1761 | if match_arch: |
| 1762 | for base_arch in base_arch_list: |
| 1763 | architectures += "\"%s\";" % base_arch |
| 1764 | apt_conf.write(" Architectures {%s};\n" % architectures); |
| 1765 | apt_conf.write(" Architecture \"%s\";\n" % base_archs) |
| 1766 | else: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1767 | line = re.sub(r"#ROOTFS#", self.target_rootfs, line) |
| 1768 | line = re.sub(r"#APTCONF#", self.apt_conf_dir, line) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1769 | apt_conf.write(line + "\n") |
| 1770 | |
| 1771 | target_dpkg_dir = "%s/var/lib/dpkg" % self.target_rootfs |
| 1772 | bb.utils.mkdirhier(os.path.join(target_dpkg_dir, "info")) |
| 1773 | |
| 1774 | bb.utils.mkdirhier(os.path.join(target_dpkg_dir, "updates")) |
| 1775 | |
| 1776 | if not os.path.exists(os.path.join(target_dpkg_dir, "status")): |
| 1777 | open(os.path.join(target_dpkg_dir, "status"), "w+").close() |
| 1778 | if not os.path.exists(os.path.join(target_dpkg_dir, "available")): |
| 1779 | open(os.path.join(target_dpkg_dir, "available"), "w+").close() |
| 1780 | |
| 1781 | def remove_packaging_data(self): |
| 1782 | bb.utils.remove(os.path.join(self.target_rootfs, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1783 | self.d.getVar('opkglibdir')), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1784 | bb.utils.remove(self.target_rootfs + "/var/lib/dpkg/", True) |
| 1785 | |
| 1786 | def fix_broken_dependencies(self): |
| 1787 | os.environ['APT_CONFIG'] = self.apt_conf_file |
| 1788 | |
| 1789 | cmd = "%s %s -f install" % (self.apt_get_cmd, self.apt_args) |
| 1790 | |
| 1791 | try: |
| 1792 | subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) |
| 1793 | except subprocess.CalledProcessError as e: |
| 1794 | bb.fatal("Cannot fix broken dependencies. Command '%s' " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1795 | "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1796 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1797 | def list_installed(self): |
| 1798 | return DpkgPkgsList(self.d, self.target_rootfs).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1799 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1800 | def package_info(self, pkg): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1801 | """ |
| 1802 | Returns a dictionary with the package info. |
| 1803 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1804 | cmd = "%s show %s" % (self.apt_cache_cmd, pkg) |
| 1805 | pkg_info = super(DpkgPM, self).package_info(pkg, cmd) |
| 1806 | |
| 1807 | pkg_arch = pkg_info[pkg]["pkgarch"] |
| 1808 | pkg_filename = pkg_info[pkg]["filename"] |
| 1809 | pkg_info[pkg]["filepath"] = \ |
| 1810 | os.path.join(self.deploy_dir, pkg_arch, pkg_filename) |
| 1811 | |
| 1812 | return pkg_info |
| 1813 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1814 | def extract(self, pkg): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1815 | """ |
| 1816 | Returns the path to a tmpdir where resides the contents of a package. |
| 1817 | |
| 1818 | Deleting the tmpdir is responsability of the caller. |
| 1819 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1820 | pkg_info = self.package_info(pkg) |
| 1821 | if not pkg_info: |
| 1822 | bb.fatal("Unable to get information for package '%s' while " |
| 1823 | "trying to extract the package." % pkg) |
| 1824 | |
| 1825 | tmp_dir = super(DpkgPM, self).extract(pkg, pkg_info) |
| 1826 | bb.utils.remove(os.path.join(tmp_dir, "data.tar.xz")) |
| 1827 | |
| 1828 | return tmp_dir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1829 | |
| 1830 | def generate_index_files(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1831 | classes = d.getVar('PACKAGE_CLASSES').replace("package_", "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1832 | |
| 1833 | indexer_map = { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1834 | "rpm": (RpmSubdirIndexer, d.getVar('DEPLOY_DIR_RPM')), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1835 | "ipk": (OpkgIndexer, d.getVar('DEPLOY_DIR_IPK')), |
| 1836 | "deb": (DpkgIndexer, d.getVar('DEPLOY_DIR_DEB')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | result = None |
| 1840 | |
| 1841 | for pkg_class in classes: |
| 1842 | if not pkg_class in indexer_map: |
| 1843 | continue |
| 1844 | |
| 1845 | if os.path.exists(indexer_map[pkg_class][1]): |
| 1846 | result = indexer_map[pkg_class][0](d, indexer_map[pkg_class][1]).write_index() |
| 1847 | |
| 1848 | if result is not None: |
| 1849 | bb.fatal(result) |