Commit ecf53fec authored by Paweł Hajdan, Jr's avatar Paweł Hajdan, Jr Committed by Commit Bot

gclient flatten: emit conditions for hooks

Bug: 661382
Change-Id: I0e74273a5e00b4f3cf1d5c22ce0944dc2fa6f31e
Reviewed-on: https://chromium-review.googlesource.com/692934Reviewed-by: 's avatarMichael Moss <mmoss@chromium.org>
Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
parent 355b7041
...@@ -181,6 +181,10 @@ class Hook(object): ...@@ -181,6 +181,10 @@ class Hook(object):
def name(self): def name(self):
return self._name return self._name
@property
def condition(self):
return self._condition
def matches(self, file_list): def matches(self, file_list):
"""Returns true if the pattern matches any of files in the list.""" """Returns true if the pattern matches any of files in the list."""
if not self._pattern: if not self._pattern:
...@@ -2042,6 +2046,8 @@ def _HooksToLines(name, hooks): ...@@ -2042,6 +2046,8 @@ def _HooksToLines(name, hooks):
s.append(' "name": "%s",' % hook.name) s.append(' "name": "%s",' % hook.name)
if hook.pattern is not None: if hook.pattern is not None:
s.append(' "pattern": "%s",' % hook.pattern) s.append(' "pattern": "%s",' % hook.pattern)
if hook.condition is not None:
s.append(' "condition": "%s",' % hook.condition)
s.extend( s.extend(
# Hooks run in the parent directory of their dep. # Hooks run in the parent directory of their dep.
[' "cwd": "%s",' % os.path.normpath(os.path.dirname(dep.name))] + [' "cwd": "%s",' % os.path.normpath(os.path.dirname(dep.name))] +
...@@ -2069,6 +2075,8 @@ def _HooksOsToLines(hooks_os): ...@@ -2069,6 +2075,8 @@ def _HooksOsToLines(hooks_os):
s.append(' "name": "%s",' % hook.name) s.append(' "name": "%s",' % hook.name)
if hook.pattern is not None: if hook.pattern is not None:
s.append(' "pattern": "%s",' % hook.pattern) s.append(' "pattern": "%s",' % hook.pattern)
if hook.condition is not None:
s.append(' "condition": "%s",' % hook.condition)
s.extend( s.extend(
# Hooks run in the parent directory of their dep. # Hooks run in the parent directory of their dep.
[' "cwd": "%s",' % os.path.normpath(os.path.dirname(dep.name))] + [' "cwd": "%s",' % os.path.normpath(os.path.dirname(dep.name))] +
......
...@@ -518,6 +518,7 @@ deps_os ={ ...@@ -518,6 +518,7 @@ deps_os ={
hooks = [ hooks = [
{ {
'pattern': '.', 'pattern': '.',
'condition': 'True',
'action': ['python', '-c', 'action': ['python', '-c',
'open(\\'src/git_hooked1\\', \\'w\\').write(\\'{hook1_contents}\\')'], 'open(\\'src/git_hooked1\\', \\'w\\').write(\\'{hook1_contents}\\')'],
}, },
......
...@@ -703,6 +703,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -703,6 +703,7 @@ class GClientSmokeGIT(GClientSmokeBase):
' # src', ' # src',
' {', ' {',
' "pattern": ".",', ' "pattern": ".",',
' "condition": "True",',
' "cwd": ".",', ' "cwd": ".",',
' "action": [', ' "action": [',
' "python",', ' "python",',
...@@ -867,6 +868,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -867,6 +868,7 @@ class GClientSmokeGIT(GClientSmokeBase):
' # src', ' # src',
' {', ' {',
' "pattern": ".",', ' "pattern": ".",',
' "condition": "True",',
' "cwd": ".",', ' "cwd": ".",',
' "action": [', ' "action": [',
' "python",', ' "python",',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment