blob: cfb09ee1830736abfe1f9d81a9fc664919aeed5c [file] [log] [blame]
Alex Kleineb77ffa2019-05-28 14:47:44 -06001# -*- 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
8from __future__ import print_function
9
Alex Klein076841b2019-08-29 15:19:39 -060010from chromite.api import faux
David Burger1e0fe232019-07-01 14:52:07 -060011from chromite.api import validate
Alex Kleineb77ffa2019-05-28 14:47:44 -060012from chromite.api.controller import controller_util
13from chromite.api.gen.chromite.api import binhost_pb2
David Burger1e0fe232019-07-01 14:52:07 -060014from chromite.api.gen.chromiumos import common_pb2
Alex Kleineb77ffa2019-05-28 14:47:44 -060015from chromite.lib import build_target_util
16from chromite.lib import constants
17from chromite.lib import cros_build_lib
Alex Klein87531182019-08-12 15:23:37 -060018from chromite.lib.uprev_lib import GitRef
Alex Kleineb77ffa2019-05-28 14:47:44 -060019from 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 Mortensen2677bf62019-10-29 08:31:25 -060028def _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 Kleineb77ffa2019-05-28 14:47:44 -060032
Michael Mortensen2677bf62019-10-29 08:31:25 -060033@faux.success(_UprevResponse)
34@faux.empty_error
Alex Klein231d2da2019-07-22 16:44:45 -060035@validate.require('overlay_type')
36@validate.is_in('overlay_type', _OVERLAY_TYPE_TO_NAME)
37@validate.validation_complete
38def Uprev(input_proto, output_proto, _config):
Alex Kleineb77ffa2019-05-28 14:47:44 -060039 """Uprev all cros workon ebuilds that have changes."""
Alex Kleineb77ffa2019-05-28 14:47:44 -060040 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 Klein5dd6b1e2019-07-31 15:45:24 -060047 uprevved = packages.uprev_build_targets(build_targets, overlay_type, chroot,
48 output_dir)
Alex Kleineb77ffa2019-05-28 14:47:44 -060049 except packages.Error as e:
50 # Handle module errors nicely, let everything else bubble up.
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -040051 cros_build_lib.Die(e)
David Burger1e0fe232019-07-01 14:52:07 -060052
Alex Klein5dd6b1e2019-07-31 15:45:24 -060053 for path in uprevved:
54 output_proto.modified_ebuilds.add().path = path
55
Alex Klein231d2da2019-07-22 16:44:45 -060056
Michael Mortensen2677bf62019-10-29 08:31:25 -060057def _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 Klein87531182019-08-12 15:23:37 -060065@validate.require('versions')
66@validate.require('package_info.package_name', 'package_info.category')
Alex Klein231d2da2019-07-22 16:44:45 -060067@validate.validation_complete
Alex Klein87531182019-08-12 15:23:37 -060068def UprevVersionedPackage(input_proto, output_proto, _config):
Evan Hernandez38555d42019-08-05 15:11:54 -060069 """Uprev a versioned package.
70
71 See go/pupr-generator for details about this endpoint.
72 """
Alex Klein87531182019-08-12 15:23:37 -060073 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 Klein34afcbc2019-08-22 16:14:31 -060081 result = packages.uprev_versioned_package(package, build_targets, refs,
82 chroot)
Alex Klein87531182019-08-12 15:23:37 -060083 except packages.Error as e:
84 # Handle module errors nicely, let everything else bubble up.
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -040085 cros_build_lib.Die(e)
Alex Klein87531182019-08-12 15:23:37 -060086
Alex Klein34afcbc2019-08-22 16:14:31 -060087 if not result.uprevved:
88 # No uprevs executed, skip the output population.
89 return
90
Yaakov Shaul730814a2019-09-10 13:58:25 -060091 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 Klein87531182019-08-12 15:23:37 -060097
Michael Mortensen2677bf62019-10-29 08:31:25 -060098def _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 Burger1e0fe232019-07-01 14:52:07 -0600110@validate.require('atom')
Alex Klein231d2da2019-07-22 16:44:45 -0600111@validate.validation_complete
112def GetBestVisible(input_proto, output_proto, _config):
David Burger1e0fe232019-07-01 14:52:07 -0600113 """Returns the best visible PackageInfo for the indicated atom."""
Alex Kleinbbef2b32019-08-27 10:38:50 -0600114 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 Burger1e0fe232019-07-01 14:52:07 -0600119 package_info = common_pb2.PackageInfo()
120 controller_util.CPVToPackageInfo(cpv, package_info)
121 output_proto.package_info.CopyFrom(package_info)
Alex Klein551e8052019-08-29 11:23:48 -0600122
123
Michael Mortensen68abdb72019-10-28 09:43:52 -0600124def _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 Klein551e8052019-08-29 11:23:48 -0600131@validate.require('build_target.name')
132@validate.validation_complete
133def GetChromeVersion(input_proto, output_proto, _config):
134 """Returns the chrome version."""
135 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Michael Mortensen9fe740c2019-10-29 14:42:48 -0600136 chrome_version = packages.determine_chrome_version(build_target)
137 if chrome_version:
138 output_proto.version = chrome_version
Alex Kleinda39c6d2019-09-16 14:36:36 -0600139
140
Michael Mortensen2677bf62019-10-29 08:31:25 -0600141def _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 Mortensenb70e8a82019-10-10 18:43:41 -0600154@validate.require('build_target.name')
155@validate.validation_complete
156def GetTargetVersions(input_proto, output_proto, _config):
157 """Returns the target versions."""
158 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Michael Mortensenedf76532019-10-16 14:22:37 -0600159 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 Mortensen9fe740c2019-10-29 14:42:48 -0600168 # TODO(crbug/1019770): Investigate cases where builds_chrome is true but
169 # chrome_version is None.
Michael Mortensen1d2ab0d2019-10-17 13:19:25 -0600170 builds_chrome = packages.builds(constants.CHROME_CP, build_target)
171 if builds_chrome:
Michael Mortensen9fe740c2019-10-29 14:42:48 -0600172 chrome_version = packages.determine_chrome_version(build_target)
173 if chrome_version:
174 output_proto.chrome_version = chrome_version
Michael Mortensen9fdb14b2019-10-17 11:17:30 -0600175 output_proto.platform_version = packages.determine_platform_version()
Michael Mortensen009cb662019-10-21 11:38:43 -0600176 output_proto.milestone_version = packages.determine_milestone_version()
177 output_proto.full_version = packages.determine_full_version()
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600178
179
Michael Mortensen68abdb72019-10-28 09:43:52 -0600180def _HasChromePrebuiltSuccess(_input_proto, output_proto, _config):
181 """The mock success case for HasChromePrebuilt."""
182 output_proto.has_prebuilt = True
183
184
Alex Kleinda39c6d2019-09-16 14:36:36 -0600185@faux.success(_HasChromePrebuiltSuccess)
186@faux.empty_error
187@validate.require('build_target.name')
188@validate.validation_complete
189def 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 Klein73fb6572019-09-30 16:55:23 -0600195
196
197def _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
206def BuildsChrome(input_proto, output_proto, _config):
207 """Check if the board builds chrome."""
Alex Kleine65131f2019-10-03 10:34:01 -0600208 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
David Burger0f9dd4e2019-10-08 12:33:42 -0600209 cpvs = [controller_util.PackageInfoToCPV(pi) for pi in input_proto.packages]
210 builds_chrome = packages.builds(constants.CHROME_CP, build_target, cpvs)
Alex Kleine65131f2019-10-03 10:34:01 -0600211 output_proto.builds_chrome = builds_chrome