Index: xcodeproj_file.py |
=================================================================== |
--- xcodeproj_file.py (revision 1473) |
+++ xcodeproj_file.py (working copy) |
@@ -254,7 +254,7 @@ |
but in some cases an object's parent may wish to push a |
hashable value into its child, and it can do so by appending |
to _hashables. |
- Attribues: |
+ Attributes: |
id: The object's identifier, a 24-character uppercase hexadecimal string. |
Usually, objects being created should not set id until the entire |
project file structure is built. At that point, UpdateIDs() should |
@@ -392,7 +392,10 @@ |
return hashables |
- def ComputeIDs(self, recursive=True, overwrite=True, hash=None): |
+ def HashablesForChild(self): |
+ return None |
+ |
+ def ComputeIDs(self, recursive=True, overwrite=True, seed_hash=None): |
"""Set "id" properties deterministically. |
An object's "id" property is set based on a hash of its class type and |
@@ -419,17 +422,28 @@ |
hash.update(struct.pack('>i', len(data))) |
hash.update(data) |
- if hash is None: |
- hash = _new_sha1() |
+ if seed_hash is None: |
+ seed_hash = _new_sha1() |
+ hash = seed_hash.copy() |
+ |
hashables = self.Hashables() |
assert len(hashables) > 0 |
for hashable in hashables: |
_HashUpdate(hash, hashable) |
if recursive: |
+ hashables_for_child = self.HashablesForChild() |
+ if hashables_for_child is None: |
+ child_hash = hash |
+ else: |
+ assert len(hashables_for_child) > 0 |
+ child_hash = seed_hash.copy() |
+ for hashable in hashables_for_child: |
+ _HashUpdate(child_hash, hashable) |
+ |
for child in self.Children(): |
- child.ComputeIDs(recursive, overwrite, hash.copy()) |
+ child.ComputeIDs(recursive, overwrite, child_hash) |
if overwrite or self.id is None: |
# Xcode IDs are only 96 bits (24 hex characters), but a SHA-1 digest is |
@@ -1104,6 +1118,26 @@ |
for child in self._properties.get('children', []): |
self._AddChildToDicts(child) |
+ def Hashables(self): |
+ # super |
+ hashables = XCHierarchicalElement.Hashables(self) |
+ |
+ # It is not sufficient to just rely on name and parent to build a unique |
+ # hashable : a node could have two child PBXGroup sharing a common name. |
+ # To add entropy the hashable is enhanced with the names of all its |
+ # children. |
Mark Mentovai
2012/08/28 12:56:22
I thought (Stuart told me?) that PBXProject object
|
+ for child in self._properties.get('children', []): |
+ child_name = child.Name() |
+ if child_name != None: |
+ hashables.append(child_name) |
+ |
+ return hashables |
+ |
+ def HashablesForChild(self): |
+ # To avoid a circular reference the hashables used to compute a child id do |
+ # not include the child names. |
+ return XCHierarchicalElement.Hashables(self) |
+ |
def _AddChildToDicts(self, child): |
# Sets up this PBXGroup object's dicts to reference the child properly. |
child_path = child.PathFromSourceTreeAndPath() |