blob: 4dc55b808ada036f32b99698a180fbca529aedca [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
12from chromite.api.gen.chromite.api import android_pb2
13# TODO(crbug/904939): implement service/android.
14from chromite.cbuildbot import commands
15from chromite.lib import constants
16from chromite.lib import cros_build_lib
17from chromite.lib import osutils
18from chromite.lib import portage_util
19
20
21ANDROIDPIN_MASK_PATH = os.path.join(constants.SOURCE_ROOT,
22 constants.CHROMIUMOS_OVERLAY_DIR,
23 'profiles', 'default', 'linux',
24 'package.mask', 'androidpin')
25
26
27def 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
82def 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)