blob: 6fa9410bbc5e87d5f2f9be9d747c179bf0a22cfe [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
Alex Klein87531182019-08-12 15:23:37 -060017from chromite.lib.uprev_lib import GitRef
Alex Kleineb77ffa2019-05-28 14:47:44 -060018from chromite.service import packages
19
20
21_OVERLAY_TYPE_TO_NAME = {
22 binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS,
23 binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS,
24 binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS,
25}
26
27
Alex Klein231d2da2019-07-22 16:44:45 -060028@validate.require('overlay_type')
29@validate.is_in('overlay_type', _OVERLAY_TYPE_TO_NAME)
30@validate.validation_complete
31def Uprev(input_proto, output_proto, _config):
Alex Kleineb77ffa2019-05-28 14:47:44 -060032 """Uprev all cros workon ebuilds that have changes."""
Alex Kleineb77ffa2019-05-28 14:47:44 -060033 target_names = [t.name for t in input_proto.build_targets]
34 build_targets = [build_target_util.BuildTarget(t) for t in target_names]
35 overlay_type = _OVERLAY_TYPE_TO_NAME[input_proto.overlay_type]
36 chroot = controller_util.ParseChroot(input_proto.chroot)
37 output_dir = input_proto.output_dir or None
38
39 try:
Alex Klein5dd6b1e2019-07-31 15:45:24 -060040 uprevved = packages.uprev_build_targets(build_targets, overlay_type, chroot,
41 output_dir)
Alex Kleineb77ffa2019-05-28 14:47:44 -060042 except packages.Error as e:
43 # Handle module errors nicely, let everything else bubble up.
44 cros_build_lib.Die(e.message)
David Burger1e0fe232019-07-01 14:52:07 -060045
Alex Klein5dd6b1e2019-07-31 15:45:24 -060046 for path in uprevved:
47 output_proto.modified_ebuilds.add().path = path
48
Alex Klein231d2da2019-07-22 16:44:45 -060049
Alex Klein87531182019-08-12 15:23:37 -060050@validate.require('versions')
51@validate.require('package_info.package_name', 'package_info.category')
Alex Klein231d2da2019-07-22 16:44:45 -060052@validate.validation_complete
Alex Klein87531182019-08-12 15:23:37 -060053def UprevVersionedPackage(input_proto, output_proto, _config):
Evan Hernandez38555d42019-08-05 15:11:54 -060054 """Uprev a versioned package.
55
56 See go/pupr-generator for details about this endpoint.
57 """
Alex Klein87531182019-08-12 15:23:37 -060058 chroot = controller_util.ParseChroot(input_proto.chroot)
59 build_targets = controller_util.ParseBuildTargets(input_proto.build_targets)
60 package = controller_util.PackageInfoToCPV(input_proto.package_info)
61 refs = []
62 for ref in input_proto.versions:
63 refs.append(GitRef(path=ref.repository, ref=ref.ref, revision=ref.revision))
64
65 try:
66 uprevved = packages.uprev_versioned_package(package, build_targets, refs,
67 chroot)
68 except packages.Error as e:
69 # Handle module errors nicely, let everything else bubble up.
70 cros_build_lib.Die(e.message)
71
72 for path in uprevved:
73 output_proto.modified_ebuilds.add().path = path
74
Evan Hernandez38555d42019-08-05 15:11:54 -060075
Alex Klein231d2da2019-07-22 16:44:45 -060076
David Burger1e0fe232019-07-01 14:52:07 -060077@validate.require('atom')
Alex Klein231d2da2019-07-22 16:44:45 -060078@validate.validation_complete
79def GetBestVisible(input_proto, output_proto, _config):
David Burger1e0fe232019-07-01 14:52:07 -060080 """Returns the best visible PackageInfo for the indicated atom."""
81 cpv = packages.get_best_visible(input_proto.atom)
82 package_info = common_pb2.PackageInfo()
83 controller_util.CPVToPackageInfo(cpv, package_info)
84 output_proto.package_info.CopyFrom(package_info)