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 |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame^] | 11 | import sys |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 12 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 13 | from chromite.api import faux |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 14 | from chromite.api import validate |
Alex Klein | 4de25e8 | 2019-08-05 15:58:39 -0600 | [diff] [blame] | 15 | from chromite.api.controller import controller_util |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 16 | from chromite.api.gen.chromite.api import android_pb2 |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 17 | from chromite.lib import constants |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 18 | from chromite.lib import osutils |
| 19 | from chromite.lib import portage_util |
Alex Klein | 4de25e8 | 2019-08-05 15:58:39 -0600 | [diff] [blame] | 20 | from chromite.service import packages |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 21 | |
| 22 | |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame^] | 23 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 24 | |
| 25 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 26 | ANDROIDPIN_MASK_PATH = os.path.join(constants.SOURCE_ROOT, |
| 27 | constants.CHROMIUMOS_OVERLAY_DIR, |
| 28 | 'profiles', 'default', 'linux', |
| 29 | 'package.mask', 'androidpin') |
| 30 | |
| 31 | |
Michael Mortensen | 2562644 | 2019-11-22 10:06:59 -0700 | [diff] [blame] | 32 | def _MarkStableResponse(_input_proto, output_proto, _config): |
| 33 | """Add fake status to a successful response.""" |
| 34 | output_proto.android_atom.category = 'category' |
| 35 | output_proto.android_atom.package_name = 'android-package-name' |
| 36 | output_proto.android_atom.version = '1.2' |
| 37 | output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS |
| 38 | |
| 39 | |
| 40 | @faux.success(_MarkStableResponse) |
| 41 | @faux.empty_error |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 42 | @validate.require('tracking_branch', 'package_name', 'android_build_branch') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 43 | @validate.validation_complete |
| 44 | def MarkStable(input_proto, output_proto, _config): |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 45 | """Uprev Android, if able. |
| 46 | |
| 47 | Uprev Android, verify that the newly uprevved package can be emerged, and |
| 48 | return the new package info. |
| 49 | |
| 50 | See AndroidService documentation in api/proto/android.proto. |
| 51 | |
| 52 | Args: |
| 53 | input_proto (MarkStableRequest): The input proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 54 | output_proto (MarkStableResponse): The output proto. |
| 55 | _config (api_config.ApiConfig): The call config. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 56 | """ |
Alex Klein | 4de25e8 | 2019-08-05 15:58:39 -0600 | [diff] [blame] | 57 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 58 | build_targets = controller_util.ParseBuildTargets(input_proto.build_targets) |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 59 | tracking_branch = input_proto.tracking_branch |
| 60 | package_name = input_proto.package_name |
| 61 | android_build_branch = input_proto.android_build_branch |
| 62 | android_version = input_proto.android_version |
| 63 | android_gts_build_branch = input_proto.android_gts_build_branch |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 64 | |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 65 | # Assume success. |
| 66 | output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS |
David Burger | ff1a92c | 2019-07-09 00:27:54 +0000 | [diff] [blame] | 67 | # TODO(crbug/904939): This should move to service/android.py and the port |
| 68 | # should be finished. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 69 | try: |
Alex Klein | 4de25e8 | 2019-08-05 15:58:39 -0600 | [diff] [blame] | 70 | android_atom_to_build = packages.uprev_android( |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 71 | tracking_branch=tracking_branch, |
| 72 | android_package=package_name, |
| 73 | android_build_branch=android_build_branch, |
Alex Klein | 4de25e8 | 2019-08-05 15:58:39 -0600 | [diff] [blame] | 74 | chroot=chroot, |
| 75 | build_targets=build_targets, |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 76 | android_version=android_version, |
| 77 | android_gts_build_branch=android_gts_build_branch) |
Alex Klein | 4de25e8 | 2019-08-05 15:58:39 -0600 | [diff] [blame] | 78 | except packages.AndroidIsPinnedUprevError as e: |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 79 | # If the uprev failed due to a pin, CI needs to unpin and retry. |
| 80 | android_atom_to_build = e.new_android_atom |
| 81 | output_proto.status = android_pb2.MARK_STABLE_STATUS_PINNED |
| 82 | |
| 83 | if android_atom_to_build: |
| 84 | CPV = portage_util.SplitCPV(android_atom_to_build) |
| 85 | output_proto.android_atom.category = CPV.category |
| 86 | output_proto.android_atom.package_name = CPV.package |
| 87 | output_proto.android_atom.version = CPV.version |
| 88 | else: |
| 89 | output_proto.status = android_pb2.MARK_STABLE_STATUS_EARLY_EXIT |
| 90 | |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 91 | |
Michael Mortensen | 2562644 | 2019-11-22 10:06:59 -0700 | [diff] [blame] | 92 | # We don't use @faux.success for UnpinVersion because output_proto is unused. |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 93 | @faux.all_empty |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 94 | @validate.validation_complete |
| 95 | def UnpinVersion(_input_proto, _output_proto, _config): |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 96 | """Unpin the Android version. |
| 97 | |
| 98 | See AndroidService documentation in api/proto/android.proto. |
| 99 | |
| 100 | Args: |
| 101 | _input_proto (UnpinVersionRequest): The input proto. (not used.) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 102 | _output_proto (UnpinVersionResponse): The output proto. (not used.) |
| 103 | _config (api_config.ApiConfig): The call config. |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 104 | """ |
LaMont Jones | 8a1644f | 2019-04-16 14:30:17 -0600 | [diff] [blame] | 105 | osutils.SafeUnlink(ANDROIDPIN_MASK_PATH) |