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 related functionality.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 10 | from chromite.api import validate |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 11 | from chromite.api.controller import controller_util |
| 12 | from chromite.api.gen.chromite.api import binhost_pb2 |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 13 | from chromite.api.gen.chromiumos import common_pb2 |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 14 | from chromite.lib import build_target_util |
| 15 | from chromite.lib import constants |
| 16 | from chromite.lib import cros_build_lib |
| 17 | from chromite.service import packages |
| 18 | |
| 19 | |
| 20 | _OVERLAY_TYPE_TO_NAME = { |
| 21 | binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS, |
| 22 | binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS, |
| 23 | binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS, |
| 24 | } |
| 25 | |
| 26 | |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 27 | def Uprev(input_proto, output_proto): |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 28 | """Uprev all cros workon ebuilds that have changes.""" |
| 29 | if not input_proto.overlay_type: |
| 30 | cros_build_lib.Die('Overlay type is required.') |
| 31 | elif input_proto.overlay_type not in _OVERLAY_TYPE_TO_NAME: |
| 32 | cros_build_lib.Die('Overlay type must be one of: %s', |
| 33 | ', '.join(_OVERLAY_TYPE_TO_NAME.values())) |
| 34 | |
| 35 | target_names = [t.name for t in input_proto.build_targets] |
| 36 | build_targets = [build_target_util.BuildTarget(t) for t in target_names] |
| 37 | overlay_type = _OVERLAY_TYPE_TO_NAME[input_proto.overlay_type] |
| 38 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 39 | output_dir = input_proto.output_dir or None |
| 40 | |
| 41 | try: |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 42 | uprevved = packages.uprev_build_targets(build_targets, overlay_type, chroot, |
| 43 | output_dir) |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 44 | except packages.Error as e: |
| 45 | # Handle module errors nicely, let everything else bubble up. |
| 46 | cros_build_lib.Die(e.message) |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 47 | |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 48 | for path in uprevved: |
| 49 | output_proto.modified_ebuilds.add().path = path |
| 50 | |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 51 | @validate.require('atom') |
| 52 | def GetBestVisible(input_proto, output_proto): |
| 53 | """Returns the best visible PackageInfo for the indicated atom.""" |
| 54 | cpv = packages.get_best_visible(input_proto.atom) |
| 55 | package_info = common_pb2.PackageInfo() |
| 56 | controller_util.CPVToPackageInfo(cpv, package_info) |
| 57 | output_proto.package_info.CopyFrom(package_info) |