blob: 5c69958cdc8ad9ed230025fdf2bde69712b8d431 [file] [log] [blame]
Tiancong Wangaf050172019-07-10 11:52:03 -07001# -*- 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
8from __future__ import print_function
9
Alex Klein231d2da2019-07-22 16:44:45 -060010from chromite.api import validate
Tiancong Wang24a3df72019-08-20 15:48:51 -070011from chromite.api.gen.chromite.api import toolchain_pb2
Tiancong Wangaf050172019-07-10 11:52:03 -070012from chromite.lib import toolchain_util
13
Tiancong Wangf9c736c2019-08-26 13:54:38 -070014_NAMES_FOR_ARTIFACTS = {
15 toolchain_pb2.ORDERFILE: 'orderfile',
16 toolchain_pb2.KERNEL_AFDO: 'kernel_afdo',
17 toolchain_pb2.CHROME_AFDO: 'chrome_afdo'
18}
19
20# Using a function instead of a dict because we need to mock these
21# functions in unittest, and mock doesn't play well with a dict definition.
22def _GetMethodForUpdatingArtifacts(artifact_type):
23 return {
24 toolchain_pb2.ORDERFILE: toolchain_util.OrderfileUpdateChromeEbuild,
25 toolchain_pb2.KERNEL_AFDO: toolchain_util.AFDOUpdateKernelEbuild,
26 toolchain_pb2.CHROME_AFDO: toolchain_util.AFDOUpdateChromeEbuild
27 }[artifact_type]
Tiancong Wang24a3df72019-08-20 15:48:51 -070028
Tiancong Wangaf050172019-07-10 11:52:03 -070029
Alex Klein231d2da2019-07-22 16:44:45 -060030@validate.require('build_target.name')
Tiancong Wangf9c736c2019-08-26 13:54:38 -070031@validate.is_in('artifact_type', _NAMES_FOR_ARTIFACTS.keys())
Alex Klein231d2da2019-07-22 16:44:45 -060032@validate.validation_complete
Tiancong Wang24a3df72019-08-20 15:48:51 -070033def UpdateEbuildWithAFDOArtifacts(input_proto, output_proto, _config):
34 """Update Chrome or kernel ebuild with most recent unvetted artifacts.
Tiancong Wangaf050172019-07-10 11:52:03 -070035
36 Args:
Tiancong Wang24a3df72019-08-20 15:48:51 -070037 input_proto (VerifyAFDOArtifactsRequest): The input proto
38 output_proto (VerifyAFDOArtifactsResponse): The output proto
Alex Klein231d2da2019-07-22 16:44:45 -060039 _config (api_config.ApiConfig): The API call config.
Tiancong Wangaf050172019-07-10 11:52:03 -070040 """
41
42 board = input_proto.build_target.name
Tiancong Wangf9c736c2019-08-26 13:54:38 -070043 update_method = _GetMethodForUpdatingArtifacts(input_proto.artifact_type)
44 output_proto.status = update_method(board)
Tiancong Wangaf050172019-07-10 11:52:03 -070045
46
Tiancong Wang24a3df72019-08-20 15:48:51 -070047@validate.require('build_target.name')
Tiancong Wangf9c736c2019-08-26 13:54:38 -070048@validate.is_in('artifact_type', _NAMES_FOR_ARTIFACTS.keys())
Alex Klein231d2da2019-07-22 16:44:45 -060049@validate.validation_complete
Tiancong Wang24a3df72019-08-20 15:48:51 -070050def UploadVettedAFDOArtifacts(input_proto, output_proto, _config):
Tiancong Wangaf050172019-07-10 11:52:03 -070051 """Upload a vetted orderfile to GS bucket.
52
53 Args:
Tiancong Wang24a3df72019-08-20 15:48:51 -070054 input_proto (VerifyAFDOArtifactsRequest): The input proto
55 output_proto (VerifyAFDOArtifactsResponse): The output proto
Alex Klein231d2da2019-07-22 16:44:45 -060056 _config (api_config.ApiConfig): The API call config.
Tiancong Wangaf050172019-07-10 11:52:03 -070057 """
Tiancong Wang24a3df72019-08-20 15:48:51 -070058 board = input_proto.build_target.name
Tiancong Wangf9c736c2019-08-26 13:54:38 -070059 artifact_type = _NAMES_FOR_ARTIFACTS[input_proto.artifact_type]
Tiancong Wang24a3df72019-08-20 15:48:51 -070060 output_proto.status = toolchain_util.UploadAndPublishVettedAFDOArtifacts(
61 artifact_type, board)