Commit 5b1fa949 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

gclient: Sync CIPD deps before running hooks.

Bug: 882611
Change-Id: I72646544a164f557ea7d53e0ce0f16d663618a98
Reviewed-on: https://chromium-review.googlesource.com/c/1255446Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent e8f574a2
...@@ -1563,76 +1563,14 @@ it or fix the checkout. ...@@ -1563,76 +1563,14 @@ it or fix the checkout.
patch_refs[patch_repo] = patch_ref patch_refs[patch_repo] = patch_ref
return patch_refs, target_branches return patch_refs, target_branches
def RunOnDeps(self, command, args, ignore_requirements=False, progress=True): def _RemoveUnversionedGitDirs(self):
"""Runs a command on each dependency in a client and its dependencies. """Remove directories that are no longer part of the checkout.
Args: Notify the user if there is an orphaned entry in their working copy.
command: The command to use (e.g., 'status' or 'diff') Only delete the directory if there are no changes in it, and
args: list of str - extra arguments to add to the command line. delete_unversioned_trees is set to true.
""" """
if not self.dependencies:
raise gclient_utils.Error('No solution specified')
revision_overrides = {}
patch_refs = {}
target_branches = {}
# It's unnecessary to check for revision overrides for 'recurse'.
# Save a few seconds by not calling _EnforceRevisions() in that case.
if command not in ('diff', 'recurse', 'runhooks', 'status', 'revert',
'validate'):
self._CheckConfig()
revision_overrides = self._EnforceRevisions()
if command == 'update':
patch_refs, target_branches = self._EnforcePatchRefsAndBranches()
# Disable progress for non-tty stdout.
should_show_progress = (
setup_color.IS_TTY and not self._options.verbose and progress)
pm = None
if should_show_progress:
if command in ('update', 'revert'):
pm = Progress('Syncing projects', 1)
elif command in ('recurse', 'validate'):
pm = Progress(' '.join(args), 1)
work_queue = gclient_utils.ExecutionQueue(
self._options.jobs, pm, ignore_requirements=ignore_requirements,
verbose=self._options.verbose)
for s in self.dependencies:
if s.should_process:
work_queue.enqueue(s)
work_queue.flush(revision_overrides, command, args, options=self._options,
patch_refs=patch_refs, target_branches=target_branches)
if revision_overrides:
print('Please fix your script, having invalid --revision flags will soon '
'be considered an error.', file=sys.stderr)
if patch_refs:
raise gclient_utils.Error(
'The following --patch-ref flags were not used. Please fix it:\n%s' %
('\n'.join(
patch_repo + '@' + patch_ref
for patch_repo, patch_ref in patch_refs.iteritems())))
# Once all the dependencies have been processed, it's now safe to write
# out the gn_args_file and run the hooks.
if command == 'update':
gn_args_dep = self.dependencies[0]
if gn_args_dep._gn_args_from:
deps_map = dict([(dep.name, dep) for dep in gn_args_dep.dependencies])
gn_args_dep = deps_map.get(gn_args_dep._gn_args_from)
if gn_args_dep and gn_args_dep.HasGNArgsFile():
gn_args_dep.WriteGNArgsFile()
if not self._options.nohooks:
if should_show_progress:
pm = Progress('Running hooks', 1)
self.RunHooksRecursively(self._options, pm)
if command == 'update':
# Notify the user if there is an orphaned entry in their working copy.
# Only delete the directory if there are no changes in it, and
# delete_unversioned_trees is set to true.
entries = [i.name for i in self.root.subtree(False) if i.url] entries = [i.name for i in self.root.subtree(False) if i.url]
full_entries = [os.path.join(self.root_dir, e.replace('/', os.path.sep)) full_entries = [os.path.join(self.root_dir, e.replace('/', os.path.sep))
for e in entries] for e in entries]
...@@ -1722,12 +1660,81 @@ it or fix the checkout. ...@@ -1722,12 +1660,81 @@ it or fix the checkout.
# record the current list of entries for next time # record the current list of entries for next time
self._SaveEntries() self._SaveEntries()
def RunOnDeps(self, command, args, ignore_requirements=False, progress=True):
"""Runs a command on each dependency in a client and its dependencies.
Args:
command: The command to use (e.g., 'status' or 'diff')
args: list of str - extra arguments to add to the command line.
"""
if not self.dependencies:
raise gclient_utils.Error('No solution specified')
revision_overrides = {}
patch_refs = {}
target_branches = {}
# It's unnecessary to check for revision overrides for 'recurse'.
# Save a few seconds by not calling _EnforceRevisions() in that case.
if command not in ('diff', 'recurse', 'runhooks', 'status', 'revert',
'validate'):
self._CheckConfig()
revision_overrides = self._EnforceRevisions()
if command == 'update':
patch_refs, target_branches = self._EnforcePatchRefsAndBranches()
# Disable progress for non-tty stdout.
should_show_progress = (
setup_color.IS_TTY and not self._options.verbose and progress)
pm = None
if should_show_progress:
if command in ('update', 'revert'):
pm = Progress('Syncing projects', 1)
elif command in ('recurse', 'validate'):
pm = Progress(' '.join(args), 1)
work_queue = gclient_utils.ExecutionQueue(
self._options.jobs, pm, ignore_requirements=ignore_requirements,
verbose=self._options.verbose)
for s in self.dependencies:
if s.should_process:
work_queue.enqueue(s)
work_queue.flush(revision_overrides, command, args, options=self._options,
patch_refs=patch_refs, target_branches=target_branches)
if revision_overrides:
print('Please fix your script, having invalid --revision flags will soon '
'be considered an error.', file=sys.stderr)
if patch_refs:
raise gclient_utils.Error(
'The following --patch-ref flags were not used. Please fix it:\n%s' %
('\n'.join(
patch_repo + '@' + patch_ref
for patch_repo, patch_ref in patch_refs.iteritems())))
# Once all the dependencies have been processed, it's now safe to write
# out the gn_args_file and run the hooks.
if command == 'update':
gn_args_dep = self.dependencies[0]
if gn_args_dep._gn_args_from:
deps_map = dict([(dep.name, dep) for dep in gn_args_dep.dependencies])
gn_args_dep = deps_map.get(gn_args_dep._gn_args_from)
if gn_args_dep and gn_args_dep.HasGNArgsFile():
gn_args_dep.WriteGNArgsFile()
self._RemoveUnversionedGitDirs()
# Sync CIPD dependencies once removed deps are deleted. In case a git # Sync CIPD dependencies once removed deps are deleted. In case a git
# dependency was moved to CIPD, we want to remove the old git directory # dependency was moved to CIPD, we want to remove the old git directory
# first and then sync the CIPD dep. # first and then sync the CIPD dep.
if self._cipd_root: if self._cipd_root:
self._cipd_root.run(command) self._cipd_root.run(command)
if not self._options.nohooks:
if should_show_progress:
pm = Progress('Running hooks', 1)
self.RunHooksRecursively(self._options, pm)
return 0 return 0
def PrintRevInfo(self): def PrintRevInfo(self):
......
...@@ -756,7 +756,12 @@ deps = { ...@@ -756,7 +756,12 @@ deps = {
], ],
'dep_type': 'cipd', 'dep_type': 'cipd',
}, },
}""", }
hooks = [{
# make sure src/repo12 exists and is a CIPD dir.
'action': ['python', '-c', 'with open("src/repo12/_cipd"): pass'],
}]
""",
'origin': 'git/repo_13@3\n' 'origin': 'git/repo_13@3\n'
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment