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