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 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame^] | 10 | from chromite.api import faux |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 11 | from chromite.api import validate |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 12 | from chromite.api.gen.chromite.api import toolchain_pb2 |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 13 | from chromite.lib import toolchain_util |
| 14 | |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 15 | _NAMES_FOR_ARTIFACTS = { |
| 16 | toolchain_pb2.ORDERFILE: 'orderfile', |
| 17 | toolchain_pb2.KERNEL_AFDO: 'kernel_afdo', |
| 18 | toolchain_pb2.CHROME_AFDO: 'chrome_afdo' |
| 19 | } |
| 20 | |
| 21 | # Using a function instead of a dict because we need to mock these |
| 22 | # functions in unittest, and mock doesn't play well with a dict definition. |
| 23 | def _GetMethodForUpdatingArtifacts(artifact_type): |
| 24 | return { |
| 25 | toolchain_pb2.ORDERFILE: toolchain_util.OrderfileUpdateChromeEbuild, |
| 26 | toolchain_pb2.KERNEL_AFDO: toolchain_util.AFDOUpdateKernelEbuild, |
| 27 | toolchain_pb2.CHROME_AFDO: toolchain_util.AFDOUpdateChromeEbuild |
| 28 | }[artifact_type] |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 29 | |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 30 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame^] | 31 | @faux.all_empty |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 32 | @validate.require('build_target.name') |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 33 | @validate.is_in('artifact_type', _NAMES_FOR_ARTIFACTS.keys()) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 34 | @validate.validation_complete |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 35 | def UpdateEbuildWithAFDOArtifacts(input_proto, output_proto, _config): |
| 36 | """Update Chrome or kernel ebuild with most recent unvetted artifacts. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 37 | |
| 38 | Args: |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 39 | input_proto (VerifyAFDOArtifactsRequest): The input proto |
| 40 | output_proto (VerifyAFDOArtifactsResponse): The output proto |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 41 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 42 | """ |
| 43 | |
| 44 | board = input_proto.build_target.name |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 45 | update_method = _GetMethodForUpdatingArtifacts(input_proto.artifact_type) |
| 46 | output_proto.status = update_method(board) |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 47 | |
| 48 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame^] | 49 | @faux.all_empty |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 50 | @validate.require('build_target.name') |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 51 | @validate.is_in('artifact_type', _NAMES_FOR_ARTIFACTS.keys()) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 52 | @validate.validation_complete |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 53 | def UploadVettedAFDOArtifacts(input_proto, output_proto, _config): |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 54 | """Upload a vetted orderfile to GS bucket. |
| 55 | |
| 56 | Args: |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 57 | input_proto (VerifyAFDOArtifactsRequest): The input proto |
| 58 | output_proto (VerifyAFDOArtifactsResponse): The output proto |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 59 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 60 | """ |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 61 | board = input_proto.build_target.name |
Tiancong Wang | f9c736c | 2019-08-26 13:54:38 -0700 | [diff] [blame] | 62 | artifact_type = _NAMES_FOR_ARTIFACTS[input_proto.artifact_type] |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 63 | output_proto.status = toolchain_util.UploadAndPublishVettedAFDOArtifacts( |
| 64 | artifact_type, board) |