blob: 1b9eb108cb9085f76987906ca8fd2065fe0947e4 [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():
Alex Klein1699fab2022-09-08 08:46:06 -060020 """Build the ArgumentParser."""
21 parser = commandline.ArgumentParser(description=__doc__)
22 parser.add_argument(
23 "-i",
24 "--init-latest",
25 action="store_true",
26 default=False,
27 help="Create the version file with the latest version "
28 "if it doesn't exist.",
29 )
Alex Kleine66c64d2018-09-11 10:27:49 -060030
Alex Klein1699fab2022-09-08 08:46:06 -060031 return parser
Alex Kleine66c64d2018-09-11 10:27:49 -060032
33
34def _ParseArgs(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060035 """Parse arguments."""
36 parser = GetParser()
Alex Kleine66c64d2018-09-11 10:27:49 -060037
Alex Klein1699fab2022-09-08 08:46:06 -060038 opts = parser.parse_args(argv)
39 opts.Freeze()
Alex Kleine66c64d2018-09-11 10:27:49 -060040
Alex Klein1699fab2022-09-08 08:46:06 -060041 return opts
Alex Kleine66c64d2018-09-11 10:27:49 -060042
43
44def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060045 """Main function."""
46 cros_build_lib.AssertInsideChroot()
Alex Kleine66c64d2018-09-11 10:27:49 -060047
Alex Klein1699fab2022-09-08 08:46:06 -060048 opts = _ParseArgs(argv)
Alex Kleine66c64d2018-09-11 10:27:49 -060049
Alex Klein1699fab2022-09-08 08:46:06 -060050 if opts.init_latest:
51 cros_sdk_lib.InitLatestVersion()
52 else:
53 try:
54 cros_sdk_lib.RunChrootVersionHooks()
55 except cros_sdk_lib.Error as e:
56 cros_build_lib.Die(e)