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 | |
| 12 | from chromite.lib import cros_logging as logging |
| 13 | from chromite.lib import gs |
| 14 | from chromite.lib import toolchain_util |
| 15 | |
| 16 | |
| 17 | def UpdateChromeEbuildWithOrderfile(input_proto, _output_proto): |
| 18 | """Update Chrome ebuild with most recent unvetted orderfile. |
| 19 | |
| 20 | Args: |
| 21 | input_proto (UpdateChromeEbuildRequest): The input proto |
| 22 | output_proto (UpdateChromeEbuildResponse): Empty output proto |
| 23 | """ |
| 24 | |
| 25 | board = input_proto.build_target.name |
| 26 | toolchain_util.OrderfileUpdateChromeEbuild(board) |
| 27 | |
| 28 | |
| 29 | def UploadVettedOrderfile(_input_proto, output_proto): |
| 30 | """Upload a vetted orderfile to GS bucket. |
| 31 | |
| 32 | Args: |
| 33 | input_proto (UploadVettedOrderfileRequest): Empty input proto |
| 34 | output_proto (UploadVettedOrderfileResponse): The output proto |
| 35 | """ |
| 36 | |
| 37 | gs_context = gs.GSContext() |
| 38 | orderfile = toolchain_util.FindLatestChromeOrderfile( |
| 39 | toolchain_util.ORDERFILE_GS_URL_UNVETTED) |
| 40 | |
| 41 | if gs_context.Exists( |
| 42 | os.path.join(toolchain_util.ORDERFILE_GS_URL_VETTED, orderfile)): |
| 43 | output_proto.status = False |
| 44 | return |
| 45 | |
| 46 | source_url = os.path.join(toolchain_util.ORDERFILE_GS_URL_UNVETTED, orderfile) |
| 47 | dest_url = os.path.join(toolchain_util.ORDERFILE_GS_URL_VETTED, orderfile) |
| 48 | |
| 49 | logging.info('Copying tarball from %s to %s', source_url, dest_url) |
| 50 | gs_context.Copy(source_url, dest_url, acl='public-read') |
| 51 | output_proto.status = True |