| 3077 | product_group.AppendChild(reference_proxy) |
| 3078 | |
| 3079 | def SortRemoteProductReferences(self): |
| 3080 | # For each remote project file, sort the associated ProductGroup in the |
| 3081 | # same order that the targets are sorted in the remote project file. This |
| 3082 | # is the sort order used by Xcode. |
| 3083 | |
| 3084 | def CompareProducts(x, y, remote_products): |
| 3085 | # x and y are PBXReferenceProxy objects. Go through their associated |
| 3086 | # PBXContainerItem to get the remote PBXFileReference, which will be |
| 3087 | # present in the remote_products list. |
| 3088 | x_remote = x._properties["remoteRef"]._properties["remoteGlobalIDString"] |
| 3089 | y_remote = y._properties["remoteRef"]._properties["remoteGlobalIDString"] |
| 3090 | x_index = remote_products.index(x_remote) |
| 3091 | y_index = remote_products.index(y_remote) |
| 3092 | |
| 3093 | # Use the order of each remote PBXFileReference in remote_products to |
| 3094 | # determine the sort order. |
| 3095 | return cmp(x_index, y_index) |
| 3096 | |
| 3097 | for other_pbxproject, ref_dict in self._other_pbxprojects.items(): |
| 3098 | # Build up a list of products in the remote project file, ordered the |
| 3099 | # same as the targets that produce them. |
| 3100 | remote_products = [] |
| 3101 | for target in other_pbxproject._properties["targets"]: |
| 3102 | if not isinstance(target, PBXNativeTarget): |
| 3103 | continue |
| 3104 | remote_products.append(target._properties["productReference"]) |
| 3105 | |
| 3106 | # Sort the PBXReferenceProxy children according to the list of remote |
| 3107 | # products. |
| 3108 | product_group = ref_dict["ProductGroup"] |
| 3109 | product_group._properties["children"] = sorted( |
| 3110 | product_group._properties["children"], |
| 3111 | key=cmp_to_key( |
| 3112 | lambda x, y, rp=remote_products: CompareProducts(x, y, rp) |
| 3113 | ), |
| 3114 | ) |
| 3115 | |
| 3116 | |
| 3117 | class XCProjectFile(XCObject): |