1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright 2014 The Chromium Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7import argparse 8import doctest 9import itertools 10import os 11import subprocess 12import sys 13 14# This script prints information about the build system, the operating 15# system and the iOS or Mac SDK (depending on the platform "iphonesimulator", 16# "iphoneos" or "macosx" generally). 17 18 19def SplitVersion(version): 20 """Splits the Xcode version to 3 values. 21 22 >>> list(SplitVersion('8.2.1.1')) 23 ['8', '2', '1'] 24 >>> list(SplitVersion('9.3')) 25 ['9', '3', '0'] 26 >>> list(SplitVersion('10.0')) 27 ['10', '0', '0'] 28 """ 29 if isinstance(version, bytes): 30 version = version.decode() 31 version = version.split('.') 32 return itertools.islice(itertools.chain(version, itertools.repeat('0')), 0, 3) 33 34 35def FormatVersion(version): 36 """Converts Xcode version to a format required for DTXcode in Info.plist 37 38 >>> FormatVersion('8.2.1') 39 '0821' 40 >>> FormatVersion('9.3') 41 '0930' 42 >>> FormatVersion('10.0') 43 '1000' 44 """ 45 major, minor, patch = SplitVersion(version) 46 return ('%2s%s%s' % (major, minor, patch)).replace(' ', '0') 47 48 49def FillXcodeVersion(settings): 50 """Fills the Xcode version and build number into |settings|.""" 51 lines = subprocess.check_output(['xcodebuild', '-version']).splitlines() 52 settings['xcode_version'] = FormatVersion(lines[0].split()[-1]) 53 settings['xcode_version_int'] = int(settings['xcode_version'], 10) 54 settings['xcode_build'] = lines[-1].split()[-1] 55 56 57def FillMachineOSBuild(settings): 58 """Fills OS build number into |settings|.""" 59 settings['machine_os_build'] = subprocess.check_output( 60 ['sw_vers', '-buildVersion']).strip() 61 62 63def FillSDKPathAndVersion(settings, platform, xcode_version): 64 """Fills the SDK path and version for |platform| into |settings|.""" 65 settings['sdk_path'] = subprocess.check_output([ 66 'xcrun', '-sdk', platform, '--show-sdk-path']).strip() 67 settings['sdk_version'] = subprocess.check_output([ 68 'xcrun', '-sdk', platform, '--show-sdk-version']).strip() 69 settings['sdk_platform_path'] = subprocess.check_output([ 70 'xcrun', '-sdk', platform, '--show-sdk-platform-path']).strip() 71 if xcode_version >= '0720': 72 settings['sdk_build'] = subprocess.check_output([ 73 'xcrun', '-sdk', platform, '--show-sdk-build-version']).strip() 74 else: 75 settings['sdk_build'] = settings['sdk_version'] 76 77 78if __name__ == '__main__': 79 doctest.testmod() 80 81 parser = argparse.ArgumentParser() 82 parser.add_argument("--developer_dir", required=False) 83 args, unknownargs = parser.parse_known_args() 84 if args.developer_dir: 85 os.environ['DEVELOPER_DIR'] = args.developer_dir 86 87 if len(unknownargs) != 1: 88 sys.stderr.write( 89 'usage: %s [iphoneos|iphonesimulator|macosx]\n' % 90 os.path.basename(sys.argv[0])) 91 sys.exit(1) 92 93 settings = {} 94 FillMachineOSBuild(settings) 95 FillXcodeVersion(settings) 96 FillSDKPathAndVersion(settings, unknownargs[0], settings['xcode_version']) 97 98 for key in sorted(settings): 99 value = settings[key] 100 if isinstance(value, bytes): 101 value = value.decode() 102 value = '"%s"' % value 103 print('%s=%s' % (key, value)) 104