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 | |
| 10 | import os |
| 11 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame^] | 12 | from chromite.api import validate |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 13 | from chromite.lib import cros_logging as logging |
| 14 | from chromite.lib import gs |
| 15 | from chromite.lib import toolchain_util |
| 16 | |
| 17 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame^] | 18 | @validate.require('build_target.name') |
| 19 | @validate.validation_complete |
| 20 | def UpdateChromeEbuildWithOrderfile(input_proto, _output_proto, _config): |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 21 | """Update Chrome ebuild with most recent unvetted orderfile. |
| 22 | |
| 23 | Args: |
| 24 | input_proto (UpdateChromeEbuildRequest): The input proto |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame^] | 25 | _output_proto (UpdateChromeEbuildResponse): Empty output proto |
| 26 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 27 | """ |
| 28 | |
| 29 | board = input_proto.build_target.name |
| 30 | toolchain_util.OrderfileUpdateChromeEbuild(board) |
| 31 | |
| 32 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame^] | 33 | @validate.validation_complete |
| 34 | def UploadVettedOrderfile(_input_proto, output_proto, _config): |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 35 | """Upload a vetted orderfile to GS bucket. |
| 36 | |
| 37 | Args: |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame^] | 38 | _input_proto (UploadVettedOrderfileRequest): Empty input proto |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 39 | output_proto (UploadVettedOrderfileResponse): The output proto |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame^] | 40 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 41 | """ |
Tiancong Wang | af05017 | 2019-07-10 11:52:03 -0700 | [diff] [blame] | 42 | gs_context = gs.GSContext() |
| 43 | orderfile = toolchain_util.FindLatestChromeOrderfile( |
| 44 | toolchain_util.ORDERFILE_GS_URL_UNVETTED) |
| 45 | |
| 46 | if gs_context.Exists( |
| 47 | os.path.join(toolchain_util.ORDERFILE_GS_URL_VETTED, orderfile)): |
| 48 | output_proto.status = False |
| 49 | return |
| 50 | |
| 51 | source_url = os.path.join(toolchain_util.ORDERFILE_GS_URL_UNVETTED, orderfile) |
| 52 | dest_url = os.path.join(toolchain_util.ORDERFILE_GS_URL_VETTED, orderfile) |
| 53 | |
| 54 | logging.info('Copying tarball from %s to %s', source_url, dest_url) |
| 55 | gs_context.Copy(source_url, dest_url, acl='public-read') |
| 56 | output_proto.status = True |