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 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 28 | def _UprevResponse(_input_proto, output_proto, _config): |
| 29 | """Add fake paths to a successful uprev response.""" |
| 30 | output_proto.modified_ebuilds.add().path = '/fake/path1' |
| 31 | output_proto.modified_ebuilds.add().path = '/fake/path2' |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 32 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 33 | @faux.success(_UprevResponse) |
| 34 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 35 | @validate.require('overlay_type') |
| 36 | @validate.is_in('overlay_type', _OVERLAY_TYPE_TO_NAME) |
| 37 | @validate.validation_complete |
| 38 | def Uprev(input_proto, output_proto, _config): |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 39 | """Uprev all cros workon ebuilds that have changes.""" |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 40 | target_names = [t.name for t in input_proto.build_targets] |
| 41 | build_targets = [build_target_util.BuildTarget(t) for t in target_names] |
| 42 | overlay_type = _OVERLAY_TYPE_TO_NAME[input_proto.overlay_type] |
| 43 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 44 | output_dir = input_proto.output_dir or None |
| 45 | |
| 46 | try: |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 47 | uprevved = packages.uprev_build_targets(build_targets, overlay_type, chroot, |
| 48 | output_dir) |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 49 | except packages.Error as e: |
| 50 | # Handle module errors nicely, let everything else bubble up. |
Mike Frysinger | 6b5c3cd | 2019-08-27 16:51:00 -0400 | [diff] [blame] | 51 | cros_build_lib.Die(e) |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 52 | |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 53 | for path in uprevved: |
| 54 | output_proto.modified_ebuilds.add().path = path |
| 55 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 56 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 57 | def _UprevVersionedPackageResponse(_input_proto, output_proto, _config): |
| 58 | """Add fake paths to a successful uprev versioned package response.""" |
| 59 | uprev_response = output_proto.responses.add() |
| 60 | uprev_response.modified_ebuilds.add().path = '/uprev/response/path' |
| 61 | |
| 62 | |
| 63 | @faux.success(_UprevVersionedPackageResponse) |
| 64 | @faux.empty_error |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 65 | @validate.require('versions') |
| 66 | @validate.require('package_info.package_name', 'package_info.category') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 67 | @validate.validation_complete |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 68 | def UprevVersionedPackage(input_proto, output_proto, _config): |
Evan Hernandez | 38555d4 | 2019-08-05 15:11:54 -0600 | [diff] [blame] | 69 | """Uprev a versioned package. |
| 70 | |
| 71 | See go/pupr-generator for details about this endpoint. |
| 72 | """ |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 73 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 74 | build_targets = controller_util.ParseBuildTargets(input_proto.build_targets) |
| 75 | package = controller_util.PackageInfoToCPV(input_proto.package_info) |
| 76 | refs = [] |
| 77 | for ref in input_proto.versions: |
| 78 | refs.append(GitRef(path=ref.repository, ref=ref.ref, revision=ref.revision)) |
| 79 | |
| 80 | try: |
Alex Klein | 34afcbc | 2019-08-22 16:14:31 -0600 | [diff] [blame] | 81 | result = packages.uprev_versioned_package(package, build_targets, refs, |
| 82 | chroot) |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 83 | except packages.Error as e: |
| 84 | # Handle module errors nicely, let everything else bubble up. |
Mike Frysinger | 6b5c3cd | 2019-08-27 16:51:00 -0400 | [diff] [blame] | 85 | cros_build_lib.Die(e) |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 86 | |
Alex Klein | 34afcbc | 2019-08-22 16:14:31 -0600 | [diff] [blame] | 87 | if not result.uprevved: |
| 88 | # No uprevs executed, skip the output population. |
| 89 | return |
| 90 | |
Yaakov Shaul | 730814a | 2019-09-10 13:58:25 -0600 | [diff] [blame] | 91 | for modified in result.modified: |
| 92 | uprev_response = output_proto.responses.add() |
| 93 | uprev_response.version = modified.new_version |
| 94 | for path in modified.files: |
| 95 | uprev_response.modified_ebuilds.add().path = path |
| 96 | |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 97 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 98 | def _GetBestVisibleResponse(_input_proto, output_proto, _config): |
| 99 | """Add fake paths to a successful GetBestVisible response.""" |
| 100 | package_info = common_pb2.PackageInfo( |
| 101 | category='category', |
| 102 | package_name='name', |
| 103 | version='1.01', |
| 104 | ) |
| 105 | output_proto.package_info.CopyFrom(package_info) |
| 106 | |
| 107 | |
| 108 | @faux.success(_GetBestVisibleResponse) |
| 109 | @faux.empty_error |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 110 | @validate.require('atom') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 111 | @validate.validation_complete |
| 112 | def GetBestVisible(input_proto, output_proto, _config): |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 113 | """Returns the best visible PackageInfo for the indicated atom.""" |
Alex Klein | bbef2b3 | 2019-08-27 10:38:50 -0600 | [diff] [blame] | 114 | build_target = None |
| 115 | if input_proto.build_target.name: |
| 116 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 117 | |
| 118 | cpv = packages.get_best_visible(input_proto.atom, build_target=build_target) |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 119 | package_info = common_pb2.PackageInfo() |
| 120 | controller_util.CPVToPackageInfo(cpv, package_info) |
| 121 | output_proto.package_info.CopyFrom(package_info) |
Alex Klein | 551e805 | 2019-08-29 11:23:48 -0600 | [diff] [blame] | 122 | |
| 123 | |
Michael Mortensen | 68abdb7 | 2019-10-28 09:43:52 -0600 | [diff] [blame] | 124 | def _ChromeVersionResponse(_input_proto, output_proto, _config): |
| 125 | """Add a fake chrome version to a successful response.""" |
| 126 | output_proto.version = '78.0.3900.0' |
| 127 | |
| 128 | |
| 129 | @faux.success(_ChromeVersionResponse) |
| 130 | @faux.empty_error |
Alex Klein | 551e805 | 2019-08-29 11:23:48 -0600 | [diff] [blame] | 131 | @validate.require('build_target.name') |
| 132 | @validate.validation_complete |
| 133 | def GetChromeVersion(input_proto, output_proto, _config): |
| 134 | """Returns the chrome version.""" |
| 135 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Michael Mortensen | 9fe740c | 2019-10-29 14:42:48 -0600 | [diff] [blame] | 136 | chrome_version = packages.determine_chrome_version(build_target) |
| 137 | if chrome_version: |
| 138 | output_proto.version = chrome_version |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 139 | |
| 140 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 141 | def _GetTargetVersionsResponse(_input_proto, output_proto, _config): |
| 142 | """Add fake target version fields to a successful response.""" |
| 143 | output_proto.android_version = '5812377' |
| 144 | output_proto.android_branch_version = 'git_nyc-mr1-arc' |
| 145 | output_proto.android_target_version = 'cheets' |
| 146 | output_proto.chrome_version = '78.0.3900.0' |
| 147 | output_proto.platform_version = '12438.0.0' |
| 148 | output_proto.milestone_version = '78' |
| 149 | output_proto.full_version = 'R78-12438.0.0' |
| 150 | |
| 151 | |
| 152 | @faux.success(_GetTargetVersionsResponse) |
| 153 | @faux.empty_error |
Michael Mortensen | b70e8a8 | 2019-10-10 18:43:41 -0600 | [diff] [blame] | 154 | @validate.require('build_target.name') |
| 155 | @validate.validation_complete |
| 156 | def GetTargetVersions(input_proto, output_proto, _config): |
| 157 | """Returns the target versions.""" |
| 158 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Michael Mortensen | edf7653 | 2019-10-16 14:22:37 -0600 | [diff] [blame] | 159 | android_version = packages.determine_android_version([build_target]) |
| 160 | if android_version: |
| 161 | output_proto.android_version = android_version |
| 162 | android_branch_version = packages.determine_android_branch(build_target) |
| 163 | if android_branch_version: |
| 164 | output_proto.android_branch_version = android_branch_version |
| 165 | android_target_version = packages.determine_android_target(build_target) |
| 166 | if android_target_version: |
| 167 | output_proto.android_target_version = android_target_version |
Michael Mortensen | 9fe740c | 2019-10-29 14:42:48 -0600 | [diff] [blame] | 168 | # TODO(crbug/1019770): Investigate cases where builds_chrome is true but |
| 169 | # chrome_version is None. |
Michael Mortensen | 1d2ab0d | 2019-10-17 13:19:25 -0600 | [diff] [blame] | 170 | builds_chrome = packages.builds(constants.CHROME_CP, build_target) |
| 171 | if builds_chrome: |
Michael Mortensen | 9fe740c | 2019-10-29 14:42:48 -0600 | [diff] [blame] | 172 | chrome_version = packages.determine_chrome_version(build_target) |
| 173 | if chrome_version: |
| 174 | output_proto.chrome_version = chrome_version |
Michael Mortensen | 9fdb14b | 2019-10-17 11:17:30 -0600 | [diff] [blame] | 175 | output_proto.platform_version = packages.determine_platform_version() |
Michael Mortensen | 009cb66 | 2019-10-21 11:38:43 -0600 | [diff] [blame] | 176 | output_proto.milestone_version = packages.determine_milestone_version() |
| 177 | output_proto.full_version = packages.determine_full_version() |
Michael Mortensen | b70e8a8 | 2019-10-10 18:43:41 -0600 | [diff] [blame] | 178 | |
| 179 | |
Michael Mortensen | 68abdb7 | 2019-10-28 09:43:52 -0600 | [diff] [blame] | 180 | def _HasChromePrebuiltSuccess(_input_proto, output_proto, _config): |
| 181 | """The mock success case for HasChromePrebuilt.""" |
| 182 | output_proto.has_prebuilt = True |
| 183 | |
| 184 | |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 185 | @faux.success(_HasChromePrebuiltSuccess) |
| 186 | @faux.empty_error |
| 187 | @validate.require('build_target.name') |
| 188 | @validate.validation_complete |
| 189 | def HasChromePrebuilt(input_proto, output_proto, _config): |
| 190 | """Checks if the most recent version of Chrome has a prebuilt.""" |
| 191 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 192 | exists = packages.has_prebuilt(constants.CHROME_CP, build_target=build_target) |
| 193 | |
| 194 | output_proto.has_prebuilt = exists |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 195 | |
| 196 | |
| 197 | def _BuildsChromeSuccess(_input_proto, output_proto, _config): |
| 198 | """Mock success case for BuildsChrome.""" |
| 199 | output_proto.builds_chrome = True |
| 200 | |
| 201 | |
| 202 | @faux.success(_BuildsChromeSuccess) |
| 203 | @faux.empty_error |
| 204 | @validate.require('build_target.name') |
| 205 | @validate.validation_complete |
| 206 | def BuildsChrome(input_proto, output_proto, _config): |
| 207 | """Check if the board builds chrome.""" |
Alex Klein | e65131f | 2019-10-03 10:34:01 -0600 | [diff] [blame] | 208 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
David Burger | 0f9dd4e | 2019-10-08 12:33:42 -0600 | [diff] [blame] | 209 | cpvs = [controller_util.PackageInfoToCPV(pi) for pi in input_proto.packages] |
| 210 | builds_chrome = packages.builds(constants.CHROME_CP, build_target, cpvs) |
Alex Klein | e65131f | 2019-10-03 10:34:01 -0600 | [diff] [blame] | 211 | output_proto.builds_chrome = builds_chrome |