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 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 10 | from chromite.api import faux |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 11 | from chromite.api import validate |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 12 | from chromite.api.controller import controller_util |
| 13 | from chromite.api.gen.chromite.api import binhost_pb2 |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 14 | from chromite.api.gen.chromiumos import common_pb2 |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 15 | from chromite.lib import build_target_util |
| 16 | from chromite.lib import constants |
| 17 | from chromite.lib import cros_build_lib |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 18 | from chromite.lib.uprev_lib import GitRef |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 19 | from chromite.service import packages |
| 20 | |
| 21 | |
| 22 | _OVERLAY_TYPE_TO_NAME = { |
| 23 | binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS, |
| 24 | binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS, |
| 25 | binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS, |
| 26 | } |
| 27 | |
| 28 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 29 | @faux.all_empty |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 30 | @validate.require('overlay_type') |
| 31 | @validate.is_in('overlay_type', _OVERLAY_TYPE_TO_NAME) |
| 32 | @validate.validation_complete |
| 33 | def Uprev(input_proto, output_proto, _config): |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 34 | """Uprev all cros workon ebuilds that have changes.""" |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 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 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 51 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 52 | @faux.all_empty |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 53 | @validate.require('versions') |
| 54 | @validate.require('package_info.package_name', 'package_info.category') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 55 | @validate.validation_complete |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 56 | def UprevVersionedPackage(input_proto, output_proto, _config): |
Evan Hernandez | 38555d4 | 2019-08-05 15:11:54 -0600 | [diff] [blame] | 57 | """Uprev a versioned package. |
| 58 | |
| 59 | See go/pupr-generator for details about this endpoint. |
| 60 | """ |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 61 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 62 | build_targets = controller_util.ParseBuildTargets(input_proto.build_targets) |
| 63 | package = controller_util.PackageInfoToCPV(input_proto.package_info) |
| 64 | refs = [] |
| 65 | for ref in input_proto.versions: |
| 66 | refs.append(GitRef(path=ref.repository, ref=ref.ref, revision=ref.revision)) |
| 67 | |
| 68 | try: |
Alex Klein | 34afcbc | 2019-08-22 16:14:31 -0600 | [diff] [blame] | 69 | result = packages.uprev_versioned_package(package, build_targets, refs, |
| 70 | chroot) |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 71 | except packages.Error as e: |
| 72 | # Handle module errors nicely, let everything else bubble up. |
| 73 | cros_build_lib.Die(e.message) |
| 74 | |
Alex Klein | 34afcbc | 2019-08-22 16:14:31 -0600 | [diff] [blame] | 75 | if not result.uprevved: |
| 76 | # No uprevs executed, skip the output population. |
| 77 | return |
| 78 | |
Yaakov Shaul | 730814a | 2019-09-10 13:58:25 -0600 | [diff] [blame^] | 79 | for modified in result.modified: |
| 80 | uprev_response = output_proto.responses.add() |
| 81 | uprev_response.version = modified.new_version |
| 82 | for path in modified.files: |
| 83 | uprev_response.modified_ebuilds.add().path = path |
| 84 | |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 85 | |
Evan Hernandez | 38555d4 | 2019-08-05 15:11:54 -0600 | [diff] [blame] | 86 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 87 | @faux.all_empty |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 88 | @validate.require('atom') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 89 | @validate.validation_complete |
| 90 | def GetBestVisible(input_proto, output_proto, _config): |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 91 | """Returns the best visible PackageInfo for the indicated atom.""" |
Alex Klein | bbef2b3 | 2019-08-27 10:38:50 -0600 | [diff] [blame] | 92 | build_target = None |
| 93 | if input_proto.build_target.name: |
| 94 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 95 | |
| 96 | cpv = packages.get_best_visible(input_proto.atom, build_target=build_target) |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 97 | package_info = common_pb2.PackageInfo() |
| 98 | controller_util.CPVToPackageInfo(cpv, package_info) |
| 99 | output_proto.package_info.CopyFrom(package_info) |
Alex Klein | 551e805 | 2019-08-29 11:23:48 -0600 | [diff] [blame] | 100 | |
| 101 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 102 | @faux.all_empty |
Alex Klein | 551e805 | 2019-08-29 11:23:48 -0600 | [diff] [blame] | 103 | @validate.require('build_target.name') |
| 104 | @validate.validation_complete |
| 105 | def GetChromeVersion(input_proto, output_proto, _config): |
| 106 | """Returns the chrome version.""" |
| 107 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 108 | cpv = packages.get_best_visible( |
| 109 | constants.CHROME_CP, build_target=build_target) |
| 110 | |
| 111 | # Something like 1.2.3.4_rc -> 1.2.3.4. |
| 112 | output_proto.version = cpv.version_no_rev.split('_')[0] |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 113 | |
| 114 | |
| 115 | def _HasChromePrebuiltSuccess(_input_proto, output_proto, _config): |
| 116 | """The mock success case for HasChromePrebuilt.""" |
| 117 | output_proto.has_prebuilt = True |
| 118 | |
| 119 | |
| 120 | @faux.success(_HasChromePrebuiltSuccess) |
| 121 | @faux.empty_error |
| 122 | @validate.require('build_target.name') |
| 123 | @validate.validation_complete |
| 124 | def HasChromePrebuilt(input_proto, output_proto, _config): |
| 125 | """Checks if the most recent version of Chrome has a prebuilt.""" |
| 126 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 127 | exists = packages.has_prebuilt(constants.CHROME_CP, build_target=build_target) |
| 128 | |
| 129 | output_proto.has_prebuilt = exists |