blob: 25ec2bfd2eceb81d6ad3ba614010dc5168f0b993 [file] [log] [blame]
Alex Klein19c4cc42019-02-27 14:47:57 -07001# -*- 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"""SDK chroot operations."""
7
8from __future__ import print_function
9
10import os
11
12from chromite.lib import cros_build_lib
13from chromite.service import sdk
14
15
16def Create(input_proto, output_proto):
17 """Chroot creation, includes support for replacing an existing chroot.
18
19 Args:
20 input_proto (CreateRequest): The input proto.
21 output_proto (CreateResponse): The output proto.
22 """
23 replace = not input_proto.flags.no_replace
24 bootstrap = input_proto.flags.bootstrap
25 use_image = not input_proto.flags.no_use_image
26
27 chrome_root = input_proto.paths.chrome
28 cache_dir = input_proto.paths.cache
29 chroot_path = input_proto.paths.chroot
30
31 if chroot_path and not os.path.isabs(chroot_path):
32 cros_build_lib.Die('The chroot path must be absolute.')
33
34 paths = sdk.ChrootPaths(cache_dir=cache_dir, chrome_root=chrome_root,
35 chroot_path=chroot_path)
36 args = sdk.CreateArguments(replace=replace, bootstrap=bootstrap,
37 use_image=use_image, paths=paths)
38
39 version = sdk.Create(args)
40
41 if version:
42 output_proto.version.version = version
43 else:
44 # This should be very rare, if ever used, but worth noting.
45 cros_build_lib.Die('No chroot version could be found. There was likely an'
46 'error creating the chroot that was not detected.')
Alex Kleinaa5c4172019-02-27 17:12:20 -070047
48
49def Update(input_proto, output_proto):
50 """Update the chroot.
51
52 Args:
53 input_proto (UpdateRequest): The input proto.
54 output_proto (UpdateResponse): The output proto.
55 """
56 build_source = input_proto.flags.build_source
57 targets = [target.name for target in input_proto.toolchain_targets]
58
59 args = sdk.UpdateArguments(build_source=build_source,
60 toolchain_targets=targets)
61 version = sdk.Update(args)
62
63 if version:
64 output_proto.version.version = version
65 else:
66 # This should be very rare, if ever used, but worth noting.
67 cros_build_lib.Die('No chroot version could be found. There was likely an'
68 'error creating the chroot that was not detected.')