@@ -855,7 +855,8 @@ def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
855855      # These flags reflect the compilation options used by xcode to compile 
856856      # extensions. 
857857      ldflags .append ('-lpkstart' )
858-       if  XcodeVersion () <  '0900' :
858+       xcode_version , _  =  XcodeVersion ()
859+       if  xcode_version  <  '0900' :
859860        ldflags .append (sdk_root  + 
860861            '/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit' )
861862      ldflags .append ('-fapplication-extension' )
@@ -1088,15 +1089,15 @@ def GetExtraPlistItems(self, configname=None):
10881089      cache  =  {}
10891090      cache ['BuildMachineOSBuild' ] =  self ._BuildMachineOSBuild ()
10901091
1091-       xcode , xcode_build  =  XcodeVersion ()
1092-       cache ['DTXcode' ] =  xcode 
1092+       xcode_version , xcode_build  =  XcodeVersion ()
1093+       cache ['DTXcode' ] =  xcode_version 
10931094      cache ['DTXcodeBuild' ] =  xcode_build 
10941095
10951096      sdk_root  =  self ._SdkRoot (configname )
10961097      if  not  sdk_root :
10971098        sdk_root  =  self ._DefaultSdkRoot ()
10981099      cache ['DTSDKName' ] =  sdk_root 
1099-       if  xcode  >=  '0430' :
1100+       if  xcode_version  >=  '0430' :
11001101        cache ['DTSDKBuild' ] =  self ._GetSdkVersionInfoItem (
11011102            sdk_root , 'ProductBuildVersion' )
11021103      else :
@@ -1126,7 +1127,7 @@ def _DefaultSdkRoot(self):
11261127    project, then the environment variable was empty. Starting with this 
11271128    version, Xcode uses the name of the newest SDK installed. 
11281129    """ 
1129-     xcode_version , xcode_build  =  XcodeVersion ()
1130+     xcode_version , _  =  XcodeVersion ()
11301131    if  xcode_version  <  '0500' :
11311132      return  '' 
11321133    default_sdk_path  =  self ._XcodeSdkPath ('' )
@@ -1263,10 +1264,12 @@ def XcodeVersion():
12631264  #    Xcode 3.2.6 
12641265  #    Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0 
12651266  #    BuildVersion: 10M2518 
1266-   # Convert that to '0463', '4H1503'. 
1267+   # Convert that to ( '0463', '4H1503') or ('0326', '10M2518') . 
12671268  global  XCODE_VERSION_CACHE 
12681269  if  XCODE_VERSION_CACHE :
12691270    return  XCODE_VERSION_CACHE 
1271+   version  =  "" 
1272+   build  =  "" 
12701273  try :
12711274    version_list  =  GetStdoutQuiet (['xcodebuild' , '-version' ]).splitlines ()
12721275    # In some circumstances xcodebuild exits 0 but doesn't return 
@@ -1276,21 +1279,16 @@ def XcodeVersion():
12761279    # checking that version. 
12771280    if  len (version_list ) <  2 :
12781281      raise  GypError ("xcodebuild returned unexpected results" )
1279-   except   GypError : 
1280-     version  =  CLTVersion () 
1281-      if   version : 
1282-        version  =  "." . join ( version . split ( "." )[: 3 ]) 
1283-     else :
1282+      version   =   version_list [ 0 ]. split ()[ - 1 ]   # Last word on first line 
1283+     build  =  version_list [ - 1 ]. split ()[ - 1 ]    # Last word on last line 
1284+   except   GypError :   # Xcode not installed so look for XCode Command Line Tools 
1285+     version  =  CLTVersion ()   # macOS Catalina returns 11.0.0.0.1.1567737322 
1286+     if   not   version :
12841287      raise  GypError ("No Xcode or CLT version detected!" )
1285-     # The CLT has no build information, so we return an empty string. 
1286-     version_list  =  [version , '' ]
1287-   version  =  version_list [0 ]
1288-   build  =  version_list [- 1 ]
1289-   # Be careful to convert "4.2" to "0420" and "10.0" to "1000": 
1290-   version  =  format ('' .join ((version .split ()[- 1 ].split ('.' ) +  ['0' , '0' ])[:3 ]),
1291-                    '>04s' )
1292-   if  build :
1293-     build  =  build .split ()[- 1 ]
1288+   # Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100": 
1289+   version  =  version .split ("." )[:3 ]  # Just major, minor, micro 
1290+   version [0 ] =  version [0 ].zfill (2 )  # Add a leading zero if major is one digit 
1291+   version  =  ("" .join (version ) +  "00" )[:4 ]  # Limit to exactly four characters 
12941292  XCODE_VERSION_CACHE  =  (version , build )
12951293  return  XCODE_VERSION_CACHE 
12961294
@@ -1524,7 +1522,8 @@ def _GetXcodeEnv(xcode_settings, built_products_dir, srcroot, configuration,
15241522  install_name_base  =  xcode_settings .GetInstallNameBase ()
15251523  if  install_name_base :
15261524    env ['DYLIB_INSTALL_NAME_BASE' ] =  install_name_base 
1527-   if  XcodeVersion () >=  '0500'  and  not  env .get ('SDKROOT' ):
1525+   xcode_version , _  =  XcodeVersion ()
1526+   if  xcode_version  >=  '0500'  and  not  env .get ('SDKROOT' ):
15281527    sdk_root  =  xcode_settings ._SdkRoot (configuration )
15291528    if  not  sdk_root :
15301529      sdk_root  =  xcode_settings ._XcodeSdkPath ('' )
0 commit comments