Index: gclient.py |
diff --git a/gclient.py b/gclient.py |
index d86c3663e2d17a50f9b2c8e2b11bb698eeebce4e..6a4005b71bfa3f3dee5c958fa1195b29c2184dbc 100644 |
--- a/gclient.py |
+++ b/gclient.py |
@@ -141,6 +141,9 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem): |
def __init__(self, parent, name, url, safesync_url, custom_deps, |
custom_vars, deps_file, should_process): |
+ # Warning: this function can be called from any thread. Both |
+ # self.dependencies and self.requirements are read and modified from |
+ # multiple threads at the same time. Sad. |
GClientKeywords.__init__(self) |
gclient_utils.WorkItem.__init__(self) |
self.parent = parent |
@@ -167,11 +170,9 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem): |
# This dependency had its hook run |
self.hooks_ran = False |
# Required dependencies to run before running this one: |
- self.requirements = [] |
- if self.parent and self.parent.name: |
- self.requirements.append(self.parent.name) |
- if isinstance(self.url, self.FromImpl): |
- self.requirements.append(self.url.module_name) |
+ self.requirements = set() |
+ |
+ self._FindDependencies() |
# Sanity checks |
if not self.name and self.parent: |
@@ -185,6 +186,44 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem): |
raise gclient_utils.Error('deps_file name must not be a path, just a ' |
'filename. %s' % self.deps_file) |
+ def _FindDependencies(self): |
+ """Setup self.requirements and find any other dependency who would have self |
+ as a requirement. |
+ """ |
+ # self.parent is implicitly a requirement. This will be recursive by |
+ # definition. |
+ if self.parent and self.parent.name: |
+ self.requirements.add(self.parent.name) |
+ |
+ # For a solution with multiple items, dependencies from the non-primary |
+ # solution will dependent on the prior solutions. |
+ if self.parent and self.parent.parent: |
Dirk Pranke
2011/08/30 21:09:36
I'm a little lost here. How do you know that self.
M-A Ruel
2011/09/01 16:17:37
Redid the doc since the code didn't have to be mod
|
+ for i in range(0, self.parent.parent.dependencies.index(self.parent)): |
+ value = self.parent.parent.dependencies[i] |
+ if value.name: |
+ self.requirements.add(value.name) |
+ |
+ if isinstance(self.url, self.FromImpl): |
+ self.requirements.add(self.url.module_name) |
+ |
+ if self.name: |
Dirk Pranke
2011/08/30 21:09:36
When is self.name null? Should that be legal?
M-A Ruel
2011/09/01 16:17:37
The 'containing' root object has no name.
|
+ def all_objects(root): |
Dirk Pranke
2011/08/30 21:09:36
what is an object in this case? Is there a better
M-A Ruel
2011/09/01 16:17:37
Renamed to yield_full_tree().
|
+ """Depth-first recursion.""" |
+ yield root |
+ for i in root.dependencies: |
+ for j in all_objects(i): |
+ yield j |
+ |
+ for obj in all_objects(self.root_parent()): |
+ if obj is self or not obj.name: |
+ continue |
+ # Step 1: Find any requirements self may need. |
+ if self.name.startswith(posixpath.join(obj.name, '')): |
+ self.requirements.add(obj.name) |
+ # Step 2: Find any requirements self may impose. |
+ if obj.name.startswith(posixpath.join(self.name, '')): |
+ obj.requirements.add(self.name) |
+ |
def LateOverride(self, url): |
"""Resolves the parsed url from url. |
@@ -406,16 +445,6 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem): |
if self.recursion_limit() > 0: |
# Then we can parse the DEPS file. |
self.ParseDepsFile() |
- # Adjust the implicit dependency requirement; e.g. if a DEPS file contains |
- # both src/foo and src/foo/bar, src/foo/bar is implicitly dependent of |
- # src/foo. Yes, it's O(n^2)... It's important to do that before |
- # enqueueing them. |
- for s in self.dependencies: |
- for s2 in self.dependencies: |
- if s is s2: |
- continue |
- if s.name.startswith(posixpath.join(s2.name, '')): |
- s.requirements.append(s2.name) |
# Parse the dependencies of this dependency. |
for s in self.dependencies: |