Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [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 | """Toolchain-related operations.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 10 | import collections |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame] | 11 | import sys |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 12 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 13 | from chromite.api import controller |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 14 | from chromite.api import faux |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 15 | from chromite.api import validate |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 16 | from chromite.api.controller import controller_util |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 17 | from chromite.api.gen.chromite.api import toolchain_pb2 |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 18 | from chromite.api.gen.chromiumos.builder_config_pb2 import BuilderConfig |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 19 | from chromite.lib import cros_logging as logging |
| 20 | from chromite.lib import toolchain_util |
LaMont Jones | fd68cb1 | 2020-04-29 16:43:06 -0600 | [diff] [blame] | 21 | from chromite.api.gen.chromite.api.artifacts_pb2 import PrepareForBuildResponse |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 22 | |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame] | 23 | |
| 24 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 25 | |
| 26 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 27 | _Handlers = collections.namedtuple('_Handlers', ['name', 'prepare', 'bundle']) |
| 28 | _TOOLCHAIN_ARTIFACT_HANDLERS = { |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 29 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE: |
LaMont Jones | d394458 | 2020-03-04 10:37:05 -0700 | [diff] [blame] | 30 | _Handlers('UnverifiedChromeLlvmOrderfile', |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 31 | toolchain_util.PrepareForBuild, |
| 32 | toolchain_util.BundleArtifacts), |
LaMont Jones | cd1503d | 2020-03-04 09:09:59 -0700 | [diff] [blame] | 33 | BuilderConfig.Artifacts.VERIFIED_CHROME_LLVM_ORDERFILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 34 | _Handlers('VerifiedChromeLlvmOrderfile', toolchain_util.PrepareForBuild, |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 35 | toolchain_util.BundleArtifacts), |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 36 | BuilderConfig.Artifacts.CHROME_CLANG_WARNINGS_FILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 37 | _Handlers('ChromeClangWarningsFile', toolchain_util.PrepareForBuild, |
LaMont Jones | 90bab63 | 2020-01-27 15:58:26 -0700 | [diff] [blame] | 38 | toolchain_util.BundleArtifacts), |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 39 | BuilderConfig.Artifacts.UNVERIFIED_LLVM_PGO_FILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 40 | _Handlers('UnverifiedLlvmPgoFile', toolchain_util.PrepareForBuild, |
LaMont Jones | 90bab63 | 2020-01-27 15:58:26 -0700 | [diff] [blame] | 41 | toolchain_util.BundleArtifacts), |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 42 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_AFDO_FILE: |
| 43 | _Handlers('UnverifiedChromeBenchmarkAfdoFile', |
LaMont Jones | 90bab63 | 2020-01-27 15:58:26 -0700 | [diff] [blame] | 44 | toolchain_util.PrepareForBuild, |
| 45 | toolchain_util.BundleArtifacts), |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 46 | BuilderConfig.Artifacts.CHROME_DEBUG_BINARY: |
| 47 | _Handlers('ChromeDebugBinary', |
| 48 | toolchain_util.PrepareForBuild, |
| 49 | toolchain_util.BundleArtifacts), |
LaMont Jones | 53bddd0 | 2020-03-12 15:02:54 -0600 | [diff] [blame] | 50 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_PERF_FILE: |
| 51 | _Handlers('UnverifiedChromeBenchmarkPerfFile', |
| 52 | toolchain_util.PrepareForBuild, |
| 53 | toolchain_util.BundleArtifacts), |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 54 | BuilderConfig.Artifacts.VERIFIED_CHROME_BENCHMARK_AFDO_FILE: |
| 55 | _Handlers('VerifiedChromeBenchmarkAfdoFile', |
LaMont Jones | 90bab63 | 2020-01-27 15:58:26 -0700 | [diff] [blame] | 56 | toolchain_util.PrepareForBuild, |
| 57 | toolchain_util.BundleArtifacts), |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 58 | BuilderConfig.Artifacts.UNVERIFIED_KERNEL_CWP_AFDO_FILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 59 | _Handlers('UnverifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 60 | toolchain_util.BundleArtifacts), |
| 61 | BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 62 | _Handlers('VerifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 63 | toolchain_util.BundleArtifacts), |
| 64 | BuilderConfig.Artifacts.UNVERIFIED_CHROME_CWP_AFDO_FILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 65 | _Handlers('UnverifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 66 | toolchain_util.BundleArtifacts), |
| 67 | BuilderConfig.Artifacts.VERIFIED_CHROME_CWP_AFDO_FILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 68 | _Handlers('VerifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 69 | toolchain_util.BundleArtifacts), |
| 70 | BuilderConfig.Artifacts.VERIFIED_RELEASE_AFDO_FILE: |
LaMont Jones | 3fed7f2 | 2020-03-04 10:15:11 -0700 | [diff] [blame] | 71 | _Handlers('VerifiedReleaseAfdoFile', toolchain_util.PrepareForBuild, |
LaMont Jones | 90bab63 | 2020-01-27 15:58:26 -0700 | [diff] [blame] | 72 | toolchain_util.BundleArtifacts), |
Tiancong Wang | 91cf1dd | 2020-05-05 10:30:22 -0700 | [diff] [blame] | 73 | BuilderConfig.Artifacts.TOOLCHAIN_WARNING_LOGS: |
| 74 | _Handlers('ToolchainWarningLogs', toolchain_util.PrepareForBuild, |
| 75 | toolchain_util.BundleArtifacts), |
Tiancong Wang | fe3dbd2 | 2020-06-12 15:45:55 -0700 | [diff] [blame] | 76 | BuilderConfig.Artifacts.CHROME_AFDO_PROFILE_FOR_ANDROID_LINUX: |
| 77 | _Handlers('ChromeAFDOProfileForAndroidLinux', |
| 78 | toolchain_util.PrepareForBuild, |
| 79 | toolchain_util.BundleArtifacts), |
Jian Cai | 6190cc8 | 2020-06-12 16:24:32 -0700 | [diff] [blame^] | 80 | BuilderConfig.Artifacts.CLANG_CRASH_DIAGNOSES: |
| 81 | _Handlers('ClangCrashDiagnoses', toolchain_util.PrepareForBuild, |
| 82 | toolchain_util.BundleArtifacts), |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 86 | def _GetProfileInfoDict(profile_info): |
| 87 | """Convert profile_info to a dict. |
| 88 | |
| 89 | Args: |
| 90 | profile_info (ArtifactProfileInfo): The artifact profile_info. |
| 91 | |
| 92 | Returns: |
| 93 | A dictionary containing profile info. |
| 94 | """ |
| 95 | ret = {} |
| 96 | which = profile_info.WhichOneof('artifact_profile_info') |
| 97 | if which: |
| 98 | value = getattr(profile_info, which) |
| 99 | # If it is a message, then use the contents of the message. This works as |
| 100 | # long as simple types do not have a 'DESCRIPTOR' attribute. (And protobuf |
| 101 | # messages do.) |
| 102 | if getattr(value, 'DESCRIPTOR', None): |
| 103 | ret.update({k.name: v for k, v in value.ListFields()}) |
| 104 | else: |
| 105 | ret[which] = value |
| 106 | return ret |
| 107 | |
| 108 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 109 | # TODO(crbug/1031213): When @faux is expanded to have more than success/failure, |
| 110 | # this should be changed. |
| 111 | @faux.all_empty |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 112 | @validate.require('artifact_types') |
| 113 | # Note: chroot and sysroot are unspecified the first time that the build_target |
| 114 | # recipe calls PrepareForBuild. The second time, they are specified. No |
| 115 | # validation check because "all" values are valid. |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 116 | @validate.validation_complete |
| 117 | def PrepareForBuild(input_proto, output_proto, _config): |
| 118 | """Prepare to build toolchain artifacts. |
| 119 | |
| 120 | The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with: |
| 121 | artifact_name (str): name of the artifact type. |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 122 | chroot (chroot_lib.Chroot): chroot. Will be None if the chroot has not |
| 123 | yet been created. |
| 124 | sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas). |
| 125 | Will be an empty string if the sysroot has not yet been created. |
| 126 | build_target_name (str): name of the build target (e.g., atlas). Will be |
| 127 | an empty string if the sysroot has not yet been created. |
| 128 | input_artifacts ({(str) name:[str gs_locations]}): locations for possible |
| 129 | input artifacts. The handler is expected to know which keys it should |
| 130 | be using, and ignore any keys that it does not understand. |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 131 | profile_info ({(str) name: (str) value}) Dictionary containing profile |
| 132 | information. |
LaMont Jones | a215f1e | 2019-12-06 10:18:58 -0700 | [diff] [blame] | 133 | |
| 134 | They locate and modify any ebuilds and/or source required for the artifact |
| 135 | being created, then return a value from toolchain_util.PrepareForBuildReturn. |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 136 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 137 | This function sets output_proto.build_relevance to the result. |
| 138 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 139 | Args: |
| 140 | input_proto (PrepareForToolchainBuildRequest): The input proto |
| 141 | output_proto (PrepareForToolchainBuildResponse): The output proto |
| 142 | _config (api_config.ApiConfig): The API call config. |
| 143 | """ |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 144 | if input_proto.chroot.path: |
| 145 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 146 | else: |
| 147 | chroot = None |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 148 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 149 | input_artifacts = collections.defaultdict(list) |
| 150 | for art in input_proto.input_artifacts: |
| 151 | item = _TOOLCHAIN_ARTIFACT_HANDLERS.get(art.input_artifact_type) |
| 152 | if item: |
| 153 | input_artifacts[item.name].extend( |
| 154 | ['gs://%s' % str(x) for x in art.input_artifact_gs_locations]) |
| 155 | |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 156 | profile_info = _GetProfileInfoDict(input_proto.profile_info) |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 157 | |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 158 | results = set() |
| 159 | sysroot_path = input_proto.sysroot.path |
| 160 | build_target = input_proto.sysroot.build_target.name |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 161 | for artifact_type in input_proto.artifact_types: |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 162 | # Unknown artifact_types are an error. |
| 163 | handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type] |
| 164 | if handler.prepare: |
LaMont Jones | a215f1e | 2019-12-06 10:18:58 -0700 | [diff] [blame] | 165 | results.add(handler.prepare( |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 166 | handler.name, chroot, sysroot_path, build_target, input_artifacts, |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 167 | profile_info)) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 168 | |
| 169 | # Translate the returns from the handlers we called. |
| 170 | # If any NEEDED => NEEDED |
| 171 | # elif any UNKNOWN => UNKNOWN |
| 172 | # elif any POINTLESS => POINTLESS |
| 173 | # else UNKNOWN. |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 174 | if toolchain_util.PrepareForBuildReturn.NEEDED in results: |
LaMont Jones | fd68cb1 | 2020-04-29 16:43:06 -0600 | [diff] [blame] | 175 | output_proto.build_relevance = PrepareForBuildResponse.NEEDED |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 176 | elif toolchain_util.PrepareForBuildReturn.UNKNOWN in results: |
LaMont Jones | fd68cb1 | 2020-04-29 16:43:06 -0600 | [diff] [blame] | 177 | output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 178 | elif toolchain_util.PrepareForBuildReturn.POINTLESS in results: |
LaMont Jones | fd68cb1 | 2020-04-29 16:43:06 -0600 | [diff] [blame] | 179 | output_proto.build_relevance = PrepareForBuildResponse.POINTLESS |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 180 | else: |
LaMont Jones | fd68cb1 | 2020-04-29 16:43:06 -0600 | [diff] [blame] | 181 | output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 182 | return controller.RETURN_CODE_SUCCESS |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 183 | |
| 184 | |
| 185 | # TODO(crbug/1031213): When @faux is expanded to have more than success/failure, |
| 186 | # this should be changed. |
| 187 | @faux.all_empty |
LaMont Jones | e911df0 | 2020-04-16 12:40:17 -0600 | [diff] [blame] | 188 | @validate.require('chroot.path', 'output_dir', 'artifact_types') |
LaMont Jones | 4579e8c | 2019-12-06 14:20:37 -0700 | [diff] [blame] | 189 | @validate.exists('output_dir') |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 190 | @validate.validation_complete |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 191 | def BundleArtifacts(input_proto, output_proto, _config): |
| 192 | """Bundle toolchain artifacts. |
| 193 | |
| 194 | The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with: |
LaMont Jones | a215f1e | 2019-12-06 10:18:58 -0700 | [diff] [blame] | 195 | artifact_name (str): name of the artifact type |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 196 | chroot (chroot_lib.Chroot): chroot |
LaMont Jones | e911df0 | 2020-04-16 12:40:17 -0600 | [diff] [blame] | 197 | sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas), |
| 198 | or None. |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 199 | chrome_root (str): path to chrome root. (e.g., /b/s/w/ir/k/chrome) |
LaMont Jones | e911df0 | 2020-04-16 12:40:17 -0600 | [diff] [blame] | 200 | build_target_name (str): name of the build target (e.g., atlas), or None. |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 201 | output_dir (str): absolute path where artifacts are being bundled. |
| 202 | (e.g., /b/s/w/ir/k/recipe_cleanup/artifactssptfMU) |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 203 | profile_info ({(str) name: (str) value}) Dictionary containing profile |
| 204 | information. |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 205 | |
| 206 | Note: the actual upload to GS is done by CI, not here. |
| 207 | |
| 208 | Args: |
| 209 | input_proto (BundleToolchainRequest): The input proto |
| 210 | output_proto (BundleToolchainResponse): The output proto |
| 211 | _config (api_config.ApiConfig): The API call config. |
| 212 | """ |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 213 | chroot = controller_util.ParseChroot(input_proto.chroot) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 214 | |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 215 | profile_info = _GetProfileInfoDict(input_proto.profile_info) |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 216 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 217 | for artifact_type in input_proto.artifact_types: |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 218 | if artifact_type not in _TOOLCHAIN_ARTIFACT_HANDLERS: |
| 219 | logging.error('%s not understood', artifact_type) |
| 220 | return controller.RETURN_CODE_UNRECOVERABLE |
| 221 | handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type] |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 222 | if handler and handler.bundle: |
| 223 | artifacts = handler.bundle( |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 224 | handler.name, chroot, input_proto.sysroot.path, |
LaMont Jones | 45ca6c4 | 2020-02-05 09:39:09 -0700 | [diff] [blame] | 225 | input_proto.sysroot.build_target.name, input_proto.output_dir, |
LaMont Jones | e782167 | 2020-04-09 08:56:26 -0600 | [diff] [blame] | 226 | profile_info) |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 227 | if artifacts: |
LaMont Jones | 5d2edcb | 2019-12-23 11:32:03 -0700 | [diff] [blame] | 228 | art_info = output_proto.artifacts_info.add() |
| 229 | art_info.artifact_type = artifact_type |
| 230 | for artifact in artifacts: |
| 231 | art_info.artifacts.add().path = artifact |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 232 | |
| 233 | |
| 234 | # TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone. |
| 235 | _NAMES_FOR_AFDO_ARTIFACTS = { |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 236 | toolchain_pb2.ORDERFILE: 'orderfile', |
| 237 | toolchain_pb2.KERNEL_AFDO: 'kernel_afdo', |
| 238 | toolchain_pb2.CHROME_AFDO: 'chrome_afdo' |
| 239 | } |
| 240 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 241 | # TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone. |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 242 | # Using a function instead of a dict because we need to mock these |
| 243 | # functions in unittest, and mock doesn't play well with a dict definition. |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 244 | def _GetMethodForUpdatingAFDOArtifacts(artifact_type): |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 245 | return { |
| 246 | toolchain_pb2.ORDERFILE: toolchain_util.OrderfileUpdateChromeEbuild, |
| 247 | toolchain_pb2.KERNEL_AFDO: toolchain_util.AFDOUpdateKernelEbuild, |
| 248 | toolchain_pb2.CHROME_AFDO: toolchain_util.AFDOUpdateChromeEbuild |
| 249 | }[artifact_type] |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 250 | |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 251 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 252 | # TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone. |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 253 | def _UpdateEbuildWithAFDOArtifactsResponse(_input_proto, output_proto, _config): |
| 254 | """Add successful status to the faux response.""" |
| 255 | output_proto.status = True |
| 256 | |
| 257 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 258 | # TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone. |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 259 | @faux.success(_UpdateEbuildWithAFDOArtifactsResponse) |
| 260 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 261 | @validate.require('build_target.name') |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 262 | @validate.is_in('artifact_type', _NAMES_FOR_AFDO_ARTIFACTS) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 263 | @validate.validation_complete |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 264 | def UpdateEbuildWithAFDOArtifacts(input_proto, output_proto, _config): |
| 265 | """Update Chrome or kernel ebuild with most recent unvetted artifacts. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 266 | |
| 267 | Args: |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 268 | input_proto (VerifyAFDOArtifactsRequest): The input proto |
| 269 | output_proto (VerifyAFDOArtifactsResponse): The output proto |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 270 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 271 | """ |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 272 | board = input_proto.build_target.name |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 273 | update_method = _GetMethodForUpdatingAFDOArtifacts(input_proto.artifact_type) |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 274 | output_proto.status = update_method(board) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 275 | |
| 276 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 277 | # TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone. |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 278 | def _UploadVettedAFDOArtifactsResponse(_input_proto, output_proto, _config): |
| 279 | """Add successful status to the faux response.""" |
| 280 | output_proto.status = True |
| 281 | |
| 282 | |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 283 | # TODO(crbug/1019868): Remove legacy code when cbuildbot builders are gone. |
Michael Mortensen | 54bd70a | 2019-11-21 14:45:38 -0700 | [diff] [blame] | 284 | @faux.success(_UploadVettedAFDOArtifactsResponse) |
| 285 | @faux.empty_error |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 286 | @validate.require('build_target.name') |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 287 | @validate.is_in('artifact_type', _NAMES_FOR_AFDO_ARTIFACTS) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 288 | @validate.validation_complete |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 289 | def UploadVettedAFDOArtifacts(input_proto, output_proto, _config): |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 290 | """Upload a vetted orderfile to GS bucket. |
| 291 | |
| 292 | Args: |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 293 | input_proto (VerifyAFDOArtifactsRequest): The input proto |
| 294 | output_proto (VerifyAFDOArtifactsResponse): The output proto |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 295 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 296 | """ |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 297 | board = input_proto.build_target.name |
LaMont Jones | b20b3d9 | 2019-11-23 11:47:48 -0700 | [diff] [blame] | 298 | artifact_type = _NAMES_FOR_AFDO_ARTIFACTS[input_proto.artifact_type] |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 299 | output_proto.status = toolchain_util.UploadAndPublishVettedAFDOArtifacts( |
| 300 | artifact_type, board) |