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 |
Alex Klein | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 13 | from chromite.api.controller import controller_util |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 14 | from chromite.api.gen.chromite.api import android_pb2 |
Alex Klein | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 15 | from chromite.lib import build_target_util |
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 |
Alex Klein | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 19 | from chromite.service import packages |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 20 | |
| 21 | |
| 22 | ANDROIDPIN_MASK_PATH = os.path.join(constants.SOURCE_ROOT, |
| 23 | constants.CHROMIUMOS_OVERLAY_DIR, |
| 24 | 'profiles', 'default', 'linux', |
| 25 | 'package.mask', 'androidpin') |
| 26 | |
| 27 | |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 28 | @validate.require('tracking_branch', 'package_name', 'android_build_branch') |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 29 | def MarkStable(input_proto, output_proto): |
| 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 | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 39 | output_proto (MarkStableResponse): The output proto. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 40 | """ |
Alex Klein | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 41 | chroot = controller_util.ParseChroot(input_proto.chroot) |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 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 | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 47 | |
| 48 | build_targets = [] |
| 49 | for build_target in input_proto.build_targets: |
| 50 | build_targets.append(build_target_util.BuildTarget(build_target.name)) |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 51 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 52 | # Assume success. |
| 53 | output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 54 | try: |
Alex Klein | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 55 | android_atom_to_build = packages.uprev_android( |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 56 | tracking_branch=tracking_branch, |
| 57 | android_package=package_name, |
| 58 | android_build_branch=android_build_branch, |
Alex Klein | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 59 | chroot=chroot, |
| 60 | build_targets=build_targets, |
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 | eb8616c | 2019-06-28 12:26:23 -0600 | [diff] [blame] | 63 | except packages.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 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 77 | def UnpinVersion(_input_proto, _output_proto): |
| 78 | """Unpin the Android version. |
| 79 | |
| 80 | See AndroidService documentation in api/proto/android.proto. |
| 81 | |
| 82 | Args: |
| 83 | _input_proto (UnpinVersionRequest): The input proto. (not used.) |
| 84 | _output_proto (google.protobuf.Empty): The output proto. (not used.) |
| 85 | """ |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 86 | osutils.SafeUnlink(ANDROIDPIN_MASK_PATH) |