-
-
Save toonetown/befe043f8ee85c67ad70 to your computer and use it in GitHub Desktop.
Links Xcode SDKs from the /SDKs directory (which you maintain yourself)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# link-sdks | |
# Nathan Toone <[email protected]> | |
# Based on work by Rob Napier <[email protected]> | |
# Script to link in all your old SDKs every time you upgrade Xcode | |
# Create a directory called /Applications/Developer/SDKs (or modify source_path, or pass argument). | |
# Under it, put all the platform directories: | |
# MacOSX.platform iPhoneOS.platform iPhoneSimulator.platform | |
# Under those, store the SDKs: | |
# MacOSX10.4u.sdk MacOSX10.5.sdk MacOSX10.6.sdk MacOSX10.7.sdk MacOSX10.8.sdk | |
# | |
# After upgrading Xcode, just run link-sdks. | |
# | |
# This script is based upon the script at https://gist.github.com/rnapier/3370649 | |
import argparse | |
import subprocess | |
import os | |
# Load the command-line options | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--sdksPath', help='path to SDKs', nargs=1) | |
parser.add_argument('--xcodePath', help='path to Xcode', nargs=1) | |
args = parser.parse_args() | |
# Parse out the destination path | |
if args.xcodePath: | |
dest_path = args.xcodePath[0] | |
else: | |
dest_path = subprocess.check_output(['xcode-select', '--print-path']).rstrip() | |
if not dest_path.endswith('/Contents/Developer'): | |
dest_path += '/Contents/Developer' | |
# Clean up any broken links | |
subprocess.call('find -L "%(dest_path)s/Platforms/"*"/Developer/SDKs" -type l -depth 1 -exec sudo rm -v {} \\;' % locals(), shell=True) | |
# Parse out the source path | |
if args.sdksPath: | |
source_path = args.sdksPath[0] | |
else: | |
source_path = subprocess.check_output(['brew', '--prefix']).rstrip() | |
if source_path: | |
source_path += '/share/legacy-sdks' | |
if not source_path or not os.path.isdir(source_path): | |
source_path = '/Applications/Developer/SDKs' | |
# Link the SDKs and patch the Info.plist | |
if os.path.isdir(source_path): | |
for platform in os.listdir(source_path): | |
if (platform.endswith('.platform')): | |
for sdk in os.listdir(source_path + '/' + platform + '/'): | |
print('Linking %(sdk)s' % locals()) | |
if (sdk.endswith('.sdk')): | |
subprocess.call('sudo ln -sfn "%(source_path)s/%(platform)s/%(sdk)s" "%(dest_path)s/Platforms/%(platform)s/Developer/SDKs/%(sdk)s"' % locals(), shell=True) | |
FNULL = open(os.devnull, 'w') | |
subprocess.call('sudo /usr/libexec/PlistBuddy -c "Delete :MinimumSDKVersion" "%(dest_path)s/Platforms/%(platform)s/Info.plist"' % locals(), shell=True, stderr=FNULL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment