LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [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 | """Android operations.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 12 | from chromite.api import validate |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 13 | from chromite.api.gen.chromite.api import android_pb2 |
Alex Klein | 35815c5 | 2019-08-20 18:14:08 +0000 | [diff] [blame] | 14 | # TODO(crbug/904939): implement service/android. |
| 15 | from chromite.cbuildbot import commands |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 16 | from chromite.lib import constants |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 17 | from chromite.lib import osutils |
| 18 | from chromite.lib import portage_util |
| 19 | |
| 20 | |
| 21 | ANDROIDPIN_MASK_PATH = os.path.join(constants.SOURCE_ROOT, |
| 22 | constants.CHROMIUMOS_OVERLAY_DIR, |
| 23 | 'profiles', 'default', 'linux', |
| 24 | 'package.mask', 'androidpin') |
| 25 | |
| 26 | |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 27 | @validate.require('tracking_branch', 'package_name', 'android_build_branch') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 28 | @validate.validation_complete |
| 29 | def MarkStable(input_proto, output_proto, _config): |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 30 | """Uprev Android, if able. |
| 31 | |
| 32 | Uprev Android, verify that the newly uprevved package can be emerged, and |
| 33 | return the new package info. |
| 34 | |
| 35 | See AndroidService documentation in api/proto/android.proto. |
| 36 | |
| 37 | Args: |
| 38 | input_proto (MarkStableRequest): The input proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 39 | output_proto (MarkStableResponse): The output proto. |
| 40 | _config (api_config.ApiConfig): The call config. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 41 | """ |
| 42 | tracking_branch = input_proto.tracking_branch |
| 43 | package_name = input_proto.package_name |
| 44 | android_build_branch = input_proto.android_build_branch |
| 45 | android_version = input_proto.android_version |
| 46 | android_gts_build_branch = input_proto.android_gts_build_branch |
Alex Klein | 35815c5 | 2019-08-20 18:14:08 +0000 | [diff] [blame] | 47 | boards = input_proto.boards |
| 48 | buildroot = input_proto.buildroot |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 49 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 50 | # Assume success. |
| 51 | output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame] | 52 | # TODO(crbug/904939): This should move to service/android.py and the port |
| 53 | # should be finished. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 54 | try: |
Alex Klein | 35815c5 | 2019-08-20 18:14:08 +0000 | [diff] [blame] | 55 | android_atom_to_build = commands.MarkAndroidAsStable( |
| 56 | buildroot=buildroot, |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 57 | tracking_branch=tracking_branch, |
| 58 | android_package=package_name, |
| 59 | android_build_branch=android_build_branch, |
Alex Klein | 35815c5 | 2019-08-20 18:14:08 +0000 | [diff] [blame] | 60 | boards=boards, |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 61 | android_version=android_version, |
| 62 | android_gts_build_branch=android_gts_build_branch) |
Alex Klein | 35815c5 | 2019-08-20 18:14:08 +0000 | [diff] [blame] | 63 | except commands.AndroidIsPinnedUprevError as e: |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 64 | # If the uprev failed due to a pin, CI needs to unpin and retry. |
| 65 | android_atom_to_build = e.new_android_atom |
| 66 | output_proto.status = android_pb2.MARK_STABLE_STATUS_PINNED |
| 67 | |
| 68 | if android_atom_to_build: |
| 69 | CPV = portage_util.SplitCPV(android_atom_to_build) |
| 70 | output_proto.android_atom.category = CPV.category |
| 71 | output_proto.android_atom.package_name = CPV.package |
| 72 | output_proto.android_atom.version = CPV.version |
| 73 | else: |
| 74 | output_proto.status = android_pb2.MARK_STABLE_STATUS_EARLY_EXIT |
| 75 | |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 76 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 77 | @validate.validation_complete |
| 78 | def UnpinVersion(_input_proto, _output_proto, _config): |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 79 | """Unpin the Android version. |
| 80 | |
| 81 | See AndroidService documentation in api/proto/android.proto. |
| 82 | |
| 83 | Args: |
| 84 | _input_proto (UnpinVersionRequest): The input proto. (not used.) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 85 | _output_proto (UnpinVersionResponse): The output proto. (not used.) |
| 86 | _config (api_config.ApiConfig): The call config. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 87 | """ |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 88 | osutils.SafeUnlink(ANDROIDPIN_MASK_PATH) |