Skip to content

Instantly share code, notes, and snippets.

@agirault
Last active December 17, 2015 22:28
Show Gist options
  • Save agirault/f213c737c0b2b581b13c to your computer and use it in GitHub Desktop.
Save agirault/f213c737c0b2b581b13c to your computer and use it in GitHub Desktop.
Links all your SDKs to XCode
#!/usr/bin/python
# add-sdks.py
# Rob Napier <robnapier@gmail.com>
# Alexis girault <alexis.girault@kitware.com>
# Script to link in all your old SDKs to Xcode
# Needs to be run every time you update Xcode
#
# 1. Create a directory and store the SDKs:
# MacOSX10.*.sdk
# 2. Make sure you have updated XCode (xcode-select --install)
# 3. Run 'python fix-xcode.py /path/to/SDKs'
import argparse
import subprocess
import os
import sys
# parse
parser = argparse.ArgumentParser()
parser.add_argument('sourcepath', help='Path to source SDKs', nargs='?')
parser.add_argument('xcodePath', help='Path to Xcode (optional)', nargs='?')
args = parser.parse_args()
# source_path
if args.sourcepath:
source_path = os.path.abspath(args.sourcepath)
else:
print "Missing path to SDKs"
print "# 1. Create a directory and store the SDKs:"
print "# MacOSX10.*.sdk"
print "# 2. Make sure you have updated Xcode (xcode-select --install)"
print "# 3. Run 'fix-xcode.py /path/to/SDKs'"
sys.exit(2)
# dest_path
if args.xcodePath:
dest_path = args.xcodePath
else:
dest_path = subprocess.check_output(["xcode-select", "--print-path"]).rstrip()
if not dest_path.endswith("/Contents/Developer"):
dest_path = os.path.join(dest_path,"Contents","Developer")
dest_path = os.path.join(dest_path,"Platforms","MacOSX.platform","Developer","SDKs")
print "Linking SDKs from", source_path
cpt = 0
# link
for sdk in os.listdir(source_path):
if sdk.endswith('.sdk'):
cpt +=1
print "-- Linking", sdk, "in", dest_path
subprocess.call("sudo ln -sf %(source_path)s/%(sdk)s %(dest_path)s" % locals(), shell=True)
if cpt > 0 :
print cpt, "SDKs were added to Xcode at", dest_path
else:
print "No SDKs found in this directory"
print "# 1. Create a directory and store the SDKs:"
print "# MacOSX10.*.sdk"
print "# 2. Make sure you have updated Xcode (xcode-select --install)"
print "# 3. Run 'fix-xcode.py /path/to/SDKs'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment