blob: 880da603b48fd43d00ec62ad91f5006d88513e81 [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.')