blob: 6c13082a80967ab3e7739834180857f3450e7bcc [file] [log] [blame]
Alex Kleineb77ffa2019-05-28 14:47:44 -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"""Package related functionality."""
7
8from __future__ import print_function
9
David Burger1e0fe232019-07-01 14:52:07 -060010from chromite.api import validate
Alex Kleineb77ffa2019-05-28 14:47:44 -060011from chromite.api.controller import controller_util
12from chromite.api.gen.chromite.api import binhost_pb2
David Burger1e0fe232019-07-01 14:52:07 -060013from chromite.api.gen.chromiumos import common_pb2
Alex Kleineb77ffa2019-05-28 14:47:44 -060014from chromite.lib import build_target_util
15from chromite.lib import constants
16from chromite.lib import cros_build_lib
17from chromite.service import packages
18
19
20_OVERLAY_TYPE_TO_NAME = {
21 binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS,
22 binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS,
23 binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS,
24}
25
26
27def Uprev(input_proto, _output_proto):
28 """Uprev all cros workon ebuilds that have changes."""
29 if not input_proto.overlay_type:
30 cros_build_lib.Die('Overlay type is required.')
31 elif input_proto.overlay_type not in _OVERLAY_TYPE_TO_NAME:
32 cros_build_lib.Die('Overlay type must be one of: %s',
33 ', '.join(_OVERLAY_TYPE_TO_NAME.values()))
34
35 target_names = [t.name for t in input_proto.build_targets]
36 build_targets = [build_target_util.BuildTarget(t) for t in target_names]
37 overlay_type = _OVERLAY_TYPE_TO_NAME[input_proto.overlay_type]
38 chroot = controller_util.ParseChroot(input_proto.chroot)
39 output_dir = input_proto.output_dir or None
40
41 try:
42 packages.uprev_build_targets(build_targets, overlay_type, chroot,
43 output_dir)
44 except packages.Error as e:
45 # Handle module errors nicely, let everything else bubble up.
46 cros_build_lib.Die(e.message)
David Burger1e0fe232019-07-01 14:52:07 -060047
48@validate.require('atom')
49def GetBestVisible(input_proto, output_proto):
50 """Returns the best visible PackageInfo for the indicated atom."""
51 cpv = packages.get_best_visible(input_proto.atom)
52 package_info = common_pb2.PackageInfo()
53 controller_util.CPVToPackageInfo(cpv, package_info)
54 output_proto.package_info.CopyFrom(package_info)