Files
chromium_depot_tools/repo
Mike Frysinger 19512276d2 repo: auto-update depot_tools when used
Since gclient automatically syncs this checkout when used,
have repo do the same for CrOS users.

Bug: 1148984
Test: ran and saw it auto-update when used externally
Test: ran and saw it not auto-update when used inside of a repo checkout
Change-Id: I56b9a45ef3a9ed501f6277e8f8357d4719cf2557
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2537164
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
2020-11-25 22:22:23 +00:00

52 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Wrapper around repo to auto-update depot_tools during sync.
gclient keeps depot_tools up-to-date automatically for Chromium developers.
We only want to do this on `repo sync` operations as that implies a network
operation, and update_depot_tools is not cheap.
"""
import os
from pathlib import Path
import subprocess
import sys
# Some useful paths.
DEPOT_TOOLS_DIR = Path(__file__).resolve().parent
UPDATE_DEPOT_TOOLS = DEPOT_TOOLS_DIR / 'update_depot_tools'
REPO = DEPOT_TOOLS_DIR / 'repo_launcher'
def _UpdateDepotTools():
"""Help CrOS users keep their depot_tools checkouts up-to-date."""
if os.getenv('DEPOT_TOOLS_UPDATE') == '0':
return
# We don't update the copy that's part of the CrOS repo client checkout.
path = DEPOT_TOOLS_DIR
while path != path.parent:
if (path / '.repo').is_dir() and (path / 'chromite').is_dir():
return
path = path.parent
subprocess.run([UPDATE_DEPOT_TOOLS], check=True)
def main(argv):
# This is a bit hacky, but should be "good enough". If repo itself gains
# support for sync hooks, we could switch to that.
if argv and argv[0] == 'sync':
_UpdateDepotTools()
os.execv(REPO, [sys.argv[0]] + argv)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))