blob: f447ebd76ec922c7402d8f2be2ad004a1eb65ebd [file] [log] [blame]
Tiancong Wangaf050172019-07-10 11:52:03 -07001# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Toolchain-related operations."""
6
LaMont Jonesb20b3d92019-11-23 11:47:48 -07007import collections
8
LaMont Jones5d2edcb2019-12-23 11:32:03 -07009from chromite.api import controller
Alex Klein076841b2019-08-29 15:19:39 -060010from chromite.api import faux
Alex Klein231d2da2019-07-22 16:44:45 -060011from chromite.api import validate
LaMont Jones5d2edcb2019-12-23 11:32:03 -070012from chromite.api.controller import controller_util
Tiancong Wang24a3df72019-08-20 15:48:51 -070013from chromite.api.gen.chromite.api import toolchain_pb2
LaMont Jonesb20b3d92019-11-23 11:47:48 -070014from chromite.api.gen.chromiumos.builder_config_pb2 import BuilderConfig
LaMont Jones5d2edcb2019-12-23 11:32:03 -070015from chromite.lib import cros_logging as logging
16from chromite.lib import toolchain_util
LaMont Jonesfd68cb12020-04-29 16:43:06 -060017from chromite.api.gen.chromite.api.artifacts_pb2 import PrepareForBuildResponse
Tiancong Wangaf050172019-07-10 11:52:03 -070018
LaMont Jonesb20b3d92019-11-23 11:47:48 -070019_Handlers = collections.namedtuple('_Handlers', ['name', 'prepare', 'bundle'])
20_TOOLCHAIN_ARTIFACT_HANDLERS = {
LaMont Jonescd1503d2020-03-04 09:09:59 -070021 BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE:
LaMont Jonesd3944582020-03-04 10:37:05 -070022 _Handlers('UnverifiedChromeLlvmOrderfile',
LaMont Jones5d2edcb2019-12-23 11:32:03 -070023 toolchain_util.PrepareForBuild,
24 toolchain_util.BundleArtifacts),
LaMont Jonescd1503d2020-03-04 09:09:59 -070025 BuilderConfig.Artifacts.VERIFIED_CHROME_LLVM_ORDERFILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070026 _Handlers('VerifiedChromeLlvmOrderfile', toolchain_util.PrepareForBuild,
LaMont Jones5d2edcb2019-12-23 11:32:03 -070027 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070028 BuilderConfig.Artifacts.CHROME_CLANG_WARNINGS_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070029 _Handlers('ChromeClangWarningsFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070030 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070031 BuilderConfig.Artifacts.UNVERIFIED_LLVM_PGO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070032 _Handlers('UnverifiedLlvmPgoFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070033 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070034 BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_AFDO_FILE:
35 _Handlers('UnverifiedChromeBenchmarkAfdoFile',
LaMont Jones90bab632020-01-27 15:58:26 -070036 toolchain_util.PrepareForBuild,
37 toolchain_util.BundleArtifacts),
LaMont Jones3fed7f22020-03-04 10:15:11 -070038 BuilderConfig.Artifacts.CHROME_DEBUG_BINARY:
Tiancong Wangba2a1c22021-01-19 10:45:06 -080039 _Handlers('ChromeDebugBinary', toolchain_util.PrepareForBuild,
LaMont Jones3fed7f22020-03-04 10:15:11 -070040 toolchain_util.BundleArtifacts),
LaMont Jones53bddd02020-03-12 15:02:54 -060041 BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_PERF_FILE:
42 _Handlers('UnverifiedChromeBenchmarkPerfFile',
43 toolchain_util.PrepareForBuild,
44 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070045 BuilderConfig.Artifacts.VERIFIED_CHROME_BENCHMARK_AFDO_FILE:
46 _Handlers('VerifiedChromeBenchmarkAfdoFile',
LaMont Jones90bab632020-01-27 15:58:26 -070047 toolchain_util.PrepareForBuild,
48 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070049 BuilderConfig.Artifacts.UNVERIFIED_KERNEL_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070050 _Handlers('UnverifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070051 toolchain_util.BundleArtifacts),
52 BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070053 _Handlers('VerifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070054 toolchain_util.BundleArtifacts),
55 BuilderConfig.Artifacts.UNVERIFIED_CHROME_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070056 _Handlers('UnverifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070057 toolchain_util.BundleArtifacts),
58 BuilderConfig.Artifacts.VERIFIED_CHROME_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070059 _Handlers('VerifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070060 toolchain_util.BundleArtifacts),
61 BuilderConfig.Artifacts.VERIFIED_RELEASE_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070062 _Handlers('VerifiedReleaseAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070063 toolchain_util.BundleArtifacts),
Tiancong Wang91cf1dd2020-05-05 10:30:22 -070064 BuilderConfig.Artifacts.TOOLCHAIN_WARNING_LOGS:
65 _Handlers('ToolchainWarningLogs', toolchain_util.PrepareForBuild,
66 toolchain_util.BundleArtifacts),
Tiancong Wangfe3dbd22020-06-12 15:45:55 -070067 BuilderConfig.Artifacts.CHROME_AFDO_PROFILE_FOR_ANDROID_LINUX:
68 _Handlers('ChromeAFDOProfileForAndroidLinux',
69 toolchain_util.PrepareForBuild,
70 toolchain_util.BundleArtifacts),
Jian Cai6190cc82020-06-12 16:24:32 -070071 BuilderConfig.Artifacts.CLANG_CRASH_DIAGNOSES:
72 _Handlers('ClangCrashDiagnoses', toolchain_util.PrepareForBuild,
73 toolchain_util.BundleArtifacts),
Ryan Beltran0be7dcf2020-12-09 18:31:53 +000074 BuilderConfig.Artifacts.COMPILER_RUSAGE_LOG:
75 _Handlers('CompilerRusageLogs', toolchain_util.PrepareForBuild,
76 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070077}
78
Tiancong Wangd5214132021-01-12 10:43:57 -080079_TOOLCHAIN_COMMIT_HANDLERS = {
80 BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE:
81 'VerifiedKernelCwpAfdoFile'
82}
83
LaMont Jonesb20b3d92019-11-23 11:47:48 -070084
LaMont Jonese7821672020-04-09 08:56:26 -060085def _GetProfileInfoDict(profile_info):
86 """Convert profile_info to a dict.
87
88 Args:
89 profile_info (ArtifactProfileInfo): The artifact profile_info.
90
91 Returns:
92 A dictionary containing profile info.
93 """
94 ret = {}
95 which = profile_info.WhichOneof('artifact_profile_info')
96 if which:
97 value = getattr(profile_info, which)
98 # If it is a message, then use the contents of the message. This works as
99 # long as simple types do not have a 'DESCRIPTOR' attribute. (And protobuf
100 # messages do.)
101 if getattr(value, 'DESCRIPTOR', None):
102 ret.update({k.name: v for k, v in value.ListFields()})
103 else:
104 ret[which] = value
105 return ret
106
107
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700108# TODO(crbug/1031213): When @faux is expanded to have more than success/failure,
109# this should be changed.
110@faux.all_empty
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700111@validate.require('artifact_types')
112# Note: chroot and sysroot are unspecified the first time that the build_target
113# recipe calls PrepareForBuild. The second time, they are specified. No
114# validation check because "all" values are valid.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700115@validate.validation_complete
116def PrepareForBuild(input_proto, output_proto, _config):
117 """Prepare to build toolchain artifacts.
118
119 The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with:
120 artifact_name (str): name of the artifact type.
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700121 chroot (chroot_lib.Chroot): chroot. Will be None if the chroot has not
122 yet been created.
123 sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas).
124 Will be an empty string if the sysroot has not yet been created.
125 build_target_name (str): name of the build target (e.g., atlas). Will be
126 an empty string if the sysroot has not yet been created.
127 input_artifacts ({(str) name:[str gs_locations]}): locations for possible
128 input artifacts. The handler is expected to know which keys it should
129 be using, and ignore any keys that it does not understand.
LaMont Jonese7821672020-04-09 08:56:26 -0600130 profile_info ({(str) name: (str) value}) Dictionary containing profile
131 information.
LaMont Jonesa215f1e2019-12-06 10:18:58 -0700132
133 They locate and modify any ebuilds and/or source required for the artifact
134 being created, then return a value from toolchain_util.PrepareForBuildReturn.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700135
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700136 This function sets output_proto.build_relevance to the result.
137
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700138 Args:
139 input_proto (PrepareForToolchainBuildRequest): The input proto
140 output_proto (PrepareForToolchainBuildResponse): The output proto
141 _config (api_config.ApiConfig): The API call config.
142 """
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700143 if input_proto.chroot.path:
144 chroot = controller_util.ParseChroot(input_proto.chroot)
145 else:
146 chroot = None
LaMont Jones4579e8c2019-12-06 14:20:37 -0700147
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700148 input_artifacts = collections.defaultdict(list)
149 for art in input_proto.input_artifacts:
150 item = _TOOLCHAIN_ARTIFACT_HANDLERS.get(art.input_artifact_type)
151 if item:
152 input_artifacts[item.name].extend(
153 ['gs://%s' % str(x) for x in art.input_artifact_gs_locations])
154
LaMont Jonese7821672020-04-09 08:56:26 -0600155 profile_info = _GetProfileInfoDict(input_proto.profile_info)
LaMont Jones45ca6c42020-02-05 09:39:09 -0700156
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700157 results = set()
158 sysroot_path = input_proto.sysroot.path
159 build_target = input_proto.sysroot.build_target.name
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700160 for artifact_type in input_proto.artifact_types:
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700161 # Unknown artifact_types are an error.
162 handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type]
163 if handler.prepare:
Tiancong Wangba2a1c22021-01-19 10:45:06 -0800164 results.add(
165 handler.prepare(handler.name, chroot, sysroot_path, build_target,
166 input_artifacts, profile_info))
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700167
168 # Translate the returns from the handlers we called.
169 # If any NEEDED => NEEDED
170 # elif any UNKNOWN => UNKNOWN
171 # elif any POINTLESS => POINTLESS
172 # else UNKNOWN.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700173 if toolchain_util.PrepareForBuildReturn.NEEDED in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600174 output_proto.build_relevance = PrepareForBuildResponse.NEEDED
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700175 elif toolchain_util.PrepareForBuildReturn.UNKNOWN in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600176 output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700177 elif toolchain_util.PrepareForBuildReturn.POINTLESS in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600178 output_proto.build_relevance = PrepareForBuildResponse.POINTLESS
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700179 else:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600180 output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700181 return controller.RETURN_CODE_SUCCESS
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700182
183
184# TODO(crbug/1031213): When @faux is expanded to have more than success/failure,
185# this should be changed.
186@faux.all_empty
LaMont Jonese911df02020-04-16 12:40:17 -0600187@validate.require('chroot.path', 'output_dir', 'artifact_types')
LaMont Jones4579e8c2019-12-06 14:20:37 -0700188@validate.exists('output_dir')
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700189@validate.validation_complete
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700190def BundleArtifacts(input_proto, output_proto, _config):
191 """Bundle toolchain artifacts.
192
193 The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with:
LaMont Jonesa215f1e2019-12-06 10:18:58 -0700194 artifact_name (str): name of the artifact type
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700195 chroot (chroot_lib.Chroot): chroot
LaMont Jonese911df02020-04-16 12:40:17 -0600196 sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas),
197 or None.
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700198 chrome_root (str): path to chrome root. (e.g., /b/s/w/ir/k/chrome)
LaMont Jonese911df02020-04-16 12:40:17 -0600199 build_target_name (str): name of the build target (e.g., atlas), or None.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700200 output_dir (str): absolute path where artifacts are being bundled.
201 (e.g., /b/s/w/ir/k/recipe_cleanup/artifactssptfMU)
LaMont Jonese7821672020-04-09 08:56:26 -0600202 profile_info ({(str) name: (str) value}) Dictionary containing profile
203 information.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700204
205 Note: the actual upload to GS is done by CI, not here.
206
207 Args:
208 input_proto (BundleToolchainRequest): The input proto
209 output_proto (BundleToolchainResponse): The output proto
210 _config (api_config.ApiConfig): The API call config.
211 """
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700212 chroot = controller_util.ParseChroot(input_proto.chroot)
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700213
LaMont Jonese7821672020-04-09 08:56:26 -0600214 profile_info = _GetProfileInfoDict(input_proto.profile_info)
LaMont Jones45ca6c42020-02-05 09:39:09 -0700215
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700216 for artifact_type in input_proto.artifact_types:
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700217 if artifact_type not in _TOOLCHAIN_ARTIFACT_HANDLERS:
218 logging.error('%s not understood', artifact_type)
219 return controller.RETURN_CODE_UNRECOVERABLE
220 handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type]
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700221 if handler and handler.bundle:
Tiancong Wangba2a1c22021-01-19 10:45:06 -0800222 artifacts = handler.bundle(handler.name, chroot, input_proto.sysroot.path,
223 input_proto.sysroot.build_target.name,
224 input_proto.output_dir, profile_info)
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700225 if artifacts:
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700226 art_info = output_proto.artifacts_info.add()
227 art_info.artifact_type = artifact_type
228 for artifact in artifacts:
229 art_info.artifacts.add().path = artifact
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700230
231
Tiancong Wangd5214132021-01-12 10:43:57 -0800232def _GetUpdatedFilesResponse(_input_proto, output_proto, _config):
233 """Add successful status to the faux response."""
234 file_info = output_proto.updated_files.add()
235 file_info.path = '/any/modified/file'
236 output_proto.commit_message = 'Commit message'
237
238
239@faux.empty_error
240@faux.success(_GetUpdatedFilesResponse)
241@validate.require('uploaded_artifacts')
242@validate.validation_complete
243def GetUpdatedFiles(input_proto, output_proto, _config):
244 """Use uploaded artifacts to update some updates in a chromeos checkout.
245
246 The function will call toolchain_util.GetUpdatedFiles using the type of
247 uploaded artifacts to make some changes in a checkout, and return the list
248 of change files together with commit message.
249 updated_artifacts: A list of UpdatedArtifacts type which contains a tuple
250 of artifact info and profile info.
251 Note: the actual creation of the commit is done by CI, not here.
252
253 Args:
254 input_proto (GetUpdatedFilesRequest): The input proto
255 output_proto (GetUpdatedFilesResponse): The output proto
256 _config (api_config.ApiConfig): The API call config.
257 """
258 commit_message = ''
259 for artifact in input_proto.uploaded_artifacts:
260 artifact_type = artifact.artifact_info.artifact_type
261 if artifact_type not in _TOOLCHAIN_COMMIT_HANDLERS:
262 logging.error('%s not understood', artifact_type)
263 return controller.RETURN_CODE_UNRECOVERABLE
264 artifact_name = _TOOLCHAIN_COMMIT_HANDLERS[artifact_type]
265 if artifact_name:
266 assert len(artifact.artifact_info.artifacts) == 1, (
267 'Only one file to update per each artifact')
268 updated_files, message = toolchain_util.GetUpdatedFiles(
269 artifact_name, artifact.artifact_info.artifacts[0].path,
270 _GetProfileInfoDict(artifact.profile_info))
271 for f in updated_files:
272 file_info = output_proto.updated_files.add()
273 file_info.path = f
274
275 commit_message += message + '\n'
276 output_proto.commit_message = commit_message
277 # No commit footer is added for now. Can add more here if needed
278
279
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700280# TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone.
281_NAMES_FOR_AFDO_ARTIFACTS = {
Tiancong Wangf9c736c2019-08-26 13:54:38 -0700282 toolchain_pb2.ORDERFILE: 'orderfile',
283 toolchain_pb2.KERNEL_AFDO: 'kernel_afdo',
284 toolchain_pb2.CHROME_AFDO: 'chrome_afdo'
285}
286
Tiancong Wangba2a1c22021-01-19 10:45:06 -0800287
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700288# TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone.
Tiancong Wangf9c736c2019-08-26 13:54:38 -0700289# Using a function instead of a dict because we need to mock these
290# functions in unittest, and mock doesn't play well with a dict definition.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700291def _GetMethodForUpdatingAFDOArtifacts(artifact_type):
Tiancong Wangf9c736c2019-08-26 13:54:38 -0700292 return {
293 toolchain_pb2.ORDERFILE: toolchain_util.OrderfileUpdateChromeEbuild,
294 toolchain_pb2.KERNEL_AFDO: toolchain_util.AFDOUpdateKernelEbuild,
295 toolchain_pb2.CHROME_AFDO: toolchain_util.AFDOUpdateChromeEbuild
296 }[artifact_type]
Tiancong Wang24a3df72019-08-20 15:48:51 -0700297
Tiancong Wangaf050172019-07-10 11:52:03 -0700298
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700299# TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone.
Michael Mortensen54bd70a2019-11-21 14:45:38 -0700300def _UpdateEbuildWithAFDOArtifactsResponse(_input_proto, output_proto, _config):
301 """Add successful status to the faux response."""
302 output_proto.status = True
303
304
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700305# TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone.
Michael Mortensen54bd70a2019-11-21 14:45:38 -0700306@faux.success(_UpdateEbuildWithAFDOArtifactsResponse)
307@faux.empty_error
Alex Klein231d2da2019-07-22 16:44:45 -0600308@validate.require('build_target.name')
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700309@validate.is_in('artifact_type', _NAMES_FOR_AFDO_ARTIFACTS)
Alex Klein231d2da2019-07-22 16:44:45 -0600310@validate.validation_complete
Tiancong Wang24a3df72019-08-20 15:48:51 -0700311def UpdateEbuildWithAFDOArtifacts(input_proto, output_proto, _config):
312 """Update Chrome or kernel ebuild with most recent unvetted artifacts.
Tiancong Wangaf050172019-07-10 11:52:03 -0700313
314 Args:
Tiancong Wang24a3df72019-08-20 15:48:51 -0700315 input_proto (VerifyAFDOArtifactsRequest): The input proto
316 output_proto (VerifyAFDOArtifactsResponse): The output proto
Alex Klein231d2da2019-07-22 16:44:45 -0600317 _config (api_config.ApiConfig): The API call config.
Tiancong Wangaf050172019-07-10 11:52:03 -0700318 """
Tiancong Wangaf050172019-07-10 11:52:03 -0700319 board = input_proto.build_target.name
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700320 update_method = _GetMethodForUpdatingAFDOArtifacts(input_proto.artifact_type)
Tiancong Wangf9c736c2019-08-26 13:54:38 -0700321 output_proto.status = update_method(board)
Tiancong Wangaf050172019-07-10 11:52:03 -0700322
323
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700324# TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone.
Michael Mortensen54bd70a2019-11-21 14:45:38 -0700325def _UploadVettedAFDOArtifactsResponse(_input_proto, output_proto, _config):
326 """Add successful status to the faux response."""
327 output_proto.status = True
328
329
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700330# TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone.
Michael Mortensen54bd70a2019-11-21 14:45:38 -0700331@faux.success(_UploadVettedAFDOArtifactsResponse)
332@faux.empty_error
Tiancong Wang24a3df72019-08-20 15:48:51 -0700333@validate.require('build_target.name')
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700334@validate.is_in('artifact_type', _NAMES_FOR_AFDO_ARTIFACTS)
Alex Klein231d2da2019-07-22 16:44:45 -0600335@validate.validation_complete
Tiancong Wang24a3df72019-08-20 15:48:51 -0700336def UploadVettedAFDOArtifacts(input_proto, output_proto, _config):
Tiancong Wangaf050172019-07-10 11:52:03 -0700337 """Upload a vetted orderfile to GS bucket.
338
339 Args:
Tiancong Wang24a3df72019-08-20 15:48:51 -0700340 input_proto (VerifyAFDOArtifactsRequest): The input proto
341 output_proto (VerifyAFDOArtifactsResponse): The output proto
Alex Klein231d2da2019-07-22 16:44:45 -0600342 _config (api_config.ApiConfig): The API call config.
Tiancong Wangaf050172019-07-10 11:52:03 -0700343 """
Tiancong Wang24a3df72019-08-20 15:48:51 -0700344 board = input_proto.build_target.name
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700345 artifact_type = _NAMES_FOR_AFDO_ARTIFACTS[input_proto.artifact_type]
Tiancong Wang24a3df72019-08-20 15:48:51 -0700346 output_proto.status = toolchain_util.UploadAndPublishVettedAFDOArtifacts(
347 artifact_type, board)