Commit c4826742 authored by Scott Graham's avatar Scott Graham Committed by Commit Bot

Add support for hooks_os in .gclient

This adds support for 'hooks_os' in .gclient which runs the given hooks
only when the associated os is specifed in target_os.

Bug: 706592
Change-Id: If70e51e0e784f8a8c6e45b33f59605b883a16f6e
Reviewed-on: https://chromium-review.googlesource.com/503534Reviewed-by: 's avatarPaweł Hajdan Jr. <phajdan.jr@chromium.org>
Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
parent 2c199e1e
......@@ -64,7 +64,7 @@
# Specifying a target OS
# An optional key named "target_os" may be added to a gclient file to specify
# one or more additional operating systems that should be considered when
# processing the deps_os dict of a DEPS file.
# processing the deps_os/hooks_os dict of a DEPS file.
#
# Example:
# target_os = [ "android" ]
......@@ -711,6 +711,12 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
for hook in local_scope.get('hooks', []):
if hook.get('name', '') not in hook_names_to_suppress:
hooks_to_run.append(hook)
if 'hooks_os' in local_scope and target_os_list:
hooks_os = local_scope['hooks_os']
# Specifically append these to ensure that hooks_os run after hooks.
for the_target_os in target_os_list:
the_target_os_hooks = hooks_os.get(the_target_os, [])
hooks_to_run.extend(the_target_os_hooks)
# add the replacements and any additions
for hook in self.custom_hooks:
......
......@@ -47,6 +47,9 @@ _GCLIENT_SCHEMA = schema.Schema({
# Also see 'pre_deps_hooks'.
schema.Optional('hooks'): _GCLIENT_HOOKS_SCHEMA,
# Similar to 'hooks', also keyed by OS.
schema.Optional('hooks_os'): {basestring: _GCLIENT_HOOKS_SCHEMA},
# Rules which #includes are allowed in the directory.
# Also see 'skip_child_includes' and 'specific_include_rules'.
schema.Optional('include_rules'): [basestring],
......
......@@ -482,6 +482,69 @@ class GclientTest(trial_dir.TestCase):
],
sorted(self._get_processed()))
def testTargetOsForHooksInDepsFile(self):
"""Verifies that specifying a target_os value in a DEPS file runs the right
entries in hooks_os.
"""
write(
'DEPS',
'hooks = [\n'
' {\n'
' "name": "a",\n'
' "pattern": ".",\n'
' "action": [ "python", "do_a" ],\n'
' },\n'
']\n'
'\n'
'hooks_os = {\n'
' "blorp": ['
' {\n'
' "name": "b",\n'
' "pattern": ".",\n'
' "action": [ "python", "do_b" ],\n'
' },\n'
' ],\n'
'}\n')
write(
'.gclient',
'solutions = [\n'
' { "name": ".",\n'
' "url": "svn://example.com/",\n'
' }]\n')
# Test for an OS not in hooks_os.
parser = gclient.OptionParser()
options, args = parser.parse_args(['--jobs', '1'])
options.deps_os = 'zippy'
obj = gclient.GClient.LoadCurrentConfig(options)
obj.RunOnDeps('None', args)
self.assertEqual(['zippy'], sorted(obj.enforced_os))
all_hooks = obj.GetHooks(options)
self.assertEquals(
[('.', 'svn://example.com/'),],
sorted(self._get_processed()))
self.assertEquals(all_hooks,
[['/usr/bin/python', 'do_a']])
# Test for OS that has extra hooks in hooks_os.
parser = gclient.OptionParser()
options, args = parser.parse_args(['--jobs', '1'])
options.deps_os = 'blorp'
obj = gclient.GClient.LoadCurrentConfig(options)
obj.RunOnDeps('None', args)
self.assertEqual(['blorp'], sorted(obj.enforced_os))
all_hooks = obj.GetHooks(options)
self.assertEquals(
[('.', 'svn://example.com/'),],
sorted(self._get_processed()))
self.assertEquals(all_hooks,
[['/usr/bin/python', 'do_a'],
['/usr/bin/python', 'do_b']])
def testUpdateWithOsDeps(self):
"""Verifies that complicated deps_os constructs result in the
correct data also with multple operating systems. Also see
......
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