blob: 0781a8e145f6293da5476a15542159c7f4fce1f7 [file] [log] [blame]
Alex Kleineb77ffa2019-05-28 14:47:44 -06001# -*- 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
8from __future__ import print_function
9
Alex Kleineb77ffa2019-05-28 14:47:44 -060010from chromite.lib import constants
Alex Kleineb77ffa2019-05-28 14:47:44 -060011from chromite.lib import git
Alex Kleineb77ffa2019-05-28 14:47:44 -060012from chromite.lib import portage_util
Alex Kleind6195b62019-08-06 16:01:16 -060013from chromite.lib import uprev_lib
Alex Kleineb77ffa2019-05-28 14:47:44 -060014
15
16class Error(Exception):
17 """Module's base error class."""
18
19
20class UprevError(Error):
21 """An error occurred while uprevving packages."""
22
23
Alex Kleineb77ffa2019-05-28 14:47:44 -060024def 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
49def 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 Kleind6195b62019-08-06 16:01:16 -060068 uprev_manager = uprev_lib.UprevOverlayManager(overlays, manifest,
69 build_targets=build_targets,
70 chroot=chroot,
71 output_dir=output_dir)
Alex Kleineb77ffa2019-05-28 14:47:44 -060072 uprev_manager.uprev()
73
74 return uprev_manager.modified_ebuilds
75
76
David Burger1e0fe232019-07-01 14:52:07 -060077def get_best_visible(atom):
78 """Returns the best visible CPV for the given atom."""
79 assert atom
80 return portage_util.PortageqBestVisible(atom)