blob: cdbb9aae2fc5b5c48fdbc2feff62cc8109791c33 [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 Klein2b236722019-06-19 15:44:26 -060012from chromite.api import validate
LaMont Jones8a1644f2019-04-16 14:30:17 -060013from chromite.api.gen.chromite.api import android_pb2
14# TODO(crbug/904939): implement service/android.
15from chromite.cbuildbot import commands
16from chromite.lib import constants
LaMont Jones8a1644f2019-04-16 14:30:17 -060017from 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
Alex Klein2b236722019-06-19 15:44:26 -060027@validate.require('tracking_branch', 'package_name', 'android_build_branch')
LaMont Jones8a1644f2019-04-16 14:30:17 -060028def MarkStable(input_proto, output_proto):
29 """Uprev Android, if able.
30
31 Uprev Android, verify that the newly uprevved package can be emerged, and
32 return the new package info.
33
34 See AndroidService documentation in api/proto/android.proto.
35
36 Args:
37 input_proto (MarkStableRequest): The input proto.
38 output_proto (MarkStableReSponse): The output proto.
39 """
40 tracking_branch = input_proto.tracking_branch
41 package_name = input_proto.package_name
42 android_build_branch = input_proto.android_build_branch
43 android_version = input_proto.android_version
44 android_gts_build_branch = input_proto.android_gts_build_branch
45 boards = input_proto.boards
46 buildroot = input_proto.buildroot
47
LaMont Jones8a1644f2019-04-16 14:30:17 -060048 # Assume success.
49 output_proto.status = android_pb2.MARK_STABLE_STATUS_SUCCESS
50 # TODO(crbug/904939): This should move to service/android.py and the port
51 # should be finished.
52 try:
53 android_atom_to_build = commands.MarkAndroidAsStable(
54 buildroot=buildroot,
55 tracking_branch=tracking_branch,
56 android_package=package_name,
57 android_build_branch=android_build_branch,
58 boards=boards,
59 android_version=android_version,
60 android_gts_build_branch=android_gts_build_branch)
61 except commands.AndroidIsPinnedUprevError as e:
62 # If the uprev failed due to a pin, CI needs to unpin and retry.
63 android_atom_to_build = e.new_android_atom
64 output_proto.status = android_pb2.MARK_STABLE_STATUS_PINNED
65
66 if android_atom_to_build:
67 CPV = portage_util.SplitCPV(android_atom_to_build)
68 output_proto.android_atom.category = CPV.category
69 output_proto.android_atom.package_name = CPV.package
70 output_proto.android_atom.version = CPV.version
71 else:
72 output_proto.status = android_pb2.MARK_STABLE_STATUS_EARLY_EXIT
73
Alex Klein2b236722019-06-19 15:44:26 -060074
LaMont Jones8a1644f2019-04-16 14:30:17 -060075def UnpinVersion(_input_proto, _output_proto):
76 """Unpin the Android version.
77
78 See AndroidService documentation in api/proto/android.proto.
79
80 Args:
81 _input_proto (UnpinVersionRequest): The input proto. (not used.)
82 _output_proto (google.protobuf.Empty): The output proto. (not used.)
83 """
84
85 osutils.SafeUnlink(ANDROIDPIN_MASK_PATH)