0

I'm writing a build script for build automation.

I'm going to want to run the build script under different versions of Xcode. (eg. 6, 5.1.1, 6.1b).

However, each of these will display a different list for -showsdks, as a result the available sdk may be.

  • -sdk iphoneos8.1
  • -sdk iphoneos8.0
  • -sdk iphoneos7.1
  • -sdk iphoneos7.0
  • etc ...

Without resorting to text munging gymnastics... Is there any way to get this info in easy to parse format at runtime? (Ex. XML would be awesome here).

Antoine Subit
  • 9,803
  • 4
  • 36
  • 52
Dru Freeman
  • 1,766
  • 3
  • 19
  • 41

1 Answers1

1

No, it's not possible to change the format of the output of this command. But the output is always in the same format, it's not as difficult to parse as You think.

For instance using this simple python script:

#!/usr/bin/env python

import re
import subprocess

sdk_header_pattern = re.compile("^.*SDKs:$")
sdk_switch_pattern = re.compile("^.*(-sdk)\s[a-z]+\d+\.\d+$")

def run_command(cmd):
    return subprocess.Popen(cmd, 
                            stdout=subprocess.PIPE, 
                            stderr=subprocess.PIPE, 
                            stdin=subprocess.PIPE).communicate()

input = run_command(['xcodebuild', '-showsdks'])[0] # take first element of returned tuple
sdks = {}
in_sdk = False
platform = ''

for e in input.split('\n'):
    if sdk_header_pattern.match(e) and not in_sdk:
        in_sdk = True
        platform = e[0:e.rfind(' ')]
        sdks[platform] = []
    if in_sdk and sdk_switch_pattern.match(e):
        sdk = e.split(' ')[-1]
        sdks[platform].append(sdk)
    if in_sdk and e == '':
        in_sdk = False
        del platform

for k,v in sdks.iteritems():
   print 'Platform: ', k
   for e in v:
      print '\t', e 
   print    
Opal
  • 81,889
  • 28
  • 189
  • 210