OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 (self.FromImpl, self.FileImpl, None.__class__)): | 172 (self.FromImpl, self.FileImpl, None.__class__)): |
173 raise gclient_utils.Error( | 173 raise gclient_utils.Error( |
174 ('dependency url must be either a string, None, ' | 174 ('dependency url must be either a string, None, ' |
175 'File() or From() instead of %s') % self._url.__class__.__name__) | 175 'File() or From() instead of %s') % self._url.__class__.__name__) |
176 if '/' in self._deps_file or '\\' in self._deps_file: | 176 if '/' in self._deps_file or '\\' in self._deps_file: |
177 raise gclient_utils.Error('deps_file name must not be a path, just a ' | 177 raise gclient_utils.Error('deps_file name must not be a path, just a ' |
178 'filename. %s' % self._deps_file) | 178 'filename. %s' % self._deps_file) |
179 | 179 |
180 @property | 180 @property |
181 def deps_file(self): | 181 def deps_file(self): |
182 """Immutable so no need to lock.""" | |
183 return self._deps_file | 182 return self._deps_file |
184 | 183 |
185 @property | 184 @property |
186 def managed(self): | 185 def managed(self): |
187 """Immutable so no need to lock.""" | |
188 return self._managed | 186 return self._managed |
189 | 187 |
190 @property | 188 @property |
191 def parent(self): | 189 def parent(self): |
192 """Immutable so no need to lock.""" | |
193 return self._parent | 190 return self._parent |
194 | 191 |
195 @property | 192 @property |
| 193 def root(self): |
| 194 """Returns the root node, a GClient object.""" |
| 195 if not self.parent: |
| 196 # This line is to signal pylint that it could be a GClient instance. |
| 197 return self or GClient(None, None) |
| 198 return self.parent.root |
| 199 |
| 200 @property |
196 def safesync_url(self): | 201 def safesync_url(self): |
197 """Immutable so no need to lock.""" | |
198 return self._safesync_url | 202 return self._safesync_url |
199 | 203 |
200 @property | 204 @property |
201 def should_process(self): | 205 def should_process(self): |
202 """True if this dependency should be processed, i.e. checked out.""" | 206 """True if this dependency should be processed, i.e. checked out.""" |
203 return self._should_process | 207 return self._should_process |
204 | 208 |
205 @property | 209 @property |
206 def custom_vars(self): | 210 def custom_vars(self): |
207 """Immutable so no need to lock.""" | |
208 return self._custom_vars.copy() | 211 return self._custom_vars.copy() |
209 | 212 |
210 @property | 213 @property |
211 def custom_deps(self): | 214 def custom_deps(self): |
212 """Immutable so no need to lock.""" | |
213 return self._custom_deps.copy() | 215 return self._custom_deps.copy() |
214 | 216 |
215 @property | 217 @property |
216 def url(self): | 218 def url(self): |
217 return self._url | 219 return self._url |
218 | 220 |
| 221 @property |
| 222 def recursion_limit(self): |
| 223 """Returns > 0 if this dependency is not too recursed to be processed.""" |
| 224 return max(self.parent.recursion_limit - 1, 0) |
| 225 |
| 226 def get_custom_deps(self, name, url): |
| 227 """Returns a custom deps if applicable.""" |
| 228 if self.parent: |
| 229 url = self.parent.get_custom_deps(name, url) |
| 230 # None is a valid return value to disable a dependency. |
| 231 return self.custom_deps.get(name, url) |
| 232 |
219 | 233 |
220 class Dependency(gclient_utils.WorkItem, DependencySettings): | 234 class Dependency(gclient_utils.WorkItem, DependencySettings): |
221 """Object that represents a dependency checkout.""" | 235 """Object that represents a dependency checkout.""" |
222 | 236 |
223 def __init__(self, parent, name, url, safesync_url, managed, custom_deps, | 237 def __init__(self, parent, name, url, safesync_url, managed, custom_deps, |
224 custom_vars, deps_file, should_process): | 238 custom_vars, deps_file, should_process): |
225 gclient_utils.WorkItem.__init__(self, name) | 239 gclient_utils.WorkItem.__init__(self, name) |
226 DependencySettings.__init__( | 240 DependencySettings.__init__( |
227 self, parent, url, safesync_url, managed, custom_deps, custom_vars, | 241 self, parent, url, safesync_url, managed, custom_deps, custom_vars, |
228 deps_file, should_process) | 242 deps_file, should_process) |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 yield i | 626 yield i |
613 | 627 |
614 def depth_first_tree(self): | 628 def depth_first_tree(self): |
615 """Depth-first recursion including the root node.""" | 629 """Depth-first recursion including the root node.""" |
616 yield self | 630 yield self |
617 for i in self.dependencies: | 631 for i in self.dependencies: |
618 for j in i.depth_first_tree(): | 632 for j in i.depth_first_tree(): |
619 if j.should_process: | 633 if j.should_process: |
620 yield j | 634 yield j |
621 | 635 |
622 def get_custom_deps(self, name, url): | |
623 """Returns a custom deps if applicable.""" | |
624 if self.parent: | |
625 url = self.parent.get_custom_deps(name, url) | |
626 # None is a valid return value to disable a dependency. | |
627 return self.custom_deps.get(name, url) | |
628 | |
629 @property | |
630 def recursion_limit(self): | |
631 """Returns > 0 if this dependency is not too recursed to be processed. | |
632 | |
633 Immutable so no need to lock. | |
634 """ | |
635 return max(self.parent.recursion_limit - 1, 0) | |
636 | |
637 @property | 636 @property |
638 def dependencies(self): | 637 def dependencies(self): |
639 return tuple(self._dependencies) | 638 return tuple(self._dependencies) |
640 | 639 |
641 @property | 640 @property |
642 def deps_hooks(self): | 641 def deps_hooks(self): |
643 return tuple(self._deps_hooks) | 642 return tuple(self._deps_hooks) |
644 | 643 |
645 @property | 644 @property |
646 def parsed_url(self): | 645 def parsed_url(self): |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 | 687 |
689 def hierarchy(self): | 688 def hierarchy(self): |
690 """Returns a human-readable hierarchical reference to a Dependency.""" | 689 """Returns a human-readable hierarchical reference to a Dependency.""" |
691 out = '%s(%s)' % (self.name, self.url) | 690 out = '%s(%s)' % (self.name, self.url) |
692 i = self.parent | 691 i = self.parent |
693 while i and i.name: | 692 while i and i.name: |
694 out = '%s(%s) -> %s' % (i.name, i.url, out) | 693 out = '%s(%s) -> %s' % (i.name, i.url, out) |
695 i = i.parent | 694 i = i.parent |
696 return out | 695 return out |
697 | 696 |
698 @property | |
699 def root(self): | |
700 """Returns the root node, a GClient object.""" | |
701 if not self.parent: | |
702 # This line is to signal pylint that it could be a GClient instance. | |
703 return self or GClient(None, None) | |
704 return self.parent.root | |
705 | |
706 | 697 |
707 class GClient(Dependency): | 698 class GClient(Dependency): |
708 """Object that represent a gclient checkout. A tree of Dependency(), one per | 699 """Object that represent a gclient checkout. A tree of Dependency(), one per |
709 solution or DEPS entry.""" | 700 solution or DEPS entry.""" |
710 | 701 |
711 DEPS_OS_CHOICES = { | 702 DEPS_OS_CHOICES = { |
712 "win32": "win", | 703 "win32": "win", |
713 "win": "win", | 704 "win": "win", |
714 "cygwin": "win", | 705 "cygwin": "win", |
715 "darwin": "mac", | 706 "darwin": "mac", |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1451 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
1461 print >> sys.stderr, 'Error: %s' % str(e) | 1452 print >> sys.stderr, 'Error: %s' % str(e) |
1462 return 1 | 1453 return 1 |
1463 | 1454 |
1464 | 1455 |
1465 if '__main__' == __name__: | 1456 if '__main__' == __name__: |
1466 fix_encoding.fix_encoding() | 1457 fix_encoding.fix_encoding() |
1467 sys.exit(Main(sys.argv[1:])) | 1458 sys.exit(Main(sys.argv[1:])) |
1468 | 1459 |
1469 # vim: ts=2:sw=2:tw=80:et: | 1460 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |