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 |
David Burger | ff1a92c | 2019-07-09 00:27:54 +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') |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 28 | def MarkStable(input_proto, output_proto): |
| 29 | """Uprev Android, if able. |
| 30 | |
| 31 | Uprev Android, verify that the newly uprevved package can be emerged, and |
| 32 | return the new package info. |
| 33 | |
| 34 | See AndroidService documentation in api/proto/android.proto. |
| 35 | |
| 36 | Args: |
| 37 | input_proto (MarkStableRequest): The input proto. |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame^] | 38 | output_proto (MarkStableReSponse): The output proto. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 39 | """ |
| 40 | tracking_branch = input_proto.tracking_branch |
| 41 | package_name = input_proto.package_name |
| 42 | android_build_branch = input_proto.android_build_branch |
| 43 | android_version = input_proto.android_version |
| 44 | android_gts_build_branch = input_proto.android_gts_build_branch |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame^] | 45 | boards = input_proto.boards |
| 46 | buildroot = input_proto.buildroot |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 47 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 48 | # Assume success. |
| 49 | output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame^] | 50 | # TODO(crbug/904939): This should move to service/android.py and the port |
| 51 | # should be finished. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 52 | try: |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame^] | 53 | android_atom_to_build = commands.MarkAndroidAsStable( |
| 54 | buildroot=buildroot, |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 55 | tracking_branch=tracking_branch, |
| 56 | android_package=package_name, |
| 57 | android_build_branch=android_build_branch, |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame^] | 58 | boards=boards, |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 59 | android_version=android_version, |
| 60 | android_gts_build_branch=android_gts_build_branch) |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame^] | 61 | except commands.AndroidIsPinnedUprevError as e: |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 62 | # If the uprev failed due to a pin, CI needs to unpin and retry. |
| 63 | android_atom_to_build = e.new_android_atom |
| 64 | output_proto.status = android_pb2.MARK_STABLE_STATUS_PINNED |
| 65 | |
| 66 | if android_atom_to_build: |
| 67 | CPV = portage_util.SplitCPV(android_atom_to_build) |
| 68 | output_proto.android_atom.category = CPV.category |
| 69 | output_proto.android_atom.package_name = CPV.package |
| 70 | output_proto.android_atom.version = CPV.version |
| 71 | else: |
| 72 | output_proto.status = android_pb2.MARK_STABLE_STATUS_EARLY_EXIT |
| 73 | |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 74 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 75 | def UnpinVersion(_input_proto, _output_proto): |
| 76 | """Unpin the Android version. |
| 77 | |
| 78 | See AndroidService documentation in api/proto/android.proto. |
| 79 | |
| 80 | Args: |
| 81 | _input_proto (UnpinVersionRequest): The input proto. (not used.) |
| 82 | _output_proto (google.protobuf.Empty): The output proto. (not used.) |
| 83 | """ |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame^] | 84 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 85 | osutils.SafeUnlink(ANDROIDPIN_MASK_PATH) |