Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: gclient.py

Issue 9232068: Added `gclient hookinfo`. This will be used to convert hooks into (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/gclient_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient.py
===================================================================
--- gclient.py (revision 126269)
+++ 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):
+ """Turns 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):
+ """Evaluates all hooks, and return them in a flat list.
+
+ RunOnDeps() 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,18 @@
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\'')
+ client.RunOnDeps(None, [])
+ print '; '.join(' '.join(hook) for hook in client.GetHooks(options))
+ return 0
+
+
def Command(name):
return getattr(sys.modules[__name__], 'CMD' + name, None)
« no previous file with comments | « no previous file | tests/gclient_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698