OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
7 | 7 |
8 Files | 8 Files |
9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 for s in self.dependencies: | 578 for s in self.dependencies: |
579 work_queue.enqueue(s) | 579 work_queue.enqueue(s) |
580 | 580 |
581 @gclient_utils.lockedmethod | 581 @gclient_utils.lockedmethod |
582 def _run_is_done(self, file_list, parsed_url): | 582 def _run_is_done(self, file_list, parsed_url): |
583 # Both these are kept for hooks that are run as a separate tree traversal. | 583 # Both these are kept for hooks that are run as a separate tree traversal. |
584 self._file_list = file_list | 584 self._file_list = file_list |
585 self._parsed_url = parsed_url | 585 self._parsed_url = parsed_url |
586 self._processed = True | 586 self._processed = True |
587 | 587 |
588 def RunHooksRecursively(self, options): | 588 def RunHooksRecursively(self, options, action=None): |
589 """Evaluates all hooks, running actions as needed. run() | 589 """Evaluates all hooks, running actions as needed. run() |
M-A Ruel
2012/01/30 19:23:07
... running |action| for each hook. or something l
szager
2012/01/31 00:22:20
Done.
| |
590 must have been called before to load the DEPS.""" | 590 must have been called before to load the DEPS.""" |
591 assert self.hooks_ran == False | 591 assert self.hooks_ran == False |
592 if not action: | |
M-A Ruel
2012/01/30 19:23:07
action = action or self._RunHookAction
szager
2012/01/31 00:22:20
Done.
| |
593 action = self._RunHookAction | |
592 if not self.should_process or not self.recursion_limit: | 594 if not self.should_process or not self.recursion_limit: |
593 # Don't run the hook when it is above recursion_limit. | 595 # Don't run the hook when it is above recursion_limit. |
594 return | 596 return |
595 # If "--force" was specified, run all hooks regardless of what files have | 597 # If "--force" was specified, run all hooks regardless of what files have |
596 # changed. | 598 # changed. |
597 if self.deps_hooks: | 599 if self.deps_hooks: |
598 # TODO(maruel): If the user is using git or git-svn, then we don't know | 600 # TODO(maruel): If the user is using git or git-svn, then we don't know |
599 # what files have changed so we always run all hooks. It'd be nice to fix | 601 # what files have changed so we always run all hooks. It'd be nice to fix |
600 # that. | 602 # that. |
601 if (options.force or | 603 if (options.force or |
602 isinstance(self.parsed_url, self.FileImpl) or | 604 isinstance(self.parsed_url, self.FileImpl) or |
603 gclient_scm.GetScmName(self.parsed_url) in ('git', None) or | 605 gclient_scm.GetScmName(self.parsed_url) in ('git', None) or |
604 os.path.isdir(os.path.join(self.root.root_dir, self.name, '.git'))): | 606 os.path.isdir(os.path.join(self.root.root_dir, self.name, '.git'))): |
605 for hook_dict in self.deps_hooks: | 607 for hook_dict in self.deps_hooks: |
606 self._RunHookAction(hook_dict, []) | 608 action(hook_dict, []) |
607 else: | 609 else: |
608 # Run hooks on the basis of whether the files from the gclient operation | 610 # Run hooks on the basis of whether the files from the gclient operation |
609 # match each hook's pattern. | 611 # match each hook's pattern. |
610 for hook_dict in self.deps_hooks: | 612 for hook_dict in self.deps_hooks: |
611 pattern = re.compile(hook_dict['pattern']) | 613 pattern = re.compile(hook_dict['pattern']) |
612 matching_file_list = [ | 614 matching_file_list = [ |
613 f for f in self.file_list_and_children if pattern.search(f) | 615 f for f in self.file_list_and_children if pattern.search(f) |
614 ] | 616 ] |
615 if matching_file_list: | 617 if matching_file_list: |
616 self._RunHookAction(hook_dict, matching_file_list) | 618 action(hook_dict, matching_file_list) |
617 for s in self.dependencies: | 619 for s in self.dependencies: |
618 s.RunHooksRecursively(options) | 620 s.RunHooksRecursively(options, action=action) |
M-A Ruel
2012/01/30 19:23:07
My idea was to still call _RunHookAtion but add an
szager
2012/01/31 00:22:20
OK. Patch is now much bigger...
| |
619 | 621 |
620 def _RunHookAction(self, hook_dict, matching_file_list): | 622 def _RunHookAction(self, hook_dict, matching_file_list): |
621 """Runs the action from a single hook.""" | 623 """Runs the action from a single hook.""" |
622 # A single DEPS file can specify multiple hooks so this function can be | 624 # A single DEPS file can specify multiple hooks so this function can be |
623 # called multiple times on a single Dependency. | 625 # called multiple times on a single Dependency. |
624 #assert self.hooks_ran == False | 626 #assert self.hooks_ran == False |
625 self._hooks_ran = True | 627 self._hooks_ran = True |
626 logging.debug(hook_dict) | 628 logging.debug(hook_dict) |
627 logging.debug(matching_file_list) | 629 logging.debug(matching_file_list) |
628 command = hook_dict['action'][:] | 630 command = hook_dict['action'][:] |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 for d in self.root.subtree(False): | 1075 for d in self.root.subtree(False): |
1074 if self._options.actual: | 1076 if self._options.actual: |
1075 entries[d.name] = GetURLAndRev(d) | 1077 entries[d.name] = GetURLAndRev(d) |
1076 else: | 1078 else: |
1077 entries[d.name] = d.parsed_url | 1079 entries[d.name] = d.parsed_url |
1078 keys = sorted(entries.keys()) | 1080 keys = sorted(entries.keys()) |
1079 for x in keys: | 1081 for x in keys: |
1080 print('%s: %s' % (x, entries[x])) | 1082 print('%s: %s' % (x, entries[x])) |
1081 logging.info(str(self)) | 1083 logging.info(str(self)) |
1082 | 1084 |
1085 def HookInfo(self): | |
1086 work_queue = gclient_utils.ExecutionQueue(self._options.jobs, None) | |
1087 for s in self.dependencies: | |
1088 work_queue.enqueue(s) | |
1089 work_queue.flush({}, None, [], options=self._options) | |
1090 hooks = [] | |
1091 def _process_hook(hook_dict, matching_file_list): | |
1092 command = hook_dict['action'][:] | |
1093 if '$matching_files' in command: | |
1094 splice_index = command.index('$matching_files') | |
1095 command[splice_index:splice_index + 1] = matching_file_list | |
1096 hooks.append(command) | |
1097 self.RunHooksRecursively(self._options, action=_process_hook) | |
1098 return hooks | |
1099 | |
1083 def ParseDepsFile(self): | 1100 def ParseDepsFile(self): |
1084 """No DEPS to parse for a .gclient file.""" | 1101 """No DEPS to parse for a .gclient file.""" |
1085 raise gclient_utils.Error('Internal error') | 1102 raise gclient_utils.Error('Internal error') |
1086 | 1103 |
1087 @property | 1104 @property |
1088 def root_dir(self): | 1105 def root_dir(self): |
1089 """Root directory of gclient checkout.""" | 1106 """Root directory of gclient checkout.""" |
1090 return self._root_dir | 1107 return self._root_dir |
1091 | 1108 |
1092 @property | 1109 @property |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1416 'version of all repositories to reproduce the tree, ' | 1433 'version of all repositories to reproduce the tree, ' |
1417 'implies -a') | 1434 'implies -a') |
1418 (options, args) = parser.parse_args(args) | 1435 (options, args) = parser.parse_args(args) |
1419 client = GClient.LoadCurrentConfig(options) | 1436 client = GClient.LoadCurrentConfig(options) |
1420 if not client: | 1437 if not client: |
1421 raise gclient_utils.Error('client not configured; see \'gclient config\'') | 1438 raise gclient_utils.Error('client not configured; see \'gclient config\'') |
1422 client.PrintRevInfo() | 1439 client.PrintRevInfo() |
1423 return 0 | 1440 return 0 |
1424 | 1441 |
1425 | 1442 |
1443 def CMDhookinfo(parser, args): | |
1444 """Output the hooks that would be run by `gclient runhooks`""" | |
1445 | |
1446 (options, args) = parser.parse_args(args) | |
1447 client = GClient.LoadCurrentConfig(options) | |
1448 if not client: | |
1449 raise gclient_utils.Error('client not configured; see \'gclient config\'') | |
1450 print client.HookInfo() | |
1451 return 0 | |
1452 | |
1453 | |
1426 def Command(name): | 1454 def Command(name): |
1427 return getattr(sys.modules[__name__], 'CMD' + name, None) | 1455 return getattr(sys.modules[__name__], 'CMD' + name, None) |
1428 | 1456 |
1429 | 1457 |
1430 def CMDhelp(parser, args): | 1458 def CMDhelp(parser, args): |
1431 """Prints list of commands or help for a specific command.""" | 1459 """Prints list of commands or help for a specific command.""" |
1432 (_, args) = parser.parse_args(args) | 1460 (_, args) = parser.parse_args(args) |
1433 if len(args) == 1: | 1461 if len(args) == 1: |
1434 return Main(args + ['--help']) | 1462 return Main(args + ['--help']) |
1435 parser.print_help() | 1463 parser.print_help() |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1532 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1560 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
1533 print >> sys.stderr, 'Error: %s' % str(e) | 1561 print >> sys.stderr, 'Error: %s' % str(e) |
1534 return 1 | 1562 return 1 |
1535 | 1563 |
1536 | 1564 |
1537 if '__main__' == __name__: | 1565 if '__main__' == __name__: |
1538 fix_encoding.fix_encoding() | 1566 fix_encoding.fix_encoding() |
1539 sys.exit(Main(sys.argv[1:])) | 1567 sys.exit(Main(sys.argv[1:])) |
1540 | 1568 |
1541 # vim: ts=2:sw=2:tw=80:et: | 1569 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |