summaryrefslogtreecommitdiff
path: root/tools/gyp/pylib/gyp/xcodeproj_file.py
diff options
context:
space:
mode:
authorcclauss <cclauss@me.com>2019-07-05 18:39:16 +0200
committerRich Trott <rtrott@gmail.com>2019-07-16 10:40:31 -0700
commit54fcb14467b59e82d6e24bf44803462226a5de4d (patch)
tree21aceef7b5250e29be01f01e6451892a1d191a4e /tools/gyp/pylib/gyp/xcodeproj_file.py
parent7032e59bb550adcb448b2d24877921e7f97e7399 (diff)
downloadandroid-node-v8-54fcb14467b59e82d6e24bf44803462226a5de4d.tar.gz
android-node-v8-54fcb14467b59e82d6e24bf44803462226a5de4d.tar.bz2
android-node-v8-54fcb14467b59e82d6e24bf44803462226a5de4d.zip
gyp: cherrypick more Python3 changes from node-gyp
PR-URL: https://github.com/nodejs/node/pull/28563 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'tools/gyp/pylib/gyp/xcodeproj_file.py')
-rw-r--r--tools/gyp/pylib/gyp/xcodeproj_file.py51
1 files changed, 23 insertions, 28 deletions
diff --git a/tools/gyp/pylib/gyp/xcodeproj_file.py b/tools/gyp/pylib/gyp/xcodeproj_file.py
index e69235f724..021ed4309d 100644
--- a/tools/gyp/pylib/gyp/xcodeproj_file.py
+++ b/tools/gyp/pylib/gyp/xcodeproj_file.py
@@ -138,21 +138,18 @@ a project file is output.
"""
import gyp.common
+import hashlib
import posixpath
import re
import struct
import sys
-# hashlib is supplied as of Python 2.5 as the replacement interface for sha
-# and other secure hashes. In 2.6, sha is deprecated. Import hashlib if
-# available, avoiding a deprecation warning under 2.6. Import sha otherwise,
-# preserving 2.4 compatibility.
try:
- import hashlib
- _new_sha1 = hashlib.sha1
-except ImportError:
- import sha
- _new_sha1 = sha.new
+ basestring, cmp, unicode
+except NameError: # Python 3
+ basestring = unicode = str
+ def cmp(x, y):
+ return (x > y) - (x < y)
# See XCObject._EncodeString. This pattern is used to determine when a string
@@ -314,7 +311,7 @@ class XCObject(object):
"""
that = self.__class__(id=self.id, parent=self.parent)
- for key, value in self._properties.iteritems():
+ for key, value in self._properties.items():
is_strong = self._schema[key][2]
if isinstance(value, XCObject):
@@ -324,8 +321,7 @@ class XCObject(object):
that._properties[key] = new_value
else:
that._properties[key] = value
- elif isinstance(value, str) or isinstance(value, unicode) or \
- isinstance(value, int):
+ elif isinstance(value, (basestring, int)):
that._properties[key] = value
elif isinstance(value, list):
if is_strong:
@@ -422,7 +418,7 @@ class XCObject(object):
hash.update(data)
if seed_hash is None:
- seed_hash = _new_sha1()
+ seed_hash = hashlib.sha1()
hash = seed_hash.copy()
@@ -452,7 +448,7 @@ class XCObject(object):
digest_int_count = hash.digest_size / 4
digest_ints = struct.unpack('>' + 'I' * digest_int_count, hash.digest())
id_ints = [0, 0, 0]
- for index in xrange(0, digest_int_count):
+ for index in range(0, digest_int_count):
id_ints[index % 3] ^= digest_ints[index]
self.id = '%08X%08X%08X' % tuple(id_ints)
@@ -475,7 +471,7 @@ class XCObject(object):
"""Returns a list of all of this object's owned (strong) children."""
children = []
- for property, attributes in self._schema.iteritems():
+ for property, attributes in self._schema.items():
(is_list, property_type, is_strong) = attributes[0:3]
if is_strong and property in self._properties:
if not is_list:
@@ -622,7 +618,7 @@ class XCObject(object):
printable += end_tabs + ')'
elif isinstance(value, dict):
printable = '{' + sep
- for item_key, item_value in sorted(value.iteritems()):
+ for item_key, item_value in sorted(value.items()):
printable += element_tabs + \
self._XCPrintableValue(tabs + 1, item_key, flatten_list) + ' = ' + \
self._XCPrintableValue(tabs + 1, item_value, flatten_list) + ';' + \
@@ -691,7 +687,7 @@ class XCObject(object):
printable_value[0] == '"' and printable_value[-1] == '"':
printable_value = printable_value[1:-1]
printable += printable_key + ' = ' + printable_value + ';' + after_kv
- except TypeError, e:
+ except TypeError as e:
gyp.common.ExceptionAppend(e,
'while printing key "%s"' % key)
raise
@@ -730,7 +726,7 @@ class XCObject(object):
self._XCKVPrint(file, 3, 'isa', self.__class__.__name__)
# The remaining elements of an object dictionary are sorted alphabetically.
- for property, value in sorted(self._properties.iteritems()):
+ for property, value in sorted(self._properties.items()):
self._XCKVPrint(file, 3, property, value)
# End the object.
@@ -752,7 +748,7 @@ class XCObject(object):
if properties is None:
return
- for property, value in properties.iteritems():
+ for property, value in properties.items():
# Make sure the property is in the schema.
if not property in self._schema:
raise KeyError(property + ' not in ' + self.__class__.__name__)
@@ -788,8 +784,7 @@ class XCObject(object):
self._properties[property] = value.Copy()
else:
self._properties[property] = value
- elif isinstance(value, str) or isinstance(value, unicode) or \
- isinstance(value, int):
+ elif isinstance(value, (basestring, int)):
self._properties[property] = value
elif isinstance(value, list):
if is_strong:
@@ -865,7 +860,7 @@ class XCObject(object):
# TODO(mark): A stronger verification mechanism is needed. Some
# subclasses need to perform validation beyond what the schema can enforce.
- for property, attributes in self._schema.iteritems():
+ for property, attributes in self._schema.items():
(is_list, property_type, is_strong, is_required) = attributes[0:4]
if is_required and not property in self._properties:
raise KeyError(self.__class__.__name__ + ' requires ' + property)
@@ -875,7 +870,7 @@ class XCObject(object):
overwrite properties that have already been set."""
defaults = {}
- for property, attributes in self._schema.iteritems():
+ for property, attributes in self._schema.items():
(is_list, property_type, is_strong, is_required) = attributes[0:4]
if is_required and len(attributes) >= 5 and \
not property in self._properties:
@@ -1426,7 +1421,7 @@ class XCFileLikeElement(XCHierarchicalElement):
xche = self
while xche != None and isinstance(xche, XCHierarchicalElement):
xche_hashables = xche.Hashables()
- for index in xrange(0, len(xche_hashables)):
+ for index in range(0, len(xche_hashables)):
hashables.insert(index, xche_hashables[index])
xche = xche.parent
return hashables
@@ -2468,7 +2463,7 @@ class PBXNativeTarget(XCTarget):
# The headers phase should come before the resources, sources, and
# frameworks phases, if any.
insert_at = len(self._properties['buildPhases'])
- for index in xrange(0, len(self._properties['buildPhases'])):
+ for index in range(0, len(self._properties['buildPhases'])):
phase = self._properties['buildPhases'][index]
if isinstance(phase, PBXResourcesBuildPhase) or \
isinstance(phase, PBXSourcesBuildPhase) or \
@@ -2489,7 +2484,7 @@ class PBXNativeTarget(XCTarget):
# The resources phase should come before the sources and frameworks
# phases, if any.
insert_at = len(self._properties['buildPhases'])
- for index in xrange(0, len(self._properties['buildPhases'])):
+ for index in range(0, len(self._properties['buildPhases'])):
phase = self._properties['buildPhases'][index]
if isinstance(phase, PBXSourcesBuildPhase) or \
isinstance(phase, PBXFrameworksBuildPhase):
@@ -2911,7 +2906,7 @@ class PBXProject(XCContainerPortal):
# determine the sort order.
return cmp(x_index, y_index)
- for other_pbxproject, ref_dict in self._other_pbxprojects.iteritems():
+ for other_pbxproject, ref_dict in self._other_pbxprojects.items():
# Build up a list of products in the remote project file, ordered the
# same as the targets that produce them.
remote_products = []
@@ -2956,7 +2951,7 @@ class XCProjectFile(XCObject):
self._XCPrint(file, 0, '{ ')
else:
self._XCPrint(file, 0, '{\n')
- for property, value in sorted(self._properties.iteritems(),
+ for property, value in sorted(self._properties.items(),
cmp=lambda x, y: cmp(x, y)):
if property == 'objects':
self._PrintObjects(file)