blob: 7216d00df70aeb8b862b57416c6590b2f87f486d [file] [log] [blame]
Alex Kleine66c64d2018-09-11 10:27:49 -06001# -*- coding: utf-8 -*-
2# Copyright 2018 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"""Update or initialize the chroot version.
7
8The chroot version hooks provide manually created update files to handle
9tasks that need to be manually run. See also `update_chroot` for updating
10the toolchain and some other packages on the chroot. The `update_chroot` script
11also calls this script. The chroot version and installed package versions are
12not strongly correlated.
13"""
14
15from __future__ import print_function
16
17from chromite.lib import commandline
18from chromite.lib import cros_build_lib
19from chromite.lib import cros_sdk_lib
20
21
22def GetParser():
23 """Build the ArgumentParser."""
24 parser = commandline.ArgumentParser(description=__doc__)
25 parser.add_argument('-i', '--init-latest',
26 action='store_true', default=False,
27 help='Create the version file with the latest version '
28 "if it doesn't exist.")
29
30 return parser
31
32
33def _ParseArgs(argv):
34 """Parse arguments."""
35 parser = GetParser()
36
37 opts = parser.parse_args(argv)
38 opts.Freeze()
39
40 return opts
41
42
43def main(argv):
44 """Main function."""
45 cros_build_lib.AssertInsideChroot()
46
47 opts = _ParseArgs(argv)
48
49 if opts.init_latest:
50 cros_sdk_lib.InitLatestVersion()
51 else:
52 try:
53 cros_sdk_lib.RunChrootVersionHooks()
54 except cros_sdk_lib.Error as e:
55 cros_build_lib.Die(e.message)