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 |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame^] | 17 | from chromite.lib.uprev_lib import GitRef |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 18 | from chromite.service import packages |
| 19 | |
| 20 | |
| 21 | _OVERLAY_TYPE_TO_NAME = { |
| 22 | binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS, |
| 23 | binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS, |
| 24 | binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS, |
| 25 | } |
| 26 | |
| 27 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 28 | @validate.require('overlay_type') |
| 29 | @validate.is_in('overlay_type', _OVERLAY_TYPE_TO_NAME) |
| 30 | @validate.validation_complete |
| 31 | def Uprev(input_proto, output_proto, _config): |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 32 | """Uprev all cros workon ebuilds that have changes.""" |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 33 | target_names = [t.name for t in input_proto.build_targets] |
| 34 | build_targets = [build_target_util.BuildTarget(t) for t in target_names] |
| 35 | overlay_type = _OVERLAY_TYPE_TO_NAME[input_proto.overlay_type] |
| 36 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 37 | output_dir = input_proto.output_dir or None |
| 38 | |
| 39 | try: |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 40 | uprevved = packages.uprev_build_targets(build_targets, overlay_type, chroot, |
| 41 | output_dir) |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 42 | except packages.Error as e: |
| 43 | # Handle module errors nicely, let everything else bubble up. |
| 44 | cros_build_lib.Die(e.message) |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 45 | |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 46 | for path in uprevved: |
| 47 | output_proto.modified_ebuilds.add().path = path |
| 48 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 49 | |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame^] | 50 | @validate.require('versions') |
| 51 | @validate.require('package_info.package_name', 'package_info.category') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 52 | @validate.validation_complete |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame^] | 53 | def UprevVersionedPackage(input_proto, output_proto, _config): |
Evan Hernandez | 38555d4 | 2019-08-05 15:11:54 -0600 | [diff] [blame] | 54 | """Uprev a versioned package. |
| 55 | |
| 56 | See go/pupr-generator for details about this endpoint. |
| 57 | """ |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame^] | 58 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 59 | build_targets = controller_util.ParseBuildTargets(input_proto.build_targets) |
| 60 | package = controller_util.PackageInfoToCPV(input_proto.package_info) |
| 61 | refs = [] |
| 62 | for ref in input_proto.versions: |
| 63 | refs.append(GitRef(path=ref.repository, ref=ref.ref, revision=ref.revision)) |
| 64 | |
| 65 | try: |
| 66 | uprevved = packages.uprev_versioned_package(package, build_targets, refs, |
| 67 | chroot) |
| 68 | except packages.Error as e: |
| 69 | # Handle module errors nicely, let everything else bubble up. |
| 70 | cros_build_lib.Die(e.message) |
| 71 | |
| 72 | for path in uprevved: |
| 73 | output_proto.modified_ebuilds.add().path = path |
| 74 | |
Evan Hernandez | 38555d4 | 2019-08-05 15:11:54 -0600 | [diff] [blame] | 75 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 76 | |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 77 | @validate.require('atom') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 78 | @validate.validation_complete |
| 79 | def GetBestVisible(input_proto, output_proto, _config): |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 80 | """Returns the best visible PackageInfo for the indicated atom.""" |
| 81 | cpv = packages.get_best_visible(input_proto.atom) |
| 82 | package_info = common_pb2.PackageInfo() |
| 83 | controller_util.CPVToPackageInfo(cpv, package_info) |
| 84 | output_proto.package_info.CopyFrom(package_info) |