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