提交 beedfa55 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

gyp: Fix Python 3 incompatibilities

This is a commit made by @philipnery in the gyp project:
  https://chromium-review.googlesource.com/c/external/gyp/+/1639564

Let's consider #207 fixed
上级 20a92b14
...@@ -14,3 +14,4 @@ Tom Freudenberg <th.freudenberg@gmail.com> ...@@ -14,3 +14,4 @@ Tom Freudenberg <th.freudenberg@gmail.com>
Julien Brianceau <jbriance@cisco.com> Julien Brianceau <jbriance@cisco.com>
Refael Ackermann <refack@gmail.com> Refael Ackermann <refack@gmail.com>
Jiajie Hu <jiajie.hu@intel.com> Jiajie Hu <jiajie.hu@intel.com>
Philip Nery <pbfnery@gmail.com>
...@@ -1773,7 +1773,8 @@ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD ...@@ -1773,7 +1773,8 @@ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD
# - The multi-output rule will have an do-nothing recipe. # - The multi-output rule will have an do-nothing recipe.
# Hash the target name to avoid generating overlong filenames. # Hash the target name to avoid generating overlong filenames.
cmddigest = hashlib.sha1(command if command else self.target).hexdigest() cmdstring = (command if command else self.target).encode('utf-8')
cmddigest = hashlib.sha1(cmdstring).hexdigest()
intermediate = "%s.intermediate" % (cmddigest) intermediate = "%s.intermediate" % (cmddigest)
self.WriteLn('%s: %s' % (' '.join(outputs), intermediate)) self.WriteLn('%s: %s' % (' '.join(outputs), intermediate))
self.WriteLn('\t%s' % '@:'); self.WriteLn('\t%s' % '@:');
......
...@@ -902,7 +902,8 @@ def ExpandVariables(input, phase, variables, build_file): ...@@ -902,7 +902,8 @@ def ExpandVariables(input, phase, variables, build_file):
p_stdout, p_stderr = p.communicate('') p_stdout, p_stderr = p.communicate('')
if p.wait() != 0 or p_stderr: if p.wait() != 0 or p_stderr:
sys.stderr.write(p_stderr) p_stderr_decoded = p_stderr.decode('utf-8')
sys.stderr.write(p_stderr_decoded)
# Simulate check_call behavior, since check_call only exists # Simulate check_call behavior, since check_call only exists
# in python 2.5 and later. # in python 2.5 and later.
raise GypError("Call to '%s' returned exit status %d while in %s." % raise GypError("Call to '%s' returned exit status %d while in %s." %
...@@ -948,7 +949,7 @@ def ExpandVariables(input, phase, variables, build_file): ...@@ -948,7 +949,7 @@ def ExpandVariables(input, phase, variables, build_file):
ProcessVariablesAndConditionsInList(replacement, phase, variables, ProcessVariablesAndConditionsInList(replacement, phase, variables,
build_file) build_file)
elif type(replacement) not in (str, int): elif type(replacement) not in (str, int):
raise GypError('Variable ' + contents + raise GypError('Variable ' + str(contents) +
' must expand to a string or list of strings; ' + ' must expand to a string or list of strings; ' +
'found a ' + replacement.__class__.__name__) 'found a ' + replacement.__class__.__name__)
......
...@@ -113,13 +113,14 @@ class MacTool(object): ...@@ -113,13 +113,14 @@ class MacTool(object):
raise raise
current_section_header = None current_section_header = None
for line in stdout.splitlines(): for line in stdout.splitlines():
if ibtool_section_re.match(line): line_decoded = line.decode('utf-8')
current_section_header = line if ibtool_section_re.match(line_decoded):
elif not ibtool_re.match(line): current_section_header = line_decoded
elif not ibtool_re.match(line_decoded):
if current_section_header: if current_section_header:
print(current_section_header) print(current_section_header)
current_section_header = None current_section_header = None
print(line) print(line_decoded)
return 0 return 0
def _ConvertToBinary(self, dest): def _ConvertToBinary(self, dest):
...@@ -270,7 +271,7 @@ class MacTool(object): ...@@ -270,7 +271,7 @@ class MacTool(object):
libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env) libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, env=env)
_, err = libtoolout.communicate() _, err = libtoolout.communicate()
for line in err.splitlines(): for line in err.splitlines():
line_decoded = line.decode("utf-8") line_decoded = line.decode('utf-8')
if not libtool_re.match(line_decoded) and not libtool_re5.match(line_decoded): if not libtool_re.match(line_decoded) and not libtool_re5.match(line_decoded):
print(line_decoded, file=sys.stderr) print(line_decoded, file=sys.stderr)
# Unconditionally touch the output .a file on the command line if present # Unconditionally touch the output .a file on the command line if present
......
...@@ -149,6 +149,14 @@ class Writer(object): ...@@ -149,6 +149,14 @@ class Writer(object):
return [] return []
if isinstance(input, list): if isinstance(input, list):
return input return input
# map is not a class in Python 2
try:
if isinstance(input, map):
return list(input)
except TypeError:
pass
return [input] return [input]
......
...@@ -526,7 +526,7 @@ class XcodeSettings(object): ...@@ -526,7 +526,7 @@ class XcodeSettings(object):
XcodeSettings._sdk_path_cache[sdk_root] = sdk_path XcodeSettings._sdk_path_cache[sdk_root] = sdk_path
if sdk_root: if sdk_root:
XcodeSettings._sdk_root_cache[sdk_path] = sdk_root XcodeSettings._sdk_root_cache[sdk_path] = sdk_root
return XcodeSettings._sdk_path_cache[sdk_root].decode() return XcodeSettings._sdk_path_cache[sdk_root]
def _AppendPlatformVersionMinFlags(self, lst): def _AppendPlatformVersionMinFlags(self, lst):
self._Appendf(lst, 'MACOSX_DEPLOYMENT_TARGET', '-mmacosx-version-min=%s') self._Appendf(lst, 'MACOSX_DEPLOYMENT_TARGET', '-mmacosx-version-min=%s')
...@@ -926,7 +926,7 @@ class XcodeSettings(object): ...@@ -926,7 +926,7 @@ class XcodeSettings(object):
# extensions and provide loader and main function. # extensions and provide loader and main function.
# These flags reflect the compilation options used by xcode to compile # These flags reflect the compilation options used by xcode to compile
# extensions. # extensions.
if XcodeVersion() < '0900': if XcodeVersion()[0] < '0900':
ldflags.append('-lpkstart') ldflags.append('-lpkstart')
ldflags.append(sdk_root + ldflags.append(sdk_root +
'/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit') '/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit')
...@@ -1133,8 +1133,9 @@ class XcodeSettings(object): ...@@ -1133,8 +1133,9 @@ class XcodeSettings(object):
output = subprocess.check_output( output = subprocess.check_output(
['security', 'find-identity', '-p', 'codesigning', '-v']) ['security', 'find-identity', '-p', 'codesigning', '-v'])
for line in output.splitlines(): for line in output.splitlines():
if identity in line: line_decoded = line.decode('utf-8')
fingerprint = line.split()[1] if identity in line_decoded:
fingerprint = line_decoded.split()[1]
cache = XcodeSettings._codesigning_key_cache cache = XcodeSettings._codesigning_key_cache
assert identity not in cache or fingerprint == cache[identity], ( assert identity not in cache or fingerprint == cache[identity], (
"Multiple codesigning fingerprints for identity: %s" % identity) "Multiple codesigning fingerprints for identity: %s" % identity)
...@@ -1413,7 +1414,7 @@ def XcodeVersion(): ...@@ -1413,7 +1414,7 @@ def XcodeVersion():
version = version_list[0] version = version_list[0]
build = version_list[-1] build = version_list[-1]
# Be careful to convert "4.2" to "0420": # Be careful to convert "4.2" to "0420":
version = version.split()[-1].decode().replace('.', '') version = version.split()[-1].replace('.', '')
version = (version + '0' * (3 - len(version))).zfill(4) version = (version + '0' * (3 - len(version))).zfill(4)
if build: if build:
build = build.split()[-1] build = build.split()[-1]
...@@ -1452,7 +1453,7 @@ def GetStdout(cmdlist): ...@@ -1452,7 +1453,7 @@ def GetStdout(cmdlist):
if job.returncode != 0: if job.returncode != 0:
sys.stderr.write(out + b'\n') sys.stderr.write(out + b'\n')
raise GypError('Error %d running %s' % (job.returncode, cmdlist[0])) raise GypError('Error %d running %s' % (job.returncode, cmdlist[0]))
return out.rstrip(b'\n') return out.rstrip(b'\n').decode('utf-8')
def MergeGlobalXcodeSettingsToSpec(global_dict, spec): def MergeGlobalXcodeSettingsToSpec(global_dict, spec):
...@@ -1660,7 +1661,7 @@ def _GetXcodeEnv(xcode_settings, built_products_dir, srcroot, configuration, ...@@ -1660,7 +1661,7 @@ def _GetXcodeEnv(xcode_settings, built_products_dir, srcroot, configuration,
install_name_base = xcode_settings.GetInstallNameBase() install_name_base = xcode_settings.GetInstallNameBase()
if install_name_base: if install_name_base:
env['DYLIB_INSTALL_NAME_BASE'] = install_name_base env['DYLIB_INSTALL_NAME_BASE'] = install_name_base
if XcodeVersion() >= '0500' and not env.get('SDKROOT'): if XcodeVersion()[0] >= '0500' and not env.get('SDKROOT'):
sdk_root = xcode_settings._SdkRoot(configuration) sdk_root = xcode_settings._SdkRoot(configuration)
if not sdk_root: if not sdk_root:
sdk_root = xcode_settings._XcodeSdkPath('') sdk_root = xcode_settings._XcodeSdkPath('')
......
...@@ -137,6 +137,7 @@ Strings of class unicode are handled properly and encoded in UTF-8 when ...@@ -137,6 +137,7 @@ Strings of class unicode are handled properly and encoded in UTF-8 when
a project file is output. a project file is output.
""" """
import functools
import gyp.common import gyp.common
import posixpath import posixpath
import re import re
...@@ -430,7 +431,7 @@ class XCObject(object): ...@@ -430,7 +431,7 @@ class XCObject(object):
""" """
hash.update(struct.pack('>i', len(data))) hash.update(struct.pack('>i', len(data)))
hash.update(data) hash.update(data.encode('utf-8'))
if seed_hash is None: if seed_hash is None:
seed_hash = _new_sha1() seed_hash = _new_sha1()
...@@ -1417,7 +1418,8 @@ class PBXGroup(XCHierarchicalElement): ...@@ -1417,7 +1418,8 @@ class PBXGroup(XCHierarchicalElement):
def SortGroup(self): def SortGroup(self):
self._properties['children'] = \ self._properties['children'] = \
sorted(self._properties['children'], cmp=lambda x,y: x.Compare(y)) sorted(self._properties['children'],
key=functools.cmp_to_key(XCHierarchicalElement.Compare))
# Recurse. # Recurse.
for child in self._properties['children']: for child in self._properties['children']:
...@@ -2721,7 +2723,7 @@ class PBXProject(XCContainerPortal): ...@@ -2721,7 +2723,7 @@ class PBXProject(XCContainerPortal):
# according to their defined order. # according to their defined order.
self._properties['mainGroup']._properties['children'] = \ self._properties['mainGroup']._properties['children'] = \
sorted(self._properties['mainGroup']._properties['children'], sorted(self._properties['mainGroup']._properties['children'],
cmp=lambda x,y: x.CompareRootGroup(y)) key=functools.cmp_to_key(XCHierarchicalElement.CompareRootGroup))
# Sort everything else by putting group before files, and going # Sort everything else by putting group before files, and going
# alphabetically by name within sections of groups and files. SortGroup # alphabetically by name within sections of groups and files. SortGroup
...@@ -2812,9 +2814,8 @@ class PBXProject(XCContainerPortal): ...@@ -2812,9 +2814,8 @@ class PBXProject(XCContainerPortal):
# Xcode seems to sort this list case-insensitively # Xcode seems to sort this list case-insensitively
self._properties['projectReferences'] = \ self._properties['projectReferences'] = \
sorted(self._properties['projectReferences'], cmp=lambda x,y: sorted(self._properties['projectReferences'],
cmp(x['ProjectRef'].Name().lower(), key=lambda x: x['ProjectRef'].Name().lower())
y['ProjectRef'].Name().lower()))
else: else:
# The link already exists. Pull out the relevnt data. # The link already exists. Pull out the relevnt data.
project_ref_dict = self._other_pbxprojects[other_pbxproject] project_ref_dict = self._other_pbxprojects[other_pbxproject]
...@@ -2911,19 +2912,6 @@ class PBXProject(XCContainerPortal): ...@@ -2911,19 +2912,6 @@ class PBXProject(XCContainerPortal):
# same order that the targets are sorted in the remote project file. This # same order that the targets are sorted in the remote project file. This
# is the sort order used by Xcode. # is the sort order used by Xcode.
def CompareProducts(x, y, remote_products):
# x and y are PBXReferenceProxy objects. Go through their associated
# PBXContainerItem to get the remote PBXFileReference, which will be
# present in the remote_products list.
x_remote = x._properties['remoteRef']._properties['remoteGlobalIDString']
y_remote = y._properties['remoteRef']._properties['remoteGlobalIDString']
x_index = remote_products.index(x_remote)
y_index = remote_products.index(y_remote)
# Use the order of each remote PBXFileReference in remote_products to
# determine the sort order.
return cmp(x_index, y_index)
for other_pbxproject, ref_dict in self._other_pbxprojects.items(): for other_pbxproject, ref_dict in self._other_pbxprojects.items():
# Build up a list of products in the remote project file, ordered the # Build up a list of products in the remote project file, ordered the
# same as the targets that produce them. # same as the targets that produce them.
...@@ -2938,7 +2926,7 @@ class PBXProject(XCContainerPortal): ...@@ -2938,7 +2926,7 @@ class PBXProject(XCContainerPortal):
product_group = ref_dict['ProductGroup'] product_group = ref_dict['ProductGroup']
product_group._properties['children'] = sorted( product_group._properties['children'] = sorted(
product_group._properties['children'], product_group._properties['children'],
cmp=lambda x, y, rp=remote_products: CompareProducts(x, y, rp)) key=lambda x: remote_products.index(x._properties['remoteRef']._properties['remoteGlobalIDString']))
class XCProjectFile(XCObject): class XCProjectFile(XCObject):
...@@ -2969,8 +2957,7 @@ class XCProjectFile(XCObject): ...@@ -2969,8 +2957,7 @@ class XCProjectFile(XCObject):
self._XCPrint(file, 0, '{ ') self._XCPrint(file, 0, '{ ')
else: else:
self._XCPrint(file, 0, '{\n') 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': if property == 'objects':
self._PrintObjects(file) self._PrintObjects(file)
else: else:
...@@ -2997,7 +2984,7 @@ class XCProjectFile(XCObject): ...@@ -2997,7 +2984,7 @@ class XCProjectFile(XCObject):
self._XCPrint(file, 0, '\n') self._XCPrint(file, 0, '\n')
self._XCPrint(file, 0, '/* Begin ' + class_name + ' section */\n') self._XCPrint(file, 0, '/* Begin ' + class_name + ' section */\n')
for object in sorted(objects_by_class[class_name], for object in sorted(objects_by_class[class_name],
cmp=lambda x, y: cmp(x.id, y.id)): key=lambda x: x.id):
object.Print(file) object.Print(file)
self._XCPrint(file, 0, '/* End ' + class_name + ' section */\n') self._XCPrint(file, 0, '/* End ' + class_name + ' section */\n')
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论