Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Package utility functionality.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 10 | from chromite.lib import constants |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 11 | from chromite.lib import git |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 12 | from chromite.lib import portage_util |
Alex Klein | d6195b6 | 2019-08-06 16:01:16 -0600 | [diff] [blame] | 13 | from chromite.lib import uprev_lib |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 14 | |
| 15 | |
| 16 | class Error(Exception): |
| 17 | """Module's base error class.""" |
| 18 | |
| 19 | |
| 20 | class UprevError(Error): |
| 21 | """An error occurred while uprevving packages.""" |
| 22 | |
| 23 | |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 24 | def uprev_build_targets(build_targets, overlay_type, chroot=None, |
| 25 | output_dir=None): |
| 26 | """Uprev the set provided build targets, or all if not specified. |
| 27 | |
| 28 | Args: |
| 29 | build_targets (list[build_target_util.BuildTarget]|None): The build targets |
| 30 | whose overlays should be uprevved, empty or None for all. |
| 31 | overlay_type (str): One of the valid overlay types except None (see |
| 32 | constants.VALID_OVERLAYS). |
| 33 | chroot (chroot_lib.Chroot|None): The chroot to clean, if desired. |
| 34 | output_dir (str|None): The path to optionally dump result files. |
| 35 | """ |
| 36 | # Need a valid overlay, but exclude None. |
| 37 | assert overlay_type and overlay_type in constants.VALID_OVERLAYS |
| 38 | |
| 39 | if build_targets: |
| 40 | overlays = portage_util.FindOverlaysForBoards( |
| 41 | overlay_type, boards=[t.name for t in build_targets]) |
| 42 | else: |
| 43 | overlays = portage_util.FindOverlays(overlay_type) |
| 44 | |
| 45 | return uprev_overlays(overlays, build_targets=build_targets, chroot=chroot, |
| 46 | output_dir=output_dir) |
| 47 | |
| 48 | |
| 49 | def uprev_overlays(overlays, build_targets=None, chroot=None, output_dir=None): |
| 50 | """Uprev the given overlays. |
| 51 | |
| 52 | Args: |
| 53 | overlays (list[str]): The list of overlay paths. |
| 54 | build_targets (list[build_target_util.BuildTarget]|None): The build targets |
| 55 | to clean in |chroot|, if desired. No effect unless |chroot| is provided. |
| 56 | chroot (chroot_lib.Chroot|None): The chroot to clean, if desired. |
| 57 | output_dir (str|None): The path to optionally dump result files. |
| 58 | |
| 59 | Returns: |
| 60 | list[str] - The paths to all of the modified ebuild files. This includes the |
| 61 | new files that were added (i.e. the new versions) and all of the removed |
| 62 | files (i.e. the old versions). |
| 63 | """ |
| 64 | assert overlays |
| 65 | |
| 66 | manifest = git.ManifestCheckout.Cached(constants.SOURCE_ROOT) |
| 67 | |
Alex Klein | d6195b6 | 2019-08-06 16:01:16 -0600 | [diff] [blame] | 68 | uprev_manager = uprev_lib.UprevOverlayManager(overlays, manifest, |
| 69 | build_targets=build_targets, |
| 70 | chroot=chroot, |
| 71 | output_dir=output_dir) |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 72 | uprev_manager.uprev() |
| 73 | |
| 74 | return uprev_manager.modified_ebuilds |
| 75 | |
| 76 | |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 77 | def get_best_visible(atom): |
| 78 | """Returns the best visible CPV for the given atom.""" |
| 79 | assert atom |
| 80 | return portage_util.PortageqBestVisible(atom) |