Index: gclient.py |
=================================================================== |
--- gclient.py (revision 119695) |
+++ gclient.py (working copy) |
@@ -585,10 +585,12 @@ |
self._parsed_url = parsed_url |
self._processed = True |
- def RunHooksRecursively(self, options): |
+ def RunHooksRecursively(self, options, action=None): |
"""Evaluates all hooks, running actions as needed. run() |
M-A Ruel
2012/01/30 19:23:07
... running |action| for each hook. or something l
szager
2012/01/31 00:22:20
Done.
|
must have been called before to load the DEPS.""" |
assert self.hooks_ran == False |
+ if not action: |
M-A Ruel
2012/01/30 19:23:07
action = action or self._RunHookAction
szager
2012/01/31 00:22:20
Done.
|
+ action = self._RunHookAction |
if not self.should_process or not self.recursion_limit: |
# Don't run the hook when it is above recursion_limit. |
return |
@@ -603,7 +605,7 @@ |
gclient_scm.GetScmName(self.parsed_url) in ('git', None) or |
os.path.isdir(os.path.join(self.root.root_dir, self.name, '.git'))): |
for hook_dict in self.deps_hooks: |
- self._RunHookAction(hook_dict, []) |
+ action(hook_dict, []) |
else: |
# Run hooks on the basis of whether the files from the gclient operation |
# match each hook's pattern. |
@@ -613,9 +615,9 @@ |
f for f in self.file_list_and_children if pattern.search(f) |
] |
if matching_file_list: |
- self._RunHookAction(hook_dict, matching_file_list) |
+ action(hook_dict, matching_file_list) |
for s in self.dependencies: |
- s.RunHooksRecursively(options) |
+ s.RunHooksRecursively(options, action=action) |
M-A Ruel
2012/01/30 19:23:07
My idea was to still call _RunHookAtion but add an
szager
2012/01/31 00:22:20
OK. Patch is now much bigger...
|
def _RunHookAction(self, hook_dict, matching_file_list): |
"""Runs the action from a single hook.""" |
@@ -1080,6 +1082,21 @@ |
print('%s: %s' % (x, entries[x])) |
logging.info(str(self)) |
+ def HookInfo(self): |
+ work_queue = gclient_utils.ExecutionQueue(self._options.jobs, None) |
+ for s in self.dependencies: |
+ work_queue.enqueue(s) |
+ work_queue.flush({}, None, [], options=self._options) |
+ hooks = [] |
+ def _process_hook(hook_dict, matching_file_list): |
+ command = hook_dict['action'][:] |
+ if '$matching_files' in command: |
+ splice_index = command.index('$matching_files') |
+ command[splice_index:splice_index + 1] = matching_file_list |
+ hooks.append(command) |
+ self.RunHooksRecursively(self._options, action=_process_hook) |
+ return hooks |
+ |
def ParseDepsFile(self): |
"""No DEPS to parse for a .gclient file.""" |
raise gclient_utils.Error('Internal error') |
@@ -1423,6 +1440,17 @@ |
return 0 |
+def CMDhookinfo(parser, args): |
+ """Output the hooks that would be run by `gclient runhooks`""" |
+ |
+ (options, args) = parser.parse_args(args) |
+ client = GClient.LoadCurrentConfig(options) |
+ if not client: |
+ raise gclient_utils.Error('client not configured; see \'gclient config\'') |
+ print client.HookInfo() |
+ return 0 |
+ |
+ |
def Command(name): |
return getattr(sys.modules[__name__], 'CMD' + name, None) |