• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18def SplitVersion(version):
19  """Splits the Xcode version to 3 values.
20
21  >>> list(SplitVersion('8.2.1.1'))
22  ['8', '2', '1']
23  >>> list(SplitVersion('9.3'))
24  ['9', '3', '0']
25  >>> list(SplitVersion('10.0'))
26  ['10', '0', '0']
27  """
28  if isinstance(version, bytes):
29    version = version.decode()
30  version = version.split('.')
31  return itertools.islice(itertools.chain(version, itertools.repeat('0')), 0, 3)
32
33def FormatVersion(version):
34  """Converts Xcode version to a format required for DTXcode in Info.plist
35
36  >>> FormatVersion('8.2.1')
37  '0821'
38  >>> FormatVersion('9.3')
39  '0930'
40  >>> FormatVersion('10.0')
41  '1000'
42  """
43  major, minor, patch = SplitVersion(version)
44  return ('%2s%s%s' % (major, minor, patch)).replace(' ', '0')
45
46def FillXcodeVersion(settings):
47  """Fills the Xcode version and build number into |settings|."""
48  lines = subprocess.check_output(['xcodebuild', '-version']).splitlines()
49  settings['xcode_version'] = FormatVersion(lines[0].split()[-1])
50  settings['xcode_version_int'] = int(settings['xcode_version'], 10)
51  settings['xcode_build'] = lines[-1].split()[-1]
52
53
54def FillMachineOSBuild(settings):
55  """Fills OS build number into |settings|."""
56  settings['machine_os_build'] = subprocess.check_output(
57      ['sw_vers', '-buildVersion']).strip()
58
59
60def FillSDKPathAndVersion(settings, platform, xcode_version):
61  """Fills the SDK path and version for |platform| into |settings|."""
62  settings['sdk_path'] = subprocess.check_output([
63      'xcrun', '-sdk', platform, '--show-sdk-path']).strip()
64  settings['sdk_version'] = subprocess.check_output([
65      'xcrun', '-sdk', platform, '--show-sdk-version']).strip()
66  settings['sdk_platform_path'] = subprocess.check_output([
67      'xcrun', '-sdk', platform, '--show-sdk-platform-path']).strip()
68  if xcode_version >= '0720':
69    settings['sdk_build'] = subprocess.check_output([
70        'xcrun', '-sdk', platform, '--show-sdk-build-version']).strip()
71  else:
72    settings['sdk_build'] = settings['sdk_version']
73
74
75if __name__ == '__main__':
76  doctest.testmod()
77
78  parser = argparse.ArgumentParser()
79  parser.add_argument("--developer_dir", required=False)
80  args, unknownargs = parser.parse_known_args()
81  if args.developer_dir:
82    os.environ['DEVELOPER_DIR'] = args.developer_dir
83
84  if len(unknownargs) != 1:
85    sys.stderr.write(
86        'usage: %s [iphoneos|iphonesimulator|macosx]\n' %
87        os.path.basename(sys.argv[0]))
88    sys.exit(1)
89
90  settings = {}
91  FillMachineOSBuild(settings)
92  FillXcodeVersion(settings)
93  FillSDKPathAndVersion(settings, unknownargs[0], settings['xcode_version'])
94
95  for key in sorted(settings):
96    value = settings[key]
97    if isinstance(value, bytes):
98      value = value.decode()
99    value = '"%s"' % value
100    print('%s=%s' % (key, value))
101