Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Check whether a package links libraries not in RDEPEND. |
| 6 | |
| 7 | If no argument is provided it will check all installed packages. It takes the |
| 8 | BOARD environment variable into account. |
| 9 | |
| 10 | Example: |
| 11 | package_hash_missing_deps.py --board=amd64-generic --match \ |
| 12 | chromeos-base/cryptohome |
| 13 | """ |
| 14 | |
| 15 | import argparse |
| 16 | import collections |
| 17 | import os |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 18 | from pathlib import Path |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 19 | import pprint |
| 20 | import sys |
Mike Frysinger | 1e9ac7c | 2023-09-21 14:53:48 -0400 | [diff] [blame] | 21 | from typing import Iterable, List, Optional, Set, Union |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 22 | |
| 23 | from chromite.lib import build_target_lib |
| 24 | from chromite.lib import chroot_lib |
| 25 | from chromite.lib import commandline |
| 26 | from chromite.lib import cros_build_lib |
| 27 | from chromite.lib import parallel |
| 28 | from chromite.lib import portage_util |
| 29 | from chromite.lib.parser import package_info |
| 30 | |
| 31 | |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 32 | VIRTUALS = { |
Allen Webb | 4c582aa | 2023-09-12 17:20:49 +0000 | [diff] [blame] | 33 | "virtual/acl": ("sys-apps/acl", "media-libs/img-ddk-bin"), |
| 34 | "virtual/arc-opengles": ( |
| 35 | "media-libs/arc-img-ddk", |
| 36 | "media-libs/arc-mesa-img", |
| 37 | "media-libs/arc-mali-drivers", |
| 38 | "media-libs/arc-mali-drivers-bifrost", |
| 39 | "media-libs/arc-mali-drivers-bifrost-bin", |
| 40 | "media-libs/arc-mali-drivers-valhall", |
| 41 | "media-libs/arc-mali-drivers-valhall-bin", |
| 42 | "media-libs/arc-mesa", |
| 43 | "media-libs/arc-mesa-amd", |
| 44 | "media-libs/arc-mesa-freedreno", |
| 45 | "media-libs/arc-mesa-iris", |
| 46 | "media-libs/arc-mesa-virgl", |
| 47 | "x11-drivers/opengles-headers", |
| 48 | ), |
| 49 | "virtual/cros-camera-hal": ( |
| 50 | "media-libs/cros-camera-hal-intel-ipu3", |
| 51 | "media-libs/cros-camera-hal-intel-ipu6", |
| 52 | "media-libs/cros-camera-hal-mtk", |
| 53 | "media-libs/cros-camera-hal-qti", |
| 54 | "media-libs/cros-camera-hal-rockchip-isp1", |
| 55 | "media-libs/cros-camera-hal-usb", |
| 56 | "media-libs/qti-7c-camera-tuning", |
| 57 | ), |
| 58 | "virtual/img-ddk": ("media-libs/img-ddk", "media-libs/img-ddk-bin"), |
| 59 | "virtual/jpeg": ("media-libs/libjpeg-turbo", "media-libs/jpeg"), |
| 60 | "virtual/krb5": ("app-crypt/mit-krb5", "app-crypt/heimdal"), |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 61 | "virtual/libcrypt": ("sys-libs/libxcrypt",), |
| 62 | "virtual/libelf": ("dev-libs/elfutils", "sys-freebsd/freebsd-lib"), |
| 63 | "virtual/libiconv": ("dev-libs/libiconv",), |
| 64 | "virtual/libintl": ("dev-libs/libintl",), |
| 65 | "virtual/libudev": ( |
| 66 | "sys-apps/systemd-utils", |
| 67 | "sys-fs/udev", |
| 68 | "sys-fs/eudev", |
| 69 | "sys-apps/systemd", |
| 70 | ), |
| 71 | "virtual/libusb": ("dev-libs/libusb", "sys-freebsd/freebsd-lib"), |
Allen Webb | 4c582aa | 2023-09-12 17:20:49 +0000 | [diff] [blame] | 72 | "virtual/opengles": ( |
| 73 | "media-libs/img-ddk", |
| 74 | "media-libs/img-ddk-bin", |
Ricky Liang | d5f6443 | 2023-09-15 15:50:04 +0800 | [diff] [blame] | 75 | "media-libs/libglvnd", |
Allen Webb | 4c582aa | 2023-09-12 17:20:49 +0000 | [diff] [blame] | 76 | "media-libs/mali-drivers-bin", |
| 77 | "media-libs/mali-drivers-bifrost", |
| 78 | "media-libs/mali-drivers-bifrost-bin", |
| 79 | "media-libs/mali-drivers-valhall", |
| 80 | "media-libs/mali-drivers-valhall-bin", |
| 81 | "media-libs/mesa", |
| 82 | "media-libs/mesa-amd", |
| 83 | "media-libs/mesa-freedreno", |
| 84 | "media-libs/mesa-iris", |
| 85 | "media-libs/mesa-llvmpipe", |
| 86 | "media-libs/mesa-panfrost", |
| 87 | "media-libs/mesa-reven", |
| 88 | "x11-drivers/opengles-headers", |
| 89 | ), |
| 90 | "virtual/vulkan-icd": ( |
| 91 | "media-libs/img-ddk", |
| 92 | "media-libs/img-ddk-bin", |
| 93 | "media-libs/mali-drivers-bifrost", |
| 94 | "media-libs/mali-drivers-bifrost-bin", |
| 95 | "media-libs/mali-drivers-valhall", |
| 96 | "media-libs/mali-drivers-valhall-bin", |
| 97 | "media-libs/mesa", |
| 98 | "media-libs/mesa-freedreno", |
| 99 | "media-libs/mesa-iris", |
| 100 | "media-libs/mesa-llvmpipe", |
| 101 | "media-libs/mesa-radv", |
| 102 | "media-libs/vulkan-loader", |
| 103 | ), |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 107 | def env_to_libs(var: str) -> List[str]: |
| 108 | """Converts value of REQUIRES to a list of .so files. |
| 109 | |
| 110 | For example: |
| 111 | "arm_32: libRSSupport.so libblasV8.so libc.so ..." |
| 112 | Becomes: |
| 113 | ["libRSSupport.so", "libblasV8.so", "libc.so", ...] |
| 114 | """ |
| 115 | return [x for x in var.split() if not x.endswith(":")] |
| 116 | |
| 117 | |
| 118 | class DotSoResolver: |
| 119 | """Provides shared library related dependency operations.""" |
| 120 | |
| 121 | def __init__( |
| 122 | self, |
| 123 | board: Optional[str] = None, |
| 124 | root: Union[os.PathLike, str] = "/", |
| 125 | chroot: Optional[chroot_lib.Chroot] = None, |
| 126 | ): |
| 127 | self.board = board |
| 128 | self.chroot = chroot if chroot else chroot_lib.Chroot() |
| 129 | |
| 130 | self.sdk_db = portage_util.PortageDB() |
Mike Frysinger | 2c65b08 | 2023-09-21 12:22:58 -0400 | [diff] [blame] | 131 | self._sdk_db_packges = None |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 132 | self.db = self.sdk_db if root == "/" else portage_util.PortageDB(root) |
Mike Frysinger | 2c65b08 | 2023-09-21 12:22:58 -0400 | [diff] [blame] | 133 | self._db_packges = None |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 134 | self.provided_libs_cache = {} |
| 135 | |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 136 | # Lazy initialize since it might not be needed. |
| 137 | self.lib_to_package_map = None |
| 138 | |
Mike Frysinger | 2c65b08 | 2023-09-21 12:22:58 -0400 | [diff] [blame] | 139 | @property |
| 140 | def sdk_db_packages(self): |
| 141 | """Cache sdk_db.InstalledPackages(). |
| 142 | |
| 143 | We won't be modifying it, so it's safe for us to reuse the results. |
| 144 | """ |
| 145 | if self._sdk_db_packges is None: |
| 146 | self._sdk_db_packges = self.sdk_db.InstalledPackages() |
| 147 | return self._sdk_db_packges |
| 148 | |
| 149 | @property |
| 150 | def db_packages(self): |
| 151 | """Cache db.InstalledPackages(). |
| 152 | |
| 153 | We won't be modifying it, so it's safe for us to reuse the results. |
| 154 | """ |
| 155 | if self._db_packges is None: |
| 156 | self._db_packges = self.db.InstalledPackages() |
| 157 | return self._db_packges |
| 158 | |
Mike Frysinger | 1e9ac7c | 2023-09-21 14:53:48 -0400 | [diff] [blame] | 159 | def get_packages( |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 160 | self, query: str, from_sdk=False |
Mike Frysinger | 1e9ac7c | 2023-09-21 14:53:48 -0400 | [diff] [blame] | 161 | ) -> Iterable[portage_util.InstalledPackage]: |
| 162 | """Find matching InstalledPackage(s) for the |query|.""" |
Mike Frysinger | 2c65b08 | 2023-09-21 12:22:58 -0400 | [diff] [blame] | 163 | packages = self.sdk_db_packages if from_sdk else self.db_packages |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 164 | info = package_info.parse(query) |
| 165 | for package in packages: |
| 166 | if info.package != package.package: |
| 167 | continue |
| 168 | if info.category != package.category: |
| 169 | continue |
| 170 | dep_info = package.package_info |
| 171 | if info.revision and info.revision != dep_info.revision: |
| 172 | continue |
| 173 | if info.pv and info.pv != dep_info.pv: |
| 174 | continue |
Mike Frysinger | 1e9ac7c | 2023-09-21 14:53:48 -0400 | [diff] [blame] | 175 | yield package |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 176 | |
| 177 | def get_required_libs(self, package) -> Set[str]: |
| 178 | """Return a set of required .so files.""" |
Allen Webb | 8fc0bba | 2023-09-11 14:37:25 +0000 | [diff] [blame] | 179 | requires = package.requires |
| 180 | if requires is not None: |
| 181 | return set(env_to_libs(package.requires)) |
| 182 | # Fallback to needed if requires is not available. |
| 183 | aggregate = set() |
| 184 | needed = package.needed |
| 185 | if needed is not None: |
| 186 | for libs in needed.values(): |
| 187 | aggregate.update(libs) |
| 188 | return aggregate |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 189 | |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 190 | def get_deps(self, package) -> List[portage_util.InstalledPackage]: |
| 191 | """Return a list of dependencies. |
| 192 | |
| 193 | This expands the virtuals listed below. |
| 194 | """ |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 195 | cpvr = f"{package.category}/{package.pf}" |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 196 | expanded = [] |
| 197 | deps = [] |
| 198 | for dep in portage_util.GetFlattenedDepsForPackage( |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 199 | cpvr, board=self.board, depth=1 |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 200 | ): |
| 201 | info = package_info.parse(dep) |
| 202 | if not info: |
| 203 | continue |
| 204 | |
| 205 | cp = info.cp |
| 206 | if cp in VIRTUALS: |
| 207 | expanded += VIRTUALS[cp] |
| 208 | continue |
| 209 | |
| 210 | pkg = self.db.GetInstalledPackage(info.category, info.pvr) |
| 211 | if pkg: |
| 212 | deps.append(pkg) |
| 213 | |
| 214 | for dep in expanded: |
Mike Frysinger | 1e9ac7c | 2023-09-21 14:53:48 -0400 | [diff] [blame] | 215 | deps.extend(self.get_packages(dep)) |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 216 | |
| 217 | return deps |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 218 | |
| 219 | def get_implicit_libs(self): |
| 220 | """Return a set of .so files that are provided by the system.""" |
Allen Webb | 611e8b1 | 2023-09-13 15:54:52 +0000 | [diff] [blame] | 221 | # libstdc++ comes from the toolchain so always ignore it. |
| 222 | implicit_libs = {"libstdc++.so", "libstdc++.so.6"} |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 223 | for dep, from_sdk in ( |
| 224 | ("cross-aarch64-cros-linux-gnu/glibc", True), |
| 225 | ("cross-armv7a-cros-linux-gnueabihf/glibc", True), |
| 226 | ("cross-i686-cros-linux-gnu/glibc", True), |
| 227 | ("cross-x86_64-cros-linux-gnu/glibc", True), |
| 228 | ("sys-libs/glibc", False), |
| 229 | ("sys-libs/libcxx", False), |
| 230 | ("sys-libs/llvm-libunwind", False), |
| 231 | ): |
Mike Frysinger | 1e9ac7c | 2023-09-21 14:53:48 -0400 | [diff] [blame] | 232 | for pkg in self.get_packages(dep, from_sdk): |
| 233 | implicit_libs.update(self.provided_libs(pkg)) |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 234 | return implicit_libs |
| 235 | |
| 236 | def provided_libs(self, package: portage_util.InstalledPackage) -> Set[str]: |
| 237 | """Return a set of .so files provided by |package|.""" |
| 238 | cpvr = f"{package.category}/{package.pf}" |
| 239 | if cpvr in self.provided_libs_cache: |
| 240 | return self.provided_libs_cache[cpvr] |
| 241 | |
| 242 | libs = set() |
| 243 | contents = package.ListContents() |
| 244 | # Keep only the .so files |
| 245 | for typ, path in contents: |
| 246 | if typ == package.DIR: |
| 247 | continue |
| 248 | filename = os.path.basename(path) |
Mike Frysinger | 28f7b95 | 2023-09-21 11:40:01 -0400 | [diff] [blame] | 249 | if filename.endswith(".so") or ( |
| 250 | ".so." in filename and not filename.endswith(".debug") |
| 251 | ): |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 252 | libs.add(filename) |
| 253 | self.provided_libs_cache[cpvr] = libs |
| 254 | return libs |
| 255 | |
Allen Webb | 8fc0bba | 2023-09-11 14:37:25 +0000 | [diff] [blame] | 256 | def cache_libs_from_build( |
| 257 | self, package: portage_util.InstalledPackage, image_dir: Path |
| 258 | ): |
| 259 | """Populate the provided_libs_cache for the package from the image dir. |
| 260 | |
| 261 | When using build-info, CONTENTS might not be available yet. so provide |
| 262 | alternative using the destination directory of the ebuild. |
| 263 | """ |
| 264 | |
| 265 | cpvr = f"{package.category}/{package.pf}" |
| 266 | libs = set() |
| 267 | for _, _, files in os.walk(image_dir): |
| 268 | for file in files: |
Mike Frysinger | 28f7b95 | 2023-09-21 11:40:01 -0400 | [diff] [blame] | 269 | if file.endswith(".so") or ( |
| 270 | ".so." in file and not file.endswith(".debug") |
| 271 | ): |
Allen Webb | 8fc0bba | 2023-09-11 14:37:25 +0000 | [diff] [blame] | 272 | libs.add(os.path.basename(file)) |
| 273 | self.provided_libs_cache[cpvr] = libs |
| 274 | |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 275 | def get_provided_from_all_deps( |
| 276 | self, package: portage_util.InstalledPackage |
| 277 | ) -> Set[str]: |
| 278 | """Return a set of .so files provided by the immediate dependencies.""" |
| 279 | provided_libs = set() |
Allen Webb | 8fc0bba | 2023-09-11 14:37:25 +0000 | [diff] [blame] | 280 | # |package| may not actually be installed yet so manually add it to the |
| 281 | # since a package can depend on its own libs. |
| 282 | provided_libs.update(self.provided_libs(package)) |
Allen Webb | 7cc7cd9 | 2023-09-11 16:16:33 +0000 | [diff] [blame] | 283 | for pkg in self.get_deps(package): |
| 284 | provided_libs.update(self.provided_libs(pkg)) |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 285 | return provided_libs |
| 286 | |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 287 | def lib_to_package(self, lib_filename: str = None) -> Set[str]: |
| 288 | """Return a set of packages that contain the library.""" |
| 289 | if self.lib_to_package_map is None: |
| 290 | lookup = collections.defaultdict(set) |
| 291 | for pkg in self.db.InstalledPackages(): |
| 292 | cpvr = f"{pkg.category}/{pkg.pf}" |
| 293 | # Packages with bundled libs for internal use and/or standaline |
| 294 | # binary packages. |
| 295 | if f"{pkg.category}/{pkg.package}" in ( |
| 296 | "app-emulation/qemu", |
| 297 | "chromeos-base/aosp-frameworks-ml-nn-vts", |
| 298 | "chromeos-base/factory", |
| 299 | "chromeos-base/signingtools-bin", |
| 300 | "sys-devel/gcc-bin", |
| 301 | ): |
| 302 | continue |
| 303 | for lib in set(self.provided_libs(pkg)): |
| 304 | lookup[lib].add(cpvr) |
| 305 | self.lib_to_package_map = lookup |
| 306 | else: |
| 307 | lookup = self.lib_to_package_map |
| 308 | if not lib_filename: |
| 309 | return set() |
| 310 | try: |
| 311 | return lookup[lib_filename] |
| 312 | except KeyError: |
| 313 | return set() |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 314 | |
| 315 | |
| 316 | def get_parser() -> commandline.ArgumentParser: |
| 317 | """Build the argument parser.""" |
| 318 | parser = commandline.ArgumentParser(description=__doc__) |
| 319 | |
| 320 | parser.add_argument("package", nargs="*", help="package atom") |
| 321 | |
| 322 | parser.add_argument( |
| 323 | "-b", |
| 324 | "--board", |
| 325 | "--build-target", |
| 326 | default=cros_build_lib.GetDefaultBoard(), |
| 327 | help="ChromeOS board (Uses the SDK if not specified)", |
| 328 | ) |
| 329 | |
| 330 | parser.add_argument( |
Allen Webb | 7d34a9a | 2023-09-18 09:02:15 -0500 | [diff] [blame] | 331 | "--no-default-board", |
| 332 | dest="board", |
| 333 | const=None, |
| 334 | action="store_const", |
| 335 | help="Ignore the default board", |
| 336 | ) |
| 337 | |
| 338 | parser.add_argument( |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 339 | "-i", |
| 340 | "--build-info", |
| 341 | default=None, |
| 342 | type=Path, |
| 343 | help="Path to build-info folder post src_install", |
| 344 | ) |
| 345 | |
| 346 | parser.add_argument( |
Allen Webb | 8fc0bba | 2023-09-11 14:37:25 +0000 | [diff] [blame] | 347 | "-x", |
| 348 | "--image", |
| 349 | default=None, |
| 350 | type=Path, |
| 351 | help="Path to image folder post src_install (${D} if unspecified)", |
| 352 | ) |
| 353 | |
| 354 | parser.add_argument( |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 355 | "--match", |
| 356 | default=False, |
| 357 | action="store_true", |
| 358 | help="Try to match missing libraries", |
| 359 | ) |
| 360 | |
| 361 | parser.add_argument( |
| 362 | "-j", |
| 363 | "--jobs", |
| 364 | default=None, |
| 365 | type=int, |
| 366 | help="Number of parallel processes", |
| 367 | ) |
| 368 | |
| 369 | return parser |
| 370 | |
| 371 | |
| 372 | def parse_arguments(argv: List[str]) -> argparse.Namespace: |
| 373 | """Parse and validate arguments.""" |
| 374 | parser = get_parser() |
| 375 | opts = parser.parse_args(argv) |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 376 | if opts.build_info and opts.package: |
Allen Webb | 8fc0bba | 2023-09-11 14:37:25 +0000 | [diff] [blame] | 377 | parser.error("Do not specify a package when setting --board-info") |
| 378 | if opts.image and not opts.build_info: |
| 379 | parser.error("--image requires --board-info") |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 380 | if opts.build_info or len(opts.package) == 1: |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 381 | opts.jobs = 1 |
| 382 | return opts |
| 383 | |
| 384 | |
| 385 | def check_package( |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 386 | package: portage_util.InstalledPackage, |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 387 | implicit: Set[str], |
| 388 | resolver: DotSoResolver, |
| 389 | match: bool, |
| 390 | debug: bool, |
| 391 | ) -> bool: |
| 392 | """Returns false if the package has missing dependencies""" |
| 393 | if not package: |
| 394 | print("missing package") |
| 395 | return False |
| 396 | |
| 397 | provided = resolver.get_provided_from_all_deps(package) |
| 398 | if debug: |
| 399 | print("provided") |
| 400 | pprint.pprint(provided) |
| 401 | |
| 402 | available = provided.union(implicit) |
| 403 | required = resolver.get_required_libs(package) |
| 404 | if debug: |
| 405 | print("required") |
| 406 | pprint.pprint(required) |
| 407 | unsatisfied = required - available |
| 408 | if unsatisfied: |
| 409 | cpvr = package.package_info.cpvr |
| 410 | print(f"'{cpvr}' missing deps for: ", end="") |
| 411 | pprint.pprint(unsatisfied) |
| 412 | if match: |
| 413 | missing = set() |
| 414 | for lib in unsatisfied: |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 415 | missing.update(resolver.lib_to_package(lib)) |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 416 | if missing: |
| 417 | print(f"'{cpvr}' needs: ", end="") |
| 418 | pprint.pprint(missing) |
| 419 | return False |
| 420 | return True |
| 421 | |
| 422 | |
| 423 | def main(argv: Optional[List[str]]): |
| 424 | """Main.""" |
| 425 | opts = parse_arguments(argv) |
| 426 | opts.Freeze() |
| 427 | |
| 428 | board = opts.board |
| 429 | root = build_target_lib.get_default_sysroot_path(board) |
| 430 | if board: |
| 431 | os.environ["PORTAGE_CONFIGROOT"] = root |
| 432 | os.environ["SYSROOT"] = root |
| 433 | os.environ["ROOT"] = root |
| 434 | |
| 435 | failed = False |
| 436 | resolver = DotSoResolver(board, root) |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 437 | |
| 438 | if not opts.package: |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 439 | if opts.build_info: |
Allen Webb | 8fc0bba | 2023-09-11 14:37:25 +0000 | [diff] [blame] | 440 | pkg = portage_util.InstalledPackage(resolver.db, opts.build_info) |
| 441 | image_path = opts.image or os.environ.get("D") |
| 442 | if image_path: |
| 443 | resolver.cache_libs_from_build(pkg, Path(image_path)) |
| 444 | packages = [pkg] |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 445 | else: |
| 446 | packages = resolver.db.InstalledPackages() |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 447 | else: |
Mike Frysinger | 1e9ac7c | 2023-09-21 14:53:48 -0400 | [diff] [blame] | 448 | packages = [] |
| 449 | for pkg in opts.package: |
| 450 | packages.extend(resolver.get_packages(pkg)) |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 451 | |
| 452 | implicit = resolver.get_implicit_libs() |
| 453 | if opts.debug: |
| 454 | print("implicit") |
| 455 | pprint.pprint(implicit) |
| 456 | |
| 457 | if opts.jobs == 1: |
| 458 | for package in packages: |
| 459 | if not check_package( |
| 460 | package, |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 461 | implicit, |
| 462 | resolver, |
| 463 | opts.match, |
| 464 | opts.debug, |
| 465 | ): |
| 466 | failed = True |
| 467 | else: |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 468 | if opts.match: |
| 469 | # Pre initialize the map before starting jobs. |
| 470 | resolver.lib_to_package() |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 471 | for ret in parallel.RunTasksInProcessPool( |
| 472 | lambda p: check_package( |
Allen Webb | e8c1da0 | 2023-09-08 18:25:22 +0000 | [diff] [blame] | 473 | p, implicit, resolver, opts.match, opts.debug |
Allen Webb | 3e498aa | 2023-09-05 14:40:49 +0000 | [diff] [blame] | 474 | ), |
| 475 | [[p] for p in packages], |
| 476 | opts.jobs, |
| 477 | ): |
| 478 | if not ret: |
| 479 | failed = True |
| 480 | |
| 481 | if failed: |
| 482 | sys.exit(1) |
| 483 | |
| 484 | |
| 485 | if __name__ == "__main__": |
| 486 | main(sys.argv[1:]) |