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 | |
| 12 | from chromite.api.gen.chromite.api import android_pb2 |
| 13 | # TODO(crbug/904939): implement service/android. |
| 14 | from chromite.cbuildbot import commands |
| 15 | from chromite.lib import constants |
| 16 | from chromite.lib import cros_build_lib |
| 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 | |
| 27 | def MarkStable(input_proto, output_proto): |
| 28 | """Uprev Android, if able. |
| 29 | |
| 30 | Uprev Android, verify that the newly uprevved package can be emerged, and |
| 31 | return the new package info. |
| 32 | |
| 33 | See AndroidService documentation in api/proto/android.proto. |
| 34 | |
| 35 | Args: |
| 36 | input_proto (MarkStableRequest): The input proto. |
| 37 | output_proto (MarkStableReSponse): The output proto. |
| 38 | """ |
| 39 | tracking_branch = input_proto.tracking_branch |
| 40 | package_name = input_proto.package_name |
| 41 | android_build_branch = input_proto.android_build_branch |
| 42 | android_version = input_proto.android_version |
| 43 | android_gts_build_branch = input_proto.android_gts_build_branch |
| 44 | boards = input_proto.boards |
| 45 | buildroot = input_proto.buildroot |
| 46 | |
| 47 | if not tracking_branch: |
| 48 | cros_build_lib.Die('Tracking_branch is required.') |
| 49 | |
| 50 | if not package_name: |
| 51 | cros_build_lib.Die('Package_name is required.') |
| 52 | |
| 53 | if not android_build_branch: |
| 54 | cros_build_lib.Die('Android_build_branch is required.') |
| 55 | |
| 56 | # Assume success. |
| 57 | output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS |
| 58 | # TODO(crbug/904939): This should move to service/android.py and the port |
| 59 | # should be finished. |
| 60 | try: |
| 61 | android_atom_to_build = commands.MarkAndroidAsStable( |
| 62 | buildroot=buildroot, |
| 63 | tracking_branch=tracking_branch, |
| 64 | android_package=package_name, |
| 65 | android_build_branch=android_build_branch, |
| 66 | boards=boards, |
| 67 | android_version=android_version, |
| 68 | android_gts_build_branch=android_gts_build_branch) |
| 69 | except commands.AndroidIsPinnedUprevError as e: |
| 70 | # If the uprev failed due to a pin, CI needs to unpin and retry. |
| 71 | android_atom_to_build = e.new_android_atom |
| 72 | output_proto.status = android_pb2.MARK_STABLE_STATUS_PINNED |
| 73 | |
| 74 | if android_atom_to_build: |
| 75 | CPV = portage_util.SplitCPV(android_atom_to_build) |
| 76 | output_proto.android_atom.category = CPV.category |
| 77 | output_proto.android_atom.package_name = CPV.package |
| 78 | output_proto.android_atom.version = CPV.version |
| 79 | else: |
| 80 | output_proto.status = android_pb2.MARK_STABLE_STATUS_EARLY_EXIT |
| 81 | |
| 82 | def UnpinVersion(_input_proto, _output_proto): |
| 83 | """Unpin the Android version. |
| 84 | |
| 85 | See AndroidService documentation in api/proto/android.proto. |
| 86 | |
| 87 | Args: |
| 88 | _input_proto (UnpinVersionRequest): The input proto. (not used.) |
| 89 | _output_proto (google.protobuf.Empty): The output proto. (not used.) |
| 90 | """ |
| 91 | |
| 92 | osutils.SafeUnlink(ANDROIDPIN_MASK_PATH) |