Skip to content

Commit

Permalink
tools: port Python 3 compat patch ec4d403 from node-gyp to gyp
Browse files Browse the repository at this point in the history
original commit: nodejs/node-gyp@ec4d403
Refs: nodejs/node-gyp#1939
Co-Authored-By: Christian Clauss <cclauss@me.com>
  • Loading branch information
chrmoritz committed Nov 5, 2019
1 parent c0b9253 commit 1f5d5cc
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions tools/gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,8 @@ def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
# extensions and provide loader and main function.
# These flags reflect the compilation options used by xcode to compile
# extensions.
if XcodeVersion() < '0900':
xcode_version, _ = XcodeVersion()
if xcode_version < '0900':
ldflags.append('-lpkstart')
ldflags.append(sdk_root +
'/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit')
Expand Down Expand Up @@ -1206,8 +1207,8 @@ def GetExtraPlistItems(self, configname=None):
cache = {}
cache['BuildMachineOSBuild'] = self._BuildMachineOSBuild()

xcode, xcode_build = XcodeVersion()
cache['DTXcode'] = xcode
xcode_version, xcode_build = XcodeVersion()
cache['DTXcode'] = xcode_version
cache['DTXcodeBuild'] = xcode_build
compiler = self.xcode_settings[configname].get('GCC_VERSION')
if compiler is not None:
Expand All @@ -1218,10 +1219,10 @@ def GetExtraPlistItems(self, configname=None):
sdk_root = self._DefaultSdkRoot()
sdk_version = self._GetSdkVersionInfoItem(sdk_root, '--show-sdk-version')
cache['DTSDKName'] = sdk_root + (sdk_version or '')
if xcode >= '0720':
if xcode_version >= '0720':
cache['DTSDKBuild'] = self._GetSdkVersionInfoItem(
sdk_root, '--show-sdk-build-version')
elif xcode >= '0430':
elif xcode_version >= '0430':
cache['DTSDKBuild'] = sdk_version
else:
cache['DTSDKBuild'] = cache['BuildMachineOSBuild']
Expand Down Expand Up @@ -1256,7 +1257,7 @@ def _DefaultSdkRoot(self):
project, then the environment variable was empty. Starting with this
version, Xcode uses the name of the newest SDK installed.
"""
xcode_version, xcode_build = XcodeVersion()
xcode_version, _ = XcodeVersion()
if xcode_version < '0500':
return ''
default_sdk_path = self._XcodeSdkPath('')
Expand Down Expand Up @@ -1393,10 +1394,12 @@ def XcodeVersion():
# Xcode 3.2.6
# Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
# BuildVersion: 10M2518
# Convert that to '0463', '4H1503'.
# Convert that to ('0463', '4H1503') or ('0326', '10M2518').
global XCODE_VERSION_CACHE
if XCODE_VERSION_CACHE:
return XCODE_VERSION_CACHE
version = ""
build = ""
try:
version_list = GetStdoutQuiet(['xcodebuild', '-version']).splitlines()
# In some circumstances xcodebuild exits 0 but doesn't return
Expand All @@ -1406,21 +1409,16 @@ def XcodeVersion():
# checking that version.
if len(version_list) < 2:
raise GypError("xcodebuild returned unexpected results")
except:
version = CLTVersion()
if version:
version = ".".join(version.split(".")[:3])
else:
version = version_list[0].split()[-1] # Last word on first line
build = version_list[-1].split()[-1] # Last word on last line
except GypError: # Xcode not installed so look for XCode Command Line Tools
version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
if not version:
raise GypError("No Xcode or CLT version detected!")
# The CLT has no build information, so we return an empty string.
version_list = [version, '']
version = version_list[0]
build = version_list[-1]
# Be careful to convert "4.2" to "0420":
version = version.split()[-1].replace('.', '')
version = (version + '0' * (3 - len(version))).zfill(4)
if build:
build = build.split()[-1]
# Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
version = version.split(".")[:3] # Just major, minor, micro
version[0] = version[0].zfill(2) # Add a leading zero if major is one digit
version = ("".join(version) + "00")[:4] # Limit to exactly four characters
XCODE_VERSION_CACHE = (version, build)
return XCODE_VERSION_CACHE

Expand Down Expand Up @@ -1680,7 +1678,8 @@ def _GetXcodeEnv(xcode_settings, built_products_dir, srcroot, configuration,
install_name_base = xcode_settings.GetInstallNameBase()
if install_name_base:
env['DYLIB_INSTALL_NAME_BASE'] = install_name_base
if XcodeVersion() >= '0500' and not env.get('SDKROOT'):
xcode_version, _ = XcodeVersion()
if xcode_version >= '0500' and not env.get('SDKROOT'):
sdk_root = xcode_settings._SdkRoot(configuration)
if not sdk_root:
sdk_root = xcode_settings._XcodeSdkPath('')
Expand Down

0 comments on commit 1f5d5cc

Please sign in to comment.