|
138 | 138 | """
|
139 | 139 |
|
140 | 140 | import gyp.common
|
| 141 | +from functools import cmp_to_key |
141 | 142 | import hashlib
|
| 143 | +from operator import attrgetter |
142 | 144 | import posixpath
|
143 | 145 | import re
|
144 | 146 | import struct
|
@@ -423,6 +425,8 @@ def _HashUpdate(hash, data):
|
423 | 425 | """
|
424 | 426 |
|
425 | 427 | hash.update(struct.pack(">i", len(data)))
|
| 428 | + if isinstance(data, str): |
| 429 | + data = data.encode("utf-8") |
426 | 430 | hash.update(data)
|
427 | 431 |
|
428 | 432 | if seed_hash is None:
|
@@ -1483,7 +1487,7 @@ def TakeOverOnlyChild(self, recurse=False):
|
1483 | 1487 |
|
1484 | 1488 | def SortGroup(self):
|
1485 | 1489 | self._properties["children"] = sorted(
|
1486 |
| - self._properties["children"], cmp=lambda x, y: x.Compare(y) |
| 1490 | + self._properties["children"], key=cmp_to_key(lambda x, y: x.Compare(y)) |
1487 | 1491 | )
|
1488 | 1492 |
|
1489 | 1493 | # Recurse.
|
@@ -2891,7 +2895,7 @@ def SortGroups(self):
|
2891 | 2895 | # according to their defined order.
|
2892 | 2896 | self._properties["mainGroup"]._properties["children"] = sorted(
|
2893 | 2897 | self._properties["mainGroup"]._properties["children"],
|
2894 |
| - cmp=lambda x, y: x.CompareRootGroup(y), |
| 2898 | + key=cmp_to_key(lambda x, y: x.CompareRootGroup(y)), |
2895 | 2899 | )
|
2896 | 2900 |
|
2897 | 2901 | # Sort everything else by putting group before files, and going
|
@@ -2986,9 +2990,7 @@ def AddOrGetProjectReference(self, other_pbxproject):
|
2986 | 2990 | # Xcode seems to sort this list case-insensitively
|
2987 | 2991 | self._properties["projectReferences"] = sorted(
|
2988 | 2992 | self._properties["projectReferences"],
|
2989 |
| - cmp=lambda x, y: cmp( |
2990 |
| - x["ProjectRef"].Name().lower(), y["ProjectRef"].Name().lower() |
2991 |
| - ), |
| 2993 | + key=lambda x: x["ProjectRef"].Name().lower |
2992 | 2994 | )
|
2993 | 2995 | else:
|
2994 | 2996 | # The link already exists. Pull out the relevnt data.
|
@@ -3120,7 +3122,8 @@ def CompareProducts(x, y, remote_products):
|
3120 | 3122 | product_group = ref_dict["ProductGroup"]
|
3121 | 3123 | product_group._properties["children"] = sorted(
|
3122 | 3124 | product_group._properties["children"],
|
3123 |
| - cmp=lambda x, y, rp=remote_products: CompareProducts(x, y, rp), |
| 3125 | + key=cmp_to_key( |
| 3126 | + lambda x, y, rp=remote_products: CompareProducts(x, y, rp)), |
3124 | 3127 | )
|
3125 | 3128 |
|
3126 | 3129 |
|
@@ -3155,7 +3158,7 @@ def Print(self, file=sys.stdout):
|
3155 | 3158 | else:
|
3156 | 3159 | self._XCPrint(file, 0, "{\n")
|
3157 | 3160 | for property, value in sorted(
|
3158 |
| - self._properties.items(), cmp=lambda x, y: cmp(x, y) |
| 3161 | + self._properties.items() |
3159 | 3162 | ):
|
3160 | 3163 | if property == "objects":
|
3161 | 3164 | self._PrintObjects(file)
|
@@ -3183,7 +3186,7 @@ def _PrintObjects(self, file):
|
3183 | 3186 | self._XCPrint(file, 0, "\n")
|
3184 | 3187 | self._XCPrint(file, 0, "/* Begin " + class_name + " section */\n")
|
3185 | 3188 | for object in sorted(
|
3186 |
| - objects_by_class[class_name], cmp=lambda x, y: cmp(x.id, y.id) |
| 3189 | + objects_by_class[class_name], key=attrgetter("id") |
3187 | 3190 | ):
|
3188 | 3191 | object.Print(file)
|
3189 | 3192 | self._XCPrint(file, 0, "/* End " + class_name + " section */\n")
|
|
0 commit comments