Pass matching file list to the hook in gclient.

Review URL: http://codereview.chromium.org/160294

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@22224 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
phajdan.jr@chromium.org 17 years ago
parent 67820efbf0
commit 71b4068161

@ -55,7 +55,9 @@ Hooks
The action is executed in the same directory as the .gclient The action is executed in the same directory as the .gclient
file. If the first item in the list is the string "python", file. If the first item in the list is the string "python",
the current Python interpreter (sys.executable) will be used the current Python interpreter (sys.executable) will be used
to run the command. to run the command. If the list contains string "$matching_files"
it will be removed from the list and the list will be extended
by the list of matching files.
Example: Example:
hooks = [ hooks = [
@ -1220,7 +1222,7 @@ class GClient(object):
deps[d] = url deps[d] = url
return deps return deps
def _RunHookAction(self, hook_dict): def _RunHookAction(self, hook_dict, matching_file_list):
"""Runs the action from a single hook. """Runs the action from a single hook.
""" """
command = hook_dict['action'][:] command = hook_dict['action'][:]
@ -1230,6 +1232,10 @@ class GClient(object):
# interpreter. # interpreter.
command[0] = sys.executable command[0] = sys.executable
if '$matching_files' in command:
command.remove('$matching_files')
command.extend(matching_file_list)
# Use a discrete exit status code of 2 to indicate that a hook action # Use a discrete exit status code of 2 to indicate that a hook action
# failed. Users of this script may wish to treat hook action failures # failed. Users of this script may wish to treat hook action failures
# differently from VC failures. # differently from VC failures.
@ -1256,22 +1262,16 @@ class GClient(object):
# changed so we always run all hooks. # changed so we always run all hooks.
if self._options.force or is_using_git: if self._options.force or is_using_git:
for hook_dict in hooks: for hook_dict in hooks:
self._RunHookAction(hook_dict) self._RunHookAction(hook_dict, [])
return return
# Run hooks on the basis of whether the files from the gclient operation # Run hooks on the basis of whether the files from the gclient operation
# match each hook's pattern. # match each hook's pattern.
for hook_dict in hooks: for hook_dict in hooks:
pattern = re.compile(hook_dict['pattern']) pattern = re.compile(hook_dict['pattern'])
for file in file_list: matching_file_list = [file for file in file_list if pattern.search(file)]
if not pattern.search(file): if matching_file_list:
continue self._RunHookAction(hook_dict, matching_file_list)
self._RunHookAction(hook_dict)
# The hook's action only runs once. Don't bother looking for any
# more matches.
break
def RunOnDeps(self, command, args): def RunOnDeps(self, command, args):
"""Runs a command on each dependency in a client and its dependencies. """Runs a command on each dependency in a client and its dependencies.

Loading…
Cancel
Save