Index: gclient.py |
=================================================================== |
--- gclient.py (revision 119777) |
+++ gclient.py (working copy) |
@@ -585,10 +585,28 @@ |
self._parsed_url = parsed_url |
self._processed = True |
- def RunHooksRecursively(self, options): |
- """Evaluates all hooks, running actions as needed. run() |
- must have been called before to load the DEPS.""" |
- assert self.hooks_ran == False |
+ @staticmethod |
+ def GetHookAction(hook_dict, matching_file_list): |
+ """Turn a parsed 'hook' dict into an executable command.""" |
+ logging.debug(hook_dict) |
M-A Ruel
2012/01/31 01:15:25
FTR, you'll have to remove these before committing
szager
2012/01/31 06:47:39
I don't mind removing them (done), but why? These
M-A Ruel
2012/01/31 15:18:33
I'm stupid. You can add these back.
|
+ logging.debug(matching_file_list) |
+ command = hook_dict['action'][:] |
+ if command[0] == 'python': |
+ # If the hook specified "python" as the first item, the action is a |
+ # Python script. Run it by starting a new copy of the same |
+ # interpreter. |
+ command[0] = sys.executable |
+ if '$matching_files' in command: |
+ splice_index = command.index('$matching_files') |
+ command[splice_index:splice_index + 1] = matching_file_list |
+ return command |
+ |
+ def GetHooks(self, options, result=None): |
M-A Ruel
2012/01/31 01:15:25
I think it'd be simpler if you simply returned the
szager
2012/01/31 06:47:39
Done.
|
+ """Evaluate all hooks, and return them in a flat list. |
+ |
+ run() must have been called before to load the DEPS. |
+ """ |
+ result = [] if result is None else result |
M-A Ruel
2012/01/31 01:15:25
result = result or []
?
szager
2012/01/31 06:47:39
Obsolete now.
|
if not self.should_process or not self.recursion_limit: |
# Don't run the hook when it is above recursion_limit. |
return |
@@ -603,7 +621,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, []) |
+ result.append(self.GetHookAction(hook_dict, [])) |
else: |
# Run hooks on the basis of whether the files from the gclient operation |
# match each hook's pattern. |
@@ -613,39 +631,25 @@ |
f for f in self.file_list_and_children if pattern.search(f) |
] |
if matching_file_list: |
- self._RunHookAction(hook_dict, matching_file_list) |
+ result.append(self.GetHookAction(hook_dict, matching_file_list)) |
for s in self.dependencies: |
- s.RunHooksRecursively(options) |
+ s.GetHooks(options, result) |
+ return result |
- def _RunHookAction(self, hook_dict, matching_file_list): |
- """Runs the action from a single hook.""" |
- # A single DEPS file can specify multiple hooks so this function can be |
- # called multiple times on a single Dependency. |
- #assert self.hooks_ran == False |
+ def RunHooksRecursively(self, options): |
+ assert self.hooks_ran == False |
self._hooks_ran = True |
- logging.debug(hook_dict) |
- logging.debug(matching_file_list) |
- command = hook_dict['action'][:] |
- if command[0] == 'python': |
- # If the hook specified "python" as the first item, the action is a |
- # Python script. Run it by starting a new copy of the same |
- # interpreter. |
- command[0] = sys.executable |
+ for hook in self.GetHooks(options): |
+ try: |
+ gclient_utils.CheckCallAndFilterAndHeader( |
+ hook, cwd=self.root.root_dir, always=True) |
+ except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
+ # 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 |
+ # differently from VC failures. |
+ print >> sys.stderr, 'Error: %s' % str(e) |
+ sys.exit(2) |
- if '$matching_files' in command: |
- splice_index = command.index('$matching_files') |
- command[splice_index:splice_index + 1] = matching_file_list |
- |
- try: |
- gclient_utils.CheckCallAndFilterAndHeader( |
- command, cwd=self.root.root_dir, always=True) |
- except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
- # 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 |
- # differently from VC failures. |
- print >> sys.stderr, 'Error: %s' % str(e) |
- sys.exit(2) |
- |
def subtree(self, include_all): |
"""Breadth first recursion excluding root node.""" |
dependencies = self.dependencies |
@@ -1423,6 +1427,20 @@ |
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\'') |
+ work_queue = gclient_utils.ExecutionQueue(options.jobs, None) |
+ for s in client.dependencies: |
+ work_queue.enqueue(s) |
+ work_queue.flush({}, None, [], options=options) |
+ print client.GetHooks(options) |
M-A Ruel
2012/01/31 01:15:25
for hook in client.GetHooks(options):
print ' '.
szager
2012/01/31 06:47:39
I'd like the output to be parse-able by python, so
|
+ return 0 |
+ |
+ |
def Command(name): |
return getattr(sys.modules[__name__], 'CMD' + name, None) |