blob: b3fe21403d704d018ec9247dae8ff08920779a7a [file] [log] [blame]
LaMont Jones8a1644f2019-04-16 14:30:17 -06001# -*- 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
8from __future__ import print_function
9
10import os
11
Alex Klein076841b2019-08-29 15:19:39 -060012from chromite.api import faux
Alex Klein2b236722019-06-19 15:44:26 -060013from chromite.api import validate
Alex Klein4de25e82019-08-05 15:58:39 -060014from chromite.api.controller import controller_util
LaMont Jones8a1644f2019-04-16 14:30:17 -060015from chromite.api.gen.chromite.api import android_pb2
LaMont Jones8a1644f2019-04-16 14:30:17 -060016from chromite.lib import constants
LaMont Jones8a1644f2019-04-16 14:30:17 -060017from chromite.lib import osutils
Alex Klein18a60af2020-06-11 12:08:47 -060018from chromite.lib.parser import package_info
Alex Klein4de25e82019-08-05 15:58:39 -060019from chromite.service import packages
LaMont Jones8a1644f2019-04-16 14:30:17 -060020
21
22ANDROIDPIN_MASK_PATH = os.path.join(constants.SOURCE_ROOT,
23 constants.CHROMIUMOS_OVERLAY_DIR,
24 'profiles', 'default', 'linux',
25 'package.mask', 'androidpin')
26
27
Michael Mortensen25626442019-11-22 10:06:59 -070028def _MarkStableResponse(_input_proto, output_proto, _config):
29 """Add fake status to a successful response."""
30 output_proto.android_atom.category = 'category'
31 output_proto.android_atom.package_name = 'android-package-name'
32 output_proto.android_atom.version = '1.2'
33 output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS
34
35
36@faux.success(_MarkStableResponse)
37@faux.empty_error
Boleyn Su1ffc2752020-12-18 07:16:17 +090038@validate.require('package_name', 'android_build_branch')
Alex Klein231d2da2019-07-22 16:44:45 -060039@validate.validation_complete
40def MarkStable(input_proto, output_proto, _config):
LaMont Jones8a1644f2019-04-16 14:30:17 -060041 """Uprev Android, if able.
42
43 Uprev Android, verify that the newly uprevved package can be emerged, and
44 return the new package info.
45
46 See AndroidService documentation in api/proto/android.proto.
47
48 Args:
49 input_proto (MarkStableRequest): The input proto.
Alex Klein231d2da2019-07-22 16:44:45 -060050 output_proto (MarkStableResponse): The output proto.
51 _config (api_config.ApiConfig): The call config.
LaMont Jones8a1644f2019-04-16 14:30:17 -060052 """
Alex Klein4de25e82019-08-05 15:58:39 -060053 chroot = controller_util.ParseChroot(input_proto.chroot)
54 build_targets = controller_util.ParseBuildTargets(input_proto.build_targets)
LaMont Jones8a1644f2019-04-16 14:30:17 -060055 tracking_branch = input_proto.tracking_branch
56 package_name = input_proto.package_name
57 android_build_branch = input_proto.android_build_branch
58 android_version = input_proto.android_version
LaMont Jones8a1644f2019-04-16 14:30:17 -060059
LaMont Jones8a1644f2019-04-16 14:30:17 -060060 # Assume success.
61 output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS
David Burgerff1a92c2019-07-09 00:27:54 +000062 # TODO(crbug/904939): This should move to service/android.py and the port
63 # should be finished.
LaMont Jones8a1644f2019-04-16 14:30:17 -060064 try:
Alex Klein4de25e82019-08-05 15:58:39 -060065 android_atom_to_build = packages.uprev_android(
LaMont Jones8a1644f2019-04-16 14:30:17 -060066 tracking_branch=tracking_branch,
67 android_package=package_name,
68 android_build_branch=android_build_branch,
Alex Klein4de25e82019-08-05 15:58:39 -060069 chroot=chroot,
70 build_targets=build_targets,
Shao-Chuan Lee9c39e0c2020-04-24 11:40:34 +090071 android_version=android_version)
Alex Klein4de25e82019-08-05 15:58:39 -060072 except packages.AndroidIsPinnedUprevError as e:
LaMont Jones8a1644f2019-04-16 14:30:17 -060073 # If the uprev failed due to a pin, CI needs to unpin and retry.
74 android_atom_to_build = e.new_android_atom
75 output_proto.status = android_pb2.MARK_STABLE_STATUS_PINNED
76
77 if android_atom_to_build:
Alex Klein16c0f302020-10-06 17:28:14 -060078 pkg = package_info.parse(android_atom_to_build)
79 controller_util.serialize_package_info(pkg, output_proto.android_atom)
LaMont Jones8a1644f2019-04-16 14:30:17 -060080 else:
81 output_proto.status = android_pb2.MARK_STABLE_STATUS_EARLY_EXIT
82
Alex Klein2b236722019-06-19 15:44:26 -060083
Michael Mortensen25626442019-11-22 10:06:59 -070084# We don't use @faux.success for UnpinVersion because output_proto is unused.
Alex Klein076841b2019-08-29 15:19:39 -060085@faux.all_empty
Alex Klein231d2da2019-07-22 16:44:45 -060086@validate.validation_complete
87def UnpinVersion(_input_proto, _output_proto, _config):
LaMont Jones8a1644f2019-04-16 14:30:17 -060088 """Unpin the Android version.
89
90 See AndroidService documentation in api/proto/android.proto.
91
92 Args:
93 _input_proto (UnpinVersionRequest): The input proto. (not used.)
Alex Klein231d2da2019-07-22 16:44:45 -060094 _output_proto (UnpinVersionResponse): The output proto. (not used.)
95 _config (api_config.ApiConfig): The call config.
LaMont Jones8a1644f2019-04-16 14:30:17 -060096 """
LaMont Jones8a1644f2019-04-16 14:30:17 -060097 osutils.SafeUnlink(ANDROIDPIN_MASK_PATH)