diff --git a/gclient.py b/gclient.py index 1270e03e6..e083437bf 100755 --- a/gclient.py +++ b/gclient.py @@ -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: diff --git a/gclient_eval.py b/gclient_eval.py index 889eaeece..3154e27b5 100644 --- a/gclient_eval.py +++ b/gclient_eval.py @@ -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], diff --git a/tests/gclient_test.py b/tests/gclient_test.py index 9b1b3a2f1..0b0e6c0da 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -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