Index: gclient.py |
diff --git a/gclient.py b/gclient.py |
index 749003fa8d59271146e61a8ac00b5c3a933434d5..14c71170979a34921bda02f1f92e6c1b7a6315cf 100755 |
--- a/gclient.py |
+++ b/gclient.py |
@@ -286,6 +286,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): |
# This is in both .gclient and DEPS files: |
self._deps_hooks = [] |
+ self._pre_deps_hooks = [] |
+ |
# Calculates properties: |
self._parsed_url = None |
self._dependencies = [] |
@@ -297,6 +299,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): |
self._deps_parsed = False |
# This dependency has been processed, i.e. checked out |
self._processed = False |
+ # This dependency had its pre-DEPS hooks run |
+ self._pre_deps_hooks_ran = False |
# This dependency had its hook run |
self._hooks_ran = False |
# This is the scm used to checkout self.url. It may be used by dependencies |
@@ -548,6 +552,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): |
if 'action' in hook: |
hooks_to_run.append(hook) |
+ self._pre_deps_hooks = [self.GetHookAction(hook, []) for hook in |
+ local_scope.get('pre_deps_hooks', [])] |
+ |
self.add_dependencies_and_close(deps_to_add, hooks_to_run) |
logging.info('ParseDepsFile(%s) done' % self.name) |
@@ -648,8 +655,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): |
# Always parse the DEPS file. |
self.ParseDepsFile() |
- |
self._run_is_done(file_list or [], parsed_url) |
+ if not options.nohooks: |
+ self.RunPreDepsHooks() |
iannucci
2013/10/07 22:40:09
So, the bots generally run with --nohooks. If we w
borenet
2013/10/08 13:53:19
This sounds fine to me, if adding another flag is
|
if self.recursion_limit: |
# Parse the dependencies of this dependency. |
@@ -791,6 +799,32 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): |
print "Hook '%s' took %.2f secs" % ( |
gclient_utils.CommandToStr(hook), elapsed_time) |
+ def RunPreDepsHooks(self): |
+ assert self.processed |
+ assert self.deps_parsed |
+ assert not self.pre_deps_hooks_ran |
+ assert not self.hooks_ran |
+ for s in self.dependencies: |
+ assert not s.processed |
+ self._pre_deps_hooks_ran = True |
+ for hook in self.pre_deps_hooks: |
+ try: |
+ start_time = time.time() |
+ 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) |
+ finally: |
+ elapsed_time = time.time() - start_time |
+ if elapsed_time > 10: |
+ print "Hook '%s' took %.2f secs" % ( |
+ gclient_utils.CommandToStr(hook), elapsed_time) |
+ |
+ |
def subtree(self, include_all): |
"""Breadth first recursion excluding root node.""" |
dependencies = self.dependencies |
@@ -830,6 +864,11 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): |
@property |
@gclient_utils.lockedmethod |
+ def pre_deps_hooks(self): |
+ return tuple(self._pre_deps_hooks) |
+ |
+ @property |
+ @gclient_utils.lockedmethod |
def parsed_url(self): |
return self._parsed_url |
@@ -846,6 +885,11 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): |
@property |
@gclient_utils.lockedmethod |
+ def pre_deps_hooks_ran(self): |
+ return self._pre_deps_hooks_ran |
+ |
+ @property |
+ @gclient_utils.lockedmethod |
def hooks_ran(self): |
return self._hooks_ran |