Chromium Code Reviews| 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 # Files | 7 # Files |
| 8 # .gclient : Current client configuration, written by 'config' command. | 8 # .gclient : Current client configuration, written by 'config' command. |
| 9 # Format is a Python script defining 'solutions', a list whose | 9 # Format is a Python script defining 'solutions', a list whose |
| 10 # entries each are maps binding the strings "name" and "url" | 10 # entries each are maps binding the strings "name" and "url" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 self._deps_parsed = False | 306 self._deps_parsed = False |
| 307 # This dependency has been processed, i.e. checked out | 307 # This dependency has been processed, i.e. checked out |
| 308 self._processed = False | 308 self._processed = False |
| 309 # This dependency had its pre-DEPS hooks run | 309 # This dependency had its pre-DEPS hooks run |
| 310 self._pre_deps_hooks_ran = False | 310 self._pre_deps_hooks_ran = False |
| 311 # This dependency had its hook run | 311 # This dependency had its hook run |
| 312 self._hooks_ran = False | 312 self._hooks_ran = False |
| 313 # This is the scm used to checkout self.url. It may be used by dependencies | 313 # This is the scm used to checkout self.url. It may be used by dependencies |
| 314 # to get the datetime of the revision we checked out. | 314 # to get the datetime of the revision we checked out. |
| 315 self._used_scm = None | 315 self._used_scm = None |
| 316 self._used_revision = None | |
| 316 # The actual revision we ended up getting, or None if that information is | 317 # The actual revision we ended up getting, or None if that information is |
| 317 # unavailable | 318 # unavailable |
| 318 self._got_revision = None | 319 self._got_revision = None |
| 319 | 320 |
| 320 if not self.name and self.parent: | 321 if not self.name and self.parent: |
| 321 raise gclient_utils.Error('Dependency without name') | 322 raise gclient_utils.Error('Dependency without name') |
| 322 | 323 |
| 323 @property | 324 @property |
| 324 def requirements(self): | 325 def requirements(self): |
| 325 """Calculate the list of requirements.""" | 326 """Calculate the list of requirements.""" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 logging.info('ParseDepsFile(%s) done' % self.name) | 596 logging.info('ParseDepsFile(%s) done' % self.name) |
| 596 | 597 |
| 597 def add_dependencies_and_close(self, deps_to_add, hooks): | 598 def add_dependencies_and_close(self, deps_to_add, hooks): |
| 598 """Adds the dependencies, hooks and mark the parsing as done.""" | 599 """Adds the dependencies, hooks and mark the parsing as done.""" |
| 599 for dep in deps_to_add: | 600 for dep in deps_to_add: |
| 600 if dep.verify_validity(): | 601 if dep.verify_validity(): |
| 601 self.add_dependency(dep) | 602 self.add_dependency(dep) |
| 602 self._mark_as_parsed(hooks) | 603 self._mark_as_parsed(hooks) |
| 603 | 604 |
| 604 def maybeGetParentRevision( | 605 def maybeGetParentRevision( |
| 605 self, command, options, parsed_url, parent_name, revision_overrides): | 606 self, command, options, parsed_url, parent): |
|
Ryan Tseng
2014/05/19 22:04:09
nit: This fits on the line above, right?
szager1
2014/05/20 04:41:33
Done.
| |
| 606 """Uses revision/timestamp of parent if no explicit revision was specified. | 607 """Uses revision/timestamp of parent if no explicit revision was specified. |
| 607 | 608 |
| 608 If we are performing an update and --transitive is set, use | 609 If we are performing an update and --transitive is set, use |
| 609 - the parent's revision if 'self.url' is in the same repository | 610 - the parent's revision if 'self.url' is in the same repository |
| 610 - the parent's timestamp otherwise | 611 - the parent's timestamp otherwise |
| 611 to update 'self.url'. The used revision/timestamp will be set in | 612 to update 'self.url'. The used revision/timestamp will be set in |
| 612 'options.revision'. | 613 'options.revision'. |
| 613 If we have an explicit revision do nothing. | 614 If we have an explicit revision do nothing. |
| 614 """ | 615 """ |
| 615 if command == 'update' and options.transitive and not options.revision: | 616 if command == 'update' and options.transitive and not options.revision: |
| 616 _, revision = gclient_utils.SplitUrlRevision(parsed_url) | 617 _, revision = gclient_utils.SplitUrlRevision(parsed_url) |
| 617 if not revision: | 618 if not revision: |
| 618 options.revision = revision_overrides.get(parent_name) | 619 options.revision = getattr(parent, '_used_revision', None) |
| 619 if (options.revision and | 620 if (options.revision and |
| 620 not gclient_utils.IsDateRevision(options.revision)): | 621 not gclient_utils.IsDateRevision(options.revision)): |
| 621 assert self.parent and self.parent.used_scm | 622 assert self.parent and self.parent.used_scm |
| 622 # If this dependency is in the same repository as parent it's url will | 623 # If this dependency is in the same repository as parent it's url will |
| 623 # start with a slash. If so we take the parent revision instead of | 624 # start with a slash. If so we take the parent revision instead of |
| 624 # it's timestamp. | 625 # it's timestamp. |
| 625 # (The timestamps of commits in google code are broken -- which can | 626 # (The timestamps of commits in google code are broken -- which can |
| 626 # result in dependencies to be checked out at the wrong revision) | 627 # result in dependencies to be checked out at the wrong revision) |
| 627 if self.url.startswith('/'): | 628 if self.url.startswith('/'): |
| 628 if options.verbose: | 629 if options.verbose: |
| 629 print('Using parent\'s revision %s since we are in the same ' | 630 print('Using parent\'s revision %s since we are in the same ' |
| 630 'repository.' % options.revision) | 631 'repository.' % options.revision) |
| 631 else: | 632 else: |
| 632 parent_revision_date = self.parent.used_scm.GetRevisionDate( | 633 parent_revision_date = self.parent.used_scm.GetRevisionDate( |
| 633 options.revision) | 634 options.revision) |
| 634 options.revision = gclient_utils.MakeDateRevision( | 635 options.revision = gclient_utils.MakeDateRevision( |
| 635 parent_revision_date) | 636 parent_revision_date) |
| 636 if options.verbose: | 637 if options.verbose: |
| 637 print('Using parent\'s revision date %s since we are in a ' | 638 print('Using parent\'s revision date %s since we are in a ' |
| 638 'different repository.' % options.revision) | 639 'different repository.' % options.revision) |
| 639 revision_overrides[self.name] = options.revision | |
| 640 | 640 |
| 641 # Arguments number differs from overridden method | 641 # Arguments number differs from overridden method |
| 642 # pylint: disable=W0221 | 642 # pylint: disable=W0221 |
| 643 def run(self, revision_overrides, command, args, work_queue, options): | 643 def run(self, revision_overrides, command, args, work_queue, options): |
| 644 """Runs |command| then parse the DEPS file.""" | 644 """Runs |command| then parse the DEPS file.""" |
| 645 logging.info('Dependency(%s).run()' % self.name) | 645 logging.info('Dependency(%s).run()' % self.name) |
| 646 assert self._file_list == [] | 646 assert self._file_list == [] |
| 647 if not self.should_process: | 647 if not self.should_process: |
| 648 return | 648 return |
| 649 # When running runhooks, there's no need to consult the SCM. | 649 # When running runhooks, there's no need to consult the SCM. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 662 self._used_scm = gclient_scm.SVNWrapper( | 662 self._used_scm = gclient_scm.SVNWrapper( |
| 663 parsed_url.GetPath(), self.root.root_dir, self.name, | 663 parsed_url.GetPath(), self.root.root_dir, self.name, |
| 664 out_cb=work_queue.out_cb) | 664 out_cb=work_queue.out_cb) |
| 665 self._used_scm.RunCommand('updatesingle', | 665 self._used_scm.RunCommand('updatesingle', |
| 666 options, args + [parsed_url.GetFilename()], file_list) | 666 options, args + [parsed_url.GetFilename()], file_list) |
| 667 else: | 667 else: |
| 668 # Create a shallow copy to mutate revision. | 668 # Create a shallow copy to mutate revision. |
| 669 options = copy.copy(options) | 669 options = copy.copy(options) |
| 670 options.revision = revision_overrides.get(self.name) | 670 options.revision = revision_overrides.get(self.name) |
| 671 self.maybeGetParentRevision( | 671 self.maybeGetParentRevision( |
| 672 command, options, parsed_url, self.parent.name, revision_overrides) | 672 command, options, parsed_url, self.parent) |
| 673 revision_overrides.pop(self.name, None) | |
|
Ryan Tseng
2014/05/19 22:04:09
nit: Move this to line 670, replace revision_overr
szager1
2014/05/20 04:41:33
Done.
| |
| 674 self._used_revision = options.revision | |
| 673 self._used_scm = gclient_scm.CreateSCM( | 675 self._used_scm = gclient_scm.CreateSCM( |
| 674 parsed_url, self.root.root_dir, self.name, self.outbuf, | 676 parsed_url, self.root.root_dir, self.name, self.outbuf, |
| 675 out_cb=work_queue.out_cb) | 677 out_cb=work_queue.out_cb) |
| 676 self._got_revision = self._used_scm.RunCommand(command, options, args, | 678 self._got_revision = self._used_scm.RunCommand(command, options, args, |
| 677 file_list) | 679 file_list) |
| 678 if file_list: | 680 if file_list: |
| 679 file_list = [os.path.join(self.name, f.strip()) for f in file_list] | 681 file_list = [os.path.join(self.name, f.strip()) for f in file_list] |
| 680 | 682 |
| 681 # TODO(phajdan.jr): We should know exactly when the paths are absolute. | 683 # TODO(phajdan.jr): We should know exactly when the paths are absolute. |
| 682 # Convert all absolute paths to relative. | 684 # Convert all absolute paths to relative. |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1211 elif s.safesync_url: | 1213 elif s.safesync_url: |
| 1212 self._ApplySafeSyncRev(dep=s) | 1214 self._ApplySafeSyncRev(dep=s) |
| 1213 if not self._options.revisions: | 1215 if not self._options.revisions: |
| 1214 return revision_overrides | 1216 return revision_overrides |
| 1215 solutions_names = [s.name for s in self.dependencies] | 1217 solutions_names = [s.name for s in self.dependencies] |
| 1216 index = 0 | 1218 index = 0 |
| 1217 for revision in self._options.revisions: | 1219 for revision in self._options.revisions: |
| 1218 if not '@' in revision: | 1220 if not '@' in revision: |
| 1219 # Support for --revision 123 | 1221 # Support for --revision 123 |
| 1220 revision = '%s@%s' % (solutions_names[index], revision) | 1222 revision = '%s@%s' % (solutions_names[index], revision) |
| 1221 sol, rev = revision.split('@', 1) | 1223 sol, rev = revision.split('@', 1) |
|
Ryan Tseng
2014/05/19 22:04:09
nit: rename this to (name, rev) to make it make it
szager1
2014/05/20 04:41:33
Done.
| |
| 1222 if not sol in solutions_names: | 1224 revision_overrides[sol] = rev |
| 1223 #raise gclient_utils.Error('%s is not a valid solution.' % sol) | |
| 1224 print >> sys.stderr, ('Please fix your script, having invalid ' | |
| 1225 '--revision flags will soon considered an error.') | |
| 1226 else: | |
| 1227 revision_overrides[sol] = rev | |
| 1228 index += 1 | 1225 index += 1 |
| 1229 return revision_overrides | 1226 return revision_overrides |
| 1230 | 1227 |
| 1231 def _ApplySafeSyncRev(self, dep): | 1228 def _ApplySafeSyncRev(self, dep): |
| 1232 """Finds a valid revision from the content of the safesync_url and apply it | 1229 """Finds a valid revision from the content of the safesync_url and apply it |
| 1233 by appending revisions to the revision list. Throws if revision appears to | 1230 by appending revisions to the revision list. Throws if revision appears to |
| 1234 be invalid for the given |dep|.""" | 1231 be invalid for the given |dep|.""" |
| 1235 assert len(dep.safesync_url) > 0 | 1232 assert len(dep.safesync_url) > 0 |
| 1236 handle = urllib.urlopen(dep.safesync_url) | 1233 handle = urllib.urlopen(dep.safesync_url) |
| 1237 rev = handle.read().strip() | 1234 rev = handle.read().strip() |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 if command in ('update', 'revert'): | 1268 if command in ('update', 'revert'): |
| 1272 pm = Progress('Syncing projects', 1) | 1269 pm = Progress('Syncing projects', 1) |
| 1273 elif command == 'recurse': | 1270 elif command == 'recurse': |
| 1274 pm = Progress(' '.join(args), 1) | 1271 pm = Progress(' '.join(args), 1) |
| 1275 work_queue = gclient_utils.ExecutionQueue( | 1272 work_queue = gclient_utils.ExecutionQueue( |
| 1276 self._options.jobs, pm, ignore_requirements=ignore_requirements, | 1273 self._options.jobs, pm, ignore_requirements=ignore_requirements, |
| 1277 verbose=self._options.verbose) | 1274 verbose=self._options.verbose) |
| 1278 for s in self.dependencies: | 1275 for s in self.dependencies: |
| 1279 work_queue.enqueue(s) | 1276 work_queue.enqueue(s) |
| 1280 work_queue.flush(revision_overrides, command, args, options=self._options) | 1277 work_queue.flush(revision_overrides, command, args, options=self._options) |
| 1278 if revision_overrides: | |
| 1279 print >> sys.stderr, ('Please fix your script, having invalid ' | |
| 1280 '--revision flags will soon considered an error.') | |
| 1281 | 1281 |
| 1282 # Once all the dependencies have been processed, it's now safe to run the | 1282 # Once all the dependencies have been processed, it's now safe to run the |
| 1283 # hooks. | 1283 # hooks. |
| 1284 if not self._options.nohooks: | 1284 if not self._options.nohooks: |
| 1285 self.RunHooksRecursively(self._options) | 1285 self.RunHooksRecursively(self._options) |
| 1286 | 1286 |
| 1287 if command == 'update': | 1287 if command == 'update': |
| 1288 # Notify the user if there is an orphaned entry in their working copy. | 1288 # Notify the user if there is an orphaned entry in their working copy. |
| 1289 # Only delete the directory if there are no changes in it, and | 1289 # Only delete the directory if there are no changes in it, and |
| 1290 # delete_unversioned_trees is set to true. | 1290 # delete_unversioned_trees is set to true. |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1985 print >> sys.stderr, 'Error: %s' % str(e) | 1985 print >> sys.stderr, 'Error: %s' % str(e) |
| 1986 return 1 | 1986 return 1 |
| 1987 finally: | 1987 finally: |
| 1988 gclient_utils.PrintWarnings() | 1988 gclient_utils.PrintWarnings() |
| 1989 | 1989 |
| 1990 | 1990 |
| 1991 if '__main__' == __name__: | 1991 if '__main__' == __name__: |
| 1992 sys.exit(Main(sys.argv[1:])) | 1992 sys.exit(Main(sys.argv[1:])) |
| 1993 | 1993 |
| 1994 # vim: ts=2:sw=2:tw=80:et: | 1994 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |