blob: 4737a28358aec0a2912c88fc261cf41ad84539c5 [file] [log] [blame]
Alex Kleine66c64d2018-09-11 10:27:49 -06001# Copyright 2018 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Update or initialize the chroot version.
6
7The chroot version hooks provide manually created update files to handle
8tasks that need to be manually run. See also `update_chroot` for updating
9the toolchain and some other packages on the chroot. The `update_chroot` script
10also calls this script. The chroot version and installed package versions are
11not strongly correlated.
12"""
13
Alex Kleine66c64d2018-09-11 10:27:49 -060014from chromite.lib import commandline
15from chromite.lib import cros_build_lib
16from chromite.lib import cros_sdk_lib
17
18
19def GetParser():
20 """Build the ArgumentParser."""
21 parser = commandline.ArgumentParser(description=__doc__)
22 parser.add_argument('-i', '--init-latest',
23 action='store_true', default=False,
24 help='Create the version file with the latest version '
25 "if it doesn't exist.")
26
27 return parser
28
29
30def _ParseArgs(argv):
31 """Parse arguments."""
32 parser = GetParser()
33
34 opts = parser.parse_args(argv)
35 opts.Freeze()
36
37 return opts
38
39
40def main(argv):
41 """Main function."""
42 cros_build_lib.AssertInsideChroot()
43
44 opts = _ParseArgs(argv)
45
46 if opts.init_latest:
47 cros_sdk_lib.InitLatestVersion()
48 else:
49 try:
50 cros_sdk_lib.RunChrootVersionHooks()
51 except cros_sdk_lib.Error as e:
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -040052 cros_build_lib.Die(e)