blob: b314091e0bde93710b854dee212353460983db27 [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
Alex Klein5dd6b1e2019-07-31 15:45:24 -060027def Uprev(input_proto, output_proto):
Alex Kleineb77ffa2019-05-28 14:47:44 -060028 """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:
Alex Klein5dd6b1e2019-07-31 15:45:24 -060042 uprevved = packages.uprev_build_targets(build_targets, overlay_type, chroot,
43 output_dir)
Alex Kleineb77ffa2019-05-28 14:47:44 -060044 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
Alex Klein5dd6b1e2019-07-31 15:45:24 -060048 for path in uprevved:
49 output_proto.modified_ebuilds.add().path = path
50
Evan Hernandez38555d42019-08-05 15:11:54 -060051def UprevVersionedPackage(_input_proto, _output_proto):
52 """Uprev a versioned package.
53
54 See go/pupr-generator for details about this endpoint.
55 """
56 pass
57
David Burger1e0fe232019-07-01 14:52:07 -060058@validate.require('atom')
59def GetBestVisible(input_proto, output_proto):
60 """Returns the best visible PackageInfo for the indicated atom."""
61 cpv = packages.get_best_visible(input_proto.atom)
62 package_info = common_pb2.PackageInfo()
63 controller_util.CPVToPackageInfo(cpv, package_info)
64 output_proto.package_info.CopyFrom(package_info)