diff options
author | George Burgess IV <gbiv@google.com> | 2024-03-13 09:18:17 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-03-13 16:36:29 +0000 |
commit | 013f7a3e990cee4e673e44b17d53d2dcd593fe84 (patch) | |
tree | 05f190ba2fa87c11c66087dad9dd6dc8a2242d12 | |
parent | 9b2e8e11812cd825ea2cc301554e08410fb9263e (diff) | |
download | toolchain-utils-013f7a3e990cee4e673e44b17d53d2dcd593fe84.tar.gz |
toolchain_utils_githooks: add --install_deps_only flag
This flag is useful if folks who commit to toolchain-utils set up their
chroots in some sort of background process. Saves time on `repo upload`
since all deps are already installed.
BUG=None
TEST=Ran the script with --install_deps_only.
Change-Id: I4414b16eec313ee6943fb76e559aa0e9a213bc76
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/5367609
Reviewed-by: Bob Haarman <inglorion@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
-rwxr-xr-x | toolchain_utils_githooks/check-presubmit.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/toolchain_utils_githooks/check-presubmit.py b/toolchain_utils_githooks/check-presubmit.py index 2af7569c..561ac6ce 100755 --- a/toolchain_utils_githooks/check-presubmit.py +++ b/toolchain_utils_githooks/check-presubmit.py @@ -897,7 +897,9 @@ def is_in_chroot() -> bool: return os.path.exists("/etc/cros_chroot_version") -def maybe_reexec_inside_chroot(autofix: bool, files: List[str]) -> None: +def maybe_reexec_inside_chroot( + autofix: bool, install_deps_only: bool, files: List[str] +) -> None: if is_in_chroot(): return @@ -944,6 +946,8 @@ def maybe_reexec_inside_chroot(autofix: bool, files: List[str]) -> None: if not autofix: args.append("--no_autofix") + if install_deps_only: + args.append("--install_deps_only") args.extend(rebase_path(x) for x in files) if chdir_to is None: @@ -990,20 +994,39 @@ def main(argv: List[str]) -> int: action="store_false", help="Prevent auto-entering the chroot if we're not already in it.", ) + parser.add_argument( + "--install_deps_only", + action="store_true", + help=""" + Only install dependencies that would be required if presubmits were + being run, and quit. This skips all actual checking. + """, + ) parser.add_argument("files", nargs="*") opts = parser.parse_args(argv) files = opts.files - if not files: + install_deps_only = opts.install_deps_only + if not files and not install_deps_only: return 0 if opts.enter_chroot: - maybe_reexec_inside_chroot(opts.autofix, opts.files) + maybe_reexec_inside_chroot(opts.autofix, install_deps_only, files) # If you ask for --no_enter_chroot, you're on your own for installing these # things. if is_in_chroot(): ensure_pip_deps_installed() + if install_deps_only: + print( + "Dependency installation complete & --install_deps_only " + "passed. Quit." + ) + return 0 + elif install_deps_only: + parser.error( + "--install_deps_only is meaningless if the chroot isn't entered" + ) files = [os.path.abspath(f) for f in files] |