def XcodeVersion():
 global XCODE_VERSION_CACHE
 if XCODE_VERSION_CACHE:
  return XCODE_VERSION_CACHE
 try:
  version_list = GetStdout(['xcodebuild', '-version']).splitlines()
  if (len(version_list) < 2):
   raise GypError('xcodebuild returned unexpected results')
 except:
  version = CLTVersion()
  if version:
   version = re.match('(\\d\\.\\d\\.?\\d*)', version).groups()[0]
  else:
   raise GypError('No Xcode or CLT version detected!')
  version_list = [version, '']
 version = version_list[0]
 build = version_list[(-1)]
 version = version.split()[(-1)].replace('.', '')
 version = (version + ('0' * (3 - len(version)))).zfill(4)
 if build:
  build = build.split()[(-1)]
 XCODE_VERSION_CACHE = (version, build)
 return XCODE_VERSION_CACHE

def XcodeVersion ( ) : global XCODE_VERSION_CACHE if XCODE_VERSION_CACHE : return XCODE_VERSION_CACHE try : version_list = GetStdout ( [ 'xcodebuild' , '-version' ] ) . splitlines ( ) if ( len ( version_list ) < 2 ) : raise GypError ( 'xcodebuild returned unexpected results' ) except : version = CLTVersion ( ) if version : version = re . match ( '(\\d\\.\\d\\.?\\d*)' , version ) . groups ( ) [ 0 ] else : raise GypError ( 'No Xcode or CLT version detected!' ) version_list = [ version , '' ] version = version_list [ 0 ] build = version_list [ ( - 1 ) ] version = version . split ( ) [ ( - 1 ) ] . replace ( '.' , '' ) version = ( version + ( '0' * ( 3 - len ( version ) ) ) ) . zfill ( 4 ) if build : build = build . split ( ) [ ( - 1 ) ] XCODE_VERSION_CACHE = ( version , build ) return XCODE_VERSION_CACHE
returns a tuple of version and build version of installed xcode .