Chromium Code Reviews| Index: gclient.py |
| =================================================================== |
| --- gclient.py (revision 126259) |
| +++ gclient.py (working copy) |
| @@ -604,13 +604,31 @@ |
| 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) |
| + 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): |
| + """Evaluate all hooks, and return them in a flat list. |
| + |
| + run() must have been called before to load the DEPS. |
| + """ |
| + result = [] |
| if not self.should_process or not self.recursion_limit: |
| # Don't run the hook when it is above recursion_limit. |
| - return |
| + return result |
| # If "--force" was specified, run all hooks regardless of what files have |
| # changed. |
| if self.deps_hooks: |
| @@ -622,7 +640,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. |
| @@ -632,39 +650,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) |
| + result.extend(s.GetHooks(options)) |
| + 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 |
| @@ -1454,6 +1458,21 @@ |
| return 0 |
| +def CMDhookinfo(parser, args): |
| + """Output the hooks that would be run by `gclient runhooks`""" |
| + (options, args) = parser.parse_args(args) |
| + options.force = True |
| + 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) |
|
M-A Ruel
2012/03/12 23:52:06
I'd prefer you to use RunOnDeps(None, [])
szager
2012/03/13 00:00:18
Done.
|
| + for s in client.dependencies: |
| + work_queue.enqueue(s) |
| + work_queue.flush({}, None, [], options=options) |
| + print '; '.join([' '.join(hook) for hook in client.GetHooks(options)]) |
|
M-A Ruel
2012/03/12 23:52:06
print '; '.join(' '.join(hook) for hook in client.
szager
2012/03/13 00:00:18
Done.
|
| + return 0 |
| + |
| + |
| def Command(name): |
| return getattr(sys.modules[__name__], 'CMD' + name, None) |