Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 1 | # 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 | |
| 7 | The chroot version hooks provide manually created update files to handle |
| 8 | tasks that need to be manually run. See also `update_chroot` for updating |
| 9 | the toolchain and some other packages on the chroot. The `update_chroot` script |
| 10 | also calls this script. The chroot version and installed package versions are |
| 11 | not strongly correlated. |
| 12 | """ |
| 13 | |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 14 | from chromite.lib import commandline |
| 15 | from chromite.lib import cros_build_lib |
| 16 | from chromite.lib import cros_sdk_lib |
| 17 | |
| 18 | |
| 19 | def GetParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 20 | """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 Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 30 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 31 | return parser |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 32 | |
| 33 | |
| 34 | def _ParseArgs(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 35 | """Parse arguments.""" |
| 36 | parser = GetParser() |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 37 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 38 | opts = parser.parse_args(argv) |
| 39 | opts.Freeze() |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 40 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 41 | return opts |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 42 | |
| 43 | |
| 44 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 45 | """Main function.""" |
| 46 | cros_build_lib.AssertInsideChroot() |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 47 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 48 | opts = _ParseArgs(argv) |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 49 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 50 | 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) |