| """Collection of utilities to work with gclient.""" |
| |
| from __future__ import absolute_import |
| import imp |
| import logging |
| import os |
| import pathlib |
| |
| from helpers import git_utils |
| |
| _DEPOT_TOOLS_SEARCH_PATHS = [ |
| # Newer containers don't include depot_tools so search for it in the |
| # manifest. This is the preferred version because it will be pinned on |
| # release branches and track upstream on master. |
| pathlib.Path('/workspace/checkout/chromium/tools/depot_tools'), |
| # Legacy containers have depot_tools installed at this path. |
| pathlib.Path('/workspace/depot_tools'), |
| ] |
| |
| |
| def find_depot_tools(): |
| for path in _DEPOT_TOOLS_SEARCH_PATHS: |
| if path.exists(): |
| return path |
| |
| raise ValueError('Cannot find a suitable installation of depot_tools') |
| |
| |
| def disable_depot_tools_auto_update_cmd(): |
| depot_tools_path = find_depot_tools() |
| return [ |
| 'python3', |
| str(depot_tools_path / 'update_depot_tools_toggle.py'), |
| '--disable', |
| ] |
| |
| |
| def gclient_sync_cmd(executor, jobs=None, extra_args=None): |
| """Returns the command list to run gclient sync.""" |
| depot_tools_path = find_depot_tools() |
| logging.info( |
| 'Using depot_tools at %s (%s)', |
| depot_tools_path, |
| git_utils.get_head_sha(executor, str(depot_tools_path)), |
| ) |
| |
| # See go/authenticating-cipd-on-nest-infra for more context on this command. |
| luci_auth_wrapped_cmd = [ |
| str(depot_tools_path / 'luci-auth'), 'context', '-disable-git-auth', '-service-account-json', |
| ':gce', '--', |
| str(depot_tools_path / 'gclient'), 'sync', '--force', '--with_branch_heads', |
| '--delete_unversioned_trees', '--reset' |
| ] |
| |
| if jobs is not None: |
| luci_auth_wrapped_cmd.append('--jobs={}'.format(jobs)) |
| if extra_args is not None: |
| luci_auth_wrapped_cmd.extend(extra_args) |
| |
| return luci_auth_wrapped_cmd |