blob: 8d9f533f4e894dfee28642513e049216d24c03ff [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2019 The ChromiumOS Authors
Evan Hernandezd437b4e2019-03-25 13:48:30 -06002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Portage Binhost operations."""
6
Michael Mortensenfc823882019-08-27 14:38:07 -06007import os
8import shutil
Kevin Shelton703b6882022-01-24 16:31:31 -08009from typing import TYPE_CHECKING
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040010import urllib.parse
Evan Hernandezd437b4e2019-03-25 13:48:30 -060011
Alex Klein231d2da2019-07-22 16:44:45 -060012from chromite.api import controller
Alex Klein076841b2019-08-29 15:19:39 -060013from chromite.api import faux
Alex Klein2b236722019-06-19 15:44:26 -060014from chromite.api import validate
Alex Kleinaf0e0452019-06-03 18:10:01 -060015from chromite.api.controller import controller_util
Evan Hernandezd437b4e2019-03-25 13:48:30 -060016from chromite.api.gen.chromite.api import binhost_pb2
Greg Edelston724c13d2023-04-07 16:19:24 -060017from chromite.lib import binpkg
LaMont Jonesc64ae212019-04-15 15:41:28 -060018from chromite.lib import constants
19from chromite.lib import cros_build_lib
Evan Hernandezd437b4e2019-03-25 13:48:30 -060020from chromite.lib import gs
Cindy Lind4c122a2023-04-13 19:09:31 +000021from chromite.lib import osutils
Alex Kleinaf0e0452019-06-03 18:10:01 -060022from chromite.lib import sysroot_lib
Evan Hernandezd437b4e2019-03-25 13:48:30 -060023from chromite.service import binhost
24
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040025
Kevin Shelton703b6882022-01-24 16:31:31 -080026if TYPE_CHECKING:
Alex Klein1699fab2022-09-08 08:46:06 -060027 from chromite.api import api_config
Mike Frysingeref94e4c2020-02-10 23:59:54 -050028
Alex Kleinaf0e0452019-06-03 18:10:01 -060029_OVERLAY_TYPE_TO_NAME = {
30 binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS,
31 binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS,
32 binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS,
Alex Klein1699fab2022-09-08 08:46:06 -060033 binhost_pb2.OVERLAYTYPE_NONE: None,
Alex Kleinaf0e0452019-06-03 18:10:01 -060034}
35
Arif Kasim6242cdd2022-10-19 17:51:00 +000036# Default maximum number of URIs to be stored in Binhost conf file.
37_DEFAULT_BINHOST_MAX_URIS = 1
38
Evan Hernandezd437b4e2019-03-25 13:48:30 -060039
Michael Mortensena0af77b2019-11-13 11:15:15 -070040def _GetBinhostsResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060041 """Add fake binhosts to a successful response."""
42 new_binhost = output_proto.binhosts.add()
43 new_binhost.uri = (
44 "gs://cr-prebuilt/board/amd64-generic/"
45 "paladin-R66-17.0.0-rc2/packages/"
46 )
47 new_binhost.package_index = "Packages"
Michael Mortensena0af77b2019-11-13 11:15:15 -070048
49
50@faux.success(_GetBinhostsResponse)
51@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -060052@validate.require("build_target.name")
Alex Klein231d2da2019-07-22 16:44:45 -060053@validate.validation_complete
54def GetBinhosts(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060055 """Get a list of binhosts."""
56 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Alex Klein7e40d252019-06-10 09:01:32 -060057
Alex Klein1699fab2022-09-08 08:46:06 -060058 binhosts = binhost.GetBinhosts(build_target)
Alex Klein7e40d252019-06-10 09:01:32 -060059
Alex Klein1699fab2022-09-08 08:46:06 -060060 for current in binhosts:
61 new_binhost = output_proto.binhosts.add()
62 new_binhost.uri = current
63 new_binhost.package_index = "Packages"
Alex Klein7e40d252019-06-10 09:01:32 -060064
65
Michael Mortensen42251f92019-11-14 11:01:43 -070066def _GetPrivatePrebuiltAclArgsResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060067 """Add fake acls to a successful response."""
68 new_arg = output_proto.args.add()
69 new_arg.arg = "-g"
70 new_arg.value = "group1:READ"
Michael Mortensen42251f92019-11-14 11:01:43 -070071
72
73@faux.success(_GetPrivatePrebuiltAclArgsResponse)
74@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -060075@validate.require("build_target.name")
Alex Klein231d2da2019-07-22 16:44:45 -060076@validate.validation_complete
77def GetPrivatePrebuiltAclArgs(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060078 """Get the ACL args from the files in the private overlays."""
79 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Alex Kleina471f682019-05-31 11:23:45 -060080
Alex Klein1699fab2022-09-08 08:46:06 -060081 try:
82 args = binhost.GetPrebuiltAclArgs(build_target)
83 except binhost.Error as e:
84 cros_build_lib.Die(e)
Alex Kleina471f682019-05-31 11:23:45 -060085
Alex Klein1699fab2022-09-08 08:46:06 -060086 for arg, value in args:
87 new_arg = output_proto.args.add()
88 new_arg.arg = arg
89 new_arg.value = value
Alex Kleina471f682019-05-31 11:23:45 -060090
91
Michael Mortensen42251f92019-11-14 11:01:43 -070092def _PrepareBinhostUploadsResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060093 """Add fake binhost upload targets to a successful response."""
94 output_proto.uploads_dir = "/upload/directory"
95 output_proto.upload_targets.add().path = "upload_target"
Michael Mortensen42251f92019-11-14 11:01:43 -070096
97
98@faux.success(_PrepareBinhostUploadsResponse)
99@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600100@validate.require("uri")
Kevin Shelton703b6882022-01-24 16:31:31 -0800101def PrepareBinhostUploads(
102 input_proto: binhost_pb2.PrepareBinhostUploadsRequest,
103 output_proto: binhost_pb2.PrepareBinhostUploadsResponse,
Alex Klein1699fab2022-09-08 08:46:06 -0600104 config: "api_config.ApiConfig",
105):
106 """Return a list of files to upload to the binhost.
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600107
Alex Klein1699fab2022-09-08 08:46:06 -0600108 See BinhostService documentation in api/proto/binhost.proto.
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600109
Alex Klein1699fab2022-09-08 08:46:06 -0600110 Args:
Alex Klein611dddd2022-10-11 17:02:01 -0600111 input_proto: The input proto.
112 output_proto: The output proto.
113 config: The API call config.
Alex Klein1699fab2022-09-08 08:46:06 -0600114 """
115 if input_proto.sysroot.build_target.name:
116 build_target_msg = input_proto.sysroot.build_target
117 else:
118 build_target_msg = input_proto.build_target
119 sysroot_path = input_proto.sysroot.path
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600120
Alex Klein1699fab2022-09-08 08:46:06 -0600121 if not sysroot_path and not build_target_msg.name:
122 cros_build_lib.Die("Sysroot.path is required.")
Alex Kleinaf0e0452019-06-03 18:10:01 -0600123
Alex Klein1699fab2022-09-08 08:46:06 -0600124 build_target = controller_util.ParseBuildTarget(build_target_msg)
125 chroot = controller_util.ParseChroot(input_proto.chroot)
Alex Kleinaf0e0452019-06-03 18:10:01 -0600126
Alex Klein1699fab2022-09-08 08:46:06 -0600127 if not sysroot_path:
128 sysroot_path = build_target.root
129 sysroot = sysroot_lib.Sysroot(sysroot_path)
Alex Kleinaf0e0452019-06-03 18:10:01 -0600130
Alex Klein1699fab2022-09-08 08:46:06 -0600131 uri = input_proto.uri
132 # For now, we enforce that all input URIs are Google Storage buckets.
133 if not gs.PathIsGs(uri):
134 raise ValueError("Upload URI %s must be Google Storage." % uri)
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600135
Alex Kleina0472ed2022-11-02 12:07:04 -0600136 package_index_paths = [f.path.path for f in input_proto.package_index_files]
137
Alex Klein1699fab2022-09-08 08:46:06 -0600138 if config.validate_only:
139 return controller.RETURN_CODE_VALID_INPUT
Alex Klein231d2da2019-07-22 16:44:45 -0600140
Alex Klein1699fab2022-09-08 08:46:06 -0600141 parsed_uri = urllib.parse.urlparse(uri)
142 upload_uri = gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip("/")
143 upload_path = parsed_uri.path.lstrip("/")
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600144
Alex Klein1699fab2022-09-08 08:46:06 -0600145 # Read all packages and update the index. The index must be uploaded to the
146 # binhost for Portage to use it, so include it in upload_targets.
147 uploads_dir = binhost.GetPrebuiltsRoot(chroot, sysroot, build_target)
148 index_path = binhost.UpdatePackageIndex(
149 uploads_dir, upload_uri, upload_path, sudo=True
150 )
Alex Kleina0472ed2022-11-02 12:07:04 -0600151 upload_targets = binhost.GetPrebuiltsFiles(
152 uploads_dir, package_index_paths=package_index_paths, sudo=True
153 )
Alex Klein1699fab2022-09-08 08:46:06 -0600154 assert index_path.startswith(
155 uploads_dir
156 ), "expected index_path to start with uploads_dir"
157 upload_targets.append(index_path[len(uploads_dir) :])
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600158
Alex Klein1699fab2022-09-08 08:46:06 -0600159 output_proto.uploads_dir = uploads_dir
160 for upload_target in upload_targets:
161 output_proto.upload_targets.add().path = upload_target.strip("/")
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600162
Alex Klein076841b2019-08-29 15:19:39 -0600163
Alex Klein1699fab2022-09-08 08:46:06 -0600164def _PrepareDevInstallBinhostUploadsResponse(
165 _input_proto, output_proto, _config
166):
167 """Add fake binhost files to a successful response."""
168 output_proto.upload_targets.add().path = "app-arch/zip-3.0-r3.tbz2"
169 output_proto.upload_targets.add().path = "virtual/python-enum34-1.tbz2"
170 output_proto.upload_targets.add().path = "Packages"
Michael Mortensen42251f92019-11-14 11:01:43 -0700171
172
173@faux.success(_PrepareDevInstallBinhostUploadsResponse)
174@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600175@validate.require("uri", "sysroot.path")
176@validate.exists("uploads_dir")
Kevin Shelton703b6882022-01-24 16:31:31 -0800177def PrepareDevInstallBinhostUploads(
178 input_proto: binhost_pb2.PrepareDevInstallBinhostUploadsRequest,
179 output_proto: binhost_pb2.PrepareDevInstallBinhostUploadsResponse,
Alex Klein1699fab2022-09-08 08:46:06 -0600180 config: "api_config.ApiConfig",
181):
182 """Return a list of files to upload to the binhost"
Michael Mortensenfc823882019-08-27 14:38:07 -0600183
Alex Klein1699fab2022-09-08 08:46:06 -0600184 The files will also be copied to the uploads_dir.
185 See BinhostService documentation in api/proto/binhost.proto.
Michael Mortensenfc823882019-08-27 14:38:07 -0600186
Alex Klein1699fab2022-09-08 08:46:06 -0600187 Args:
Alex Klein611dddd2022-10-11 17:02:01 -0600188 input_proto: The input proto.
189 output_proto: The output proto.
190 config: The API call config.
Alex Klein1699fab2022-09-08 08:46:06 -0600191 """
192 sysroot_path = input_proto.sysroot.path
Michael Mortensenfc823882019-08-27 14:38:07 -0600193
Alex Klein1699fab2022-09-08 08:46:06 -0600194 chroot = controller_util.ParseChroot(input_proto.chroot)
195 sysroot = sysroot_lib.Sysroot(sysroot_path)
Michael Mortensenfc823882019-08-27 14:38:07 -0600196
Alex Klein1699fab2022-09-08 08:46:06 -0600197 uri = input_proto.uri
198 # For now, we enforce that all input URIs are Google Storage buckets.
199 if not gs.PathIsGs(uri):
200 raise ValueError("Upload URI %s must be Google Storage." % uri)
Michael Mortensenfc823882019-08-27 14:38:07 -0600201
Alex Klein1699fab2022-09-08 08:46:06 -0600202 if config.validate_only:
203 return controller.RETURN_CODE_VALID_INPUT
Michael Mortensenfc823882019-08-27 14:38:07 -0600204
Alex Klein1699fab2022-09-08 08:46:06 -0600205 parsed_uri = urllib.parse.urlparse(uri)
206 upload_uri = gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip("/")
207 upload_path = parsed_uri.path.lstrip("/")
Michael Mortensenfc823882019-08-27 14:38:07 -0600208
Alex Klein1699fab2022-09-08 08:46:06 -0600209 # Calculate the filename for the to-be-created Packages file, which will
210 # contain only devinstall packages.
211 devinstall_package_index_path = os.path.join(
212 input_proto.uploads_dir, "Packages"
213 )
214 upload_targets_list = binhost.ReadDevInstallFilesToCreatePackageIndex(
215 chroot, sysroot, devinstall_package_index_path, upload_uri, upload_path
216 )
Michael Mortensenfc823882019-08-27 14:38:07 -0600217
Alex Klein1699fab2022-09-08 08:46:06 -0600218 package_dir = chroot.full_path(sysroot.path, "packages")
219 for upload_target in upload_targets_list:
220 # Copy each package to target/category/package
221 upload_target = upload_target.strip("/")
222 category = upload_target.split(os.sep)[0]
223 target_dir = os.path.join(input_proto.uploads_dir, category)
224 if not os.path.exists(target_dir):
225 os.makedirs(target_dir)
226 full_src_pkg_path = os.path.join(package_dir, upload_target)
227 full_target_src_path = os.path.join(
228 input_proto.uploads_dir, upload_target
229 )
230 shutil.copyfile(full_src_pkg_path, full_target_src_path)
231 output_proto.upload_targets.add().path = upload_target
232 output_proto.upload_targets.add().path = "Packages"
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600233
Alex Klein076841b2019-08-29 15:19:39 -0600234
Cindy Lind4c122a2023-04-13 19:09:31 +0000235def _PrepareChromeBinhostUploadsResponse(_input_proto, output_proto, _config):
236 """Add fake binhost files to a successful response."""
237 output_proto.upload_targets.add().path = (
238 "chromeos-base/chromeos-chrome-100-r1.tbz2"
239 )
240 output_proto.upload_targets.add().path = (
241 "chromeos-base/chrome-icu-100-r1.tbz2"
242 )
243 output_proto.upload_targets.add().path = (
244 "chromeos-base/chromeos-lacros-100-r1.tbz2"
245 )
246 output_proto.upload_targets.add().path = "Packages"
247
248
249@faux.success(_PrepareChromeBinhostUploadsResponse)
250@faux.empty_error
251@validate.require("uploads_dir", "uri", "sysroot.path")
252@validate.validation_complete
253def PrepareChromeBinhostUploads(
254 input_proto: binhost_pb2.PrepareChromeBinhostUploadsRequest,
255 output_proto: binhost_pb2.PrepareChromeBinhostUploadsResponse,
256 config: "api_config.ApiConfig",
257):
258 """Return a list of Chrome files to upload to the binhost.
259
260 The files will also be copied to the uploads_dir.
261 See BinhostService documentation in api/proto/binhost.proto.
262
263 Args:
264 input_proto: The input proto.
265 output_proto: The output proto.
266 config: The API call config.
267 """
268 if config.validate_only:
269 return controller.RETURN_CODE_VALID_INPUT
270
271 chroot = controller_util.ParseChroot(input_proto.chroot)
272 sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path)
273
274 uri = input_proto.uri
275 # For now, we enforce that all input URIs are Google Storage buckets.
276 if not gs.PathIsGs(uri):
277 raise ValueError("Upload URI %s must be Google Storage." % uri)
278 parsed_uri = urllib.parse.urlparse(uri)
279 gs_bucket = gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip("/")
280 upload_path = parsed_uri.path.lstrip("/")
281
282 # Determine the filename for the to-be-created Packages file, which will
283 # contain only Chrome packages.
284 chrome_package_index_path = os.path.join(
285 input_proto.uploads_dir, "Packages"
286 )
287 upload_targets_list = binhost.CreateChromePackageIndex(
288 chroot, sysroot, chrome_package_index_path, gs_bucket, upload_path
289 )
290
291 package_dir = chroot.full_path(sysroot.path, "packages")
292 for upload_target in upload_targets_list:
293 # Copy each package to uploads_dir/category/package
294 upload_target = upload_target.strip("/")
295 category = upload_target.split("/")[0]
296 target_dir = os.path.join(input_proto.uploads_dir, category)
297 if not os.path.exists(target_dir):
298 osutils.SafeMakedirs(target_dir)
299 full_src_pkg_path = os.path.join(package_dir, upload_target)
300 full_target_src_path = os.path.join(
301 input_proto.uploads_dir, upload_target
302 )
303 shutil.copyfile(full_src_pkg_path, full_target_src_path)
304 output_proto.upload_targets.add().path = upload_target
305 output_proto.upload_targets.add().path = "Packages"
306
307
Greg Edelston724c13d2023-04-07 16:19:24 -0600308def _UpdatePackageIndexResponse(_input_proto, _output_proto, _config):
309 """Set up a fake successful response."""
310
311
312@faux.success(_UpdatePackageIndexResponse)
313@faux.empty_error
314@validate.require("package_index_file")
315@validate.require_any("set_upload_location")
316@validate.validation_complete
317def UpdatePackageIndex(
318 input_proto: binhost_pb2.UpdatePackageIndexRequest,
319 _output_proto: binhost_pb2.UpdatePackageIndexResponse,
320 _config: "api_config.ApiConfig",
321):
322 """Implementation for the BinhostService/UpdatePackageIndex endpoint."""
323 # Load the index file.
324 index_path = controller_util.pb2_path_to_pathlib_path(
325 input_proto.package_index_file,
326 chroot=input_proto.chroot,
327 )
328 pkgindex = binpkg.PackageIndex()
329 pkgindex.ReadFilePath(index_path)
330
331 # Set the upload location for all packages.
332 if input_proto.set_upload_location:
333 if not input_proto.uri:
334 raise ValueError("set_upload_location is True, but no uri provided")
335 parsed_uri = urllib.parse.urlparse(input_proto.uri)
336 pkgindex.SetUploadLocation(
337 gs.GetGsURL(parsed_uri.netloc, for_gsutil=True).rstrip("/"),
338 parsed_uri.path.lstrip("/"),
339 )
340
341 # Write the updated index file back to its original location.
342 pkgindex.WriteFile(index_path)
343
344
Michael Mortensen42251f92019-11-14 11:01:43 -0700345def _SetBinhostResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600346 """Add fake binhost file to a successful response."""
347 output_proto.output_file = "/path/to/BINHOST.conf"
Michael Mortensen42251f92019-11-14 11:01:43 -0700348
349
350@faux.success(_SetBinhostResponse)
351@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600352@validate.require("build_target.name", "key", "uri")
Alex Klein231d2da2019-07-22 16:44:45 -0600353@validate.validation_complete
Alex Klein1699fab2022-09-08 08:46:06 -0600354def SetBinhost(
355 input_proto: binhost_pb2.SetBinhostRequest,
356 output_proto: binhost_pb2.SetBinhostResponse,
357 _config: "api_config.ApiConfig",
358):
359 """Set the URI for a given binhost key and build target.
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600360
Alex Klein1699fab2022-09-08 08:46:06 -0600361 See BinhostService documentation in api/proto/binhost.proto.
Evan Hernandezd437b4e2019-03-25 13:48:30 -0600362
Alex Klein1699fab2022-09-08 08:46:06 -0600363 Args:
Alex Klein611dddd2022-10-11 17:02:01 -0600364 input_proto: The input proto.
365 output_proto: The output proto.
366 _config: The API call config.
Alex Klein1699fab2022-09-08 08:46:06 -0600367 """
368 target = input_proto.build_target.name
369 key = binhost_pb2.BinhostKey.Name(input_proto.key)
370 uri = input_proto.uri
371 private = input_proto.private
Arif Kasim6242cdd2022-10-19 17:51:00 +0000372 max_uris = input_proto.max_uris or _DEFAULT_BINHOST_MAX_URIS
Alex Klein6fb0eb82019-05-20 16:16:14 -0600373
Alex Klein1699fab2022-09-08 08:46:06 -0600374 output_proto.output_file = binhost.SetBinhost(
Arif Kasim6242cdd2022-10-19 17:51:00 +0000375 target, key, uri, private=private, max_uris=max_uris
Alex Klein1699fab2022-09-08 08:46:06 -0600376 )
LaMont Jonesc64ae212019-04-15 15:41:28 -0600377
LaMont Jonesc64ae212019-04-15 15:41:28 -0600378
Arif Kasima0467262022-11-11 17:08:14 +0000379def _GetBinhostConfPathResponse(_input_proto, output_proto, _config):
380 """Add fake binhost file to a successful response."""
381 output_proto.conf_path = "/path/to/BINHOST.conf"
382
383
384@faux.success(_GetBinhostConfPathResponse)
385@faux.empty_error
386@validate.require("build_target.name", "key")
387@validate.validation_complete
388def GetBinhostConfPath(
389 input_proto: binhost_pb2.GetBinhostConfPathRequest,
390 output_proto: binhost_pb2.GetBinhostConfPathResponse,
391 _config: "api_config.ApiConfig",
392):
393 target = input_proto.build_target.name
394 key = binhost_pb2.BinhostKey.Name(input_proto.key)
395 private = input_proto.private
396 output_proto.conf_path = str(
397 binhost.GetBinhostConfPath(target, key, private)
398 )
399
400
Michael Mortensen42251f92019-11-14 11:01:43 -0700401def _RegenBuildCacheResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600402 """Add fake binhosts cache path to a successful response."""
403 output_proto.modified_overlays.add().path = "/path/to/BuildCache"
Michael Mortensen42251f92019-11-14 11:01:43 -0700404
405
406@faux.success(_RegenBuildCacheResponse)
407@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600408@validate.require("overlay_type")
409@validate.is_in("overlay_type", _OVERLAY_TYPE_TO_NAME)
Alex Klein231d2da2019-07-22 16:44:45 -0600410@validate.validation_complete
Alex Klein1699fab2022-09-08 08:46:06 -0600411def RegenBuildCache(
412 input_proto: binhost_pb2.RegenBuildCacheRequest,
413 output_proto: binhost_pb2.RegenBuildCacheResponse,
414 _config: "api_config.ApiConfig",
415):
416 """Regenerate the Build Cache for a build target.
LaMont Jonesc64ae212019-04-15 15:41:28 -0600417
Alex Klein1699fab2022-09-08 08:46:06 -0600418 See BinhostService documentation in api/proto/binhost.proto.
LaMont Jonesc64ae212019-04-15 15:41:28 -0600419
Alex Klein1699fab2022-09-08 08:46:06 -0600420 Args:
Alex Klein611dddd2022-10-11 17:02:01 -0600421 input_proto: The input proto.
422 output_proto: The output proto.
423 _config: The API call config.
Alex Klein1699fab2022-09-08 08:46:06 -0600424 """
425 chroot = controller_util.ParseChroot(input_proto.chroot)
426 overlay_type = input_proto.overlay_type
427 overlays = binhost.RegenBuildCache(
428 chroot, _OVERLAY_TYPE_TO_NAME[overlay_type]
429 )
Alex Klein82c85d42019-08-14 15:47:51 -0600430
Alex Klein1699fab2022-09-08 08:46:06 -0600431 for overlay in overlays:
432 output_proto.modified_overlays.add().path = overlay