Skip to content

Instantly share code, notes, and snippets.

@bnickel
Forked from rnapier/fix-xcode
Last active August 29, 2015 14:08
Show Gist options
  • Save bnickel/8caae9f45ca83954bb5f to your computer and use it in GitHub Desktop.
Save bnickel/8caae9f45ca83954bb5f to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# fix-xcode
# Rob Napier <[email protected]>
# Script to link in all your old SDKs every time you upgrade Xcode
# Create a directory called /SDKs (or modify source_path).
# 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 fix-xcode.
import argparse
import subprocess
import os
source_path = "/SDKs"
parser = argparse.ArgumentParser()
parser.add_argument('xcodePath', help='path to Xcode', nargs='?')
args = parser.parse_args()
if args.xcodePath:
dest_path = args.xcodePath
else:
dest_path = subprocess.check_output(["xcode-select", "--print-path"]).rstrip().rstrip("/")
if not dest_path.endswith("/Contents/Developer"):
dest_path += "/Contents/Developer"
for platform in os.listdir(source_path):
subprocess.call("sudo ln -sf %(source_path)s/%(platform)s/* %(dest_path)s/Platforms/%(platform)s/Developer/SDKs" % locals(), shell=True)
#!/usr/bin/python
# save-xcode-sdks
# Brian Nickel <[email protected]>
# Script to save your current SDKs before you upgrade Xcode.
# SDKs are saved in /SDKs according to their target platform.
# E.g., the iOS 8.0 device SDK will get placed in /SDKs/iPhoneOS.platform/iPhoneOS8.0.sdk
#
# Before upgrading Xcode, run save-xcode-sdks.
# After upgrading Xcode, run fix-xcode.
#
# For both programs, you can supply a path pointing to a specific Xcode path.
# Otherwise, Xcode is selected from `xcode-select --print-path`.
import argparse
import subprocess
import os
dest_path = "/SDKs"
platforms = ["MacOSX", "iPhoneOS", "iPhoneSimulator"]
parser = argparse.ArgumentParser()
parser.add_argument('xcodePath', help='path to Xcode', nargs='?')
args = parser.parse_args()
if args.xcodePath:
source_path = args.xcodePath
else:
source_path = subprocess.check_output(["xcode-select", "--print-path"]).rstrip().rstrip("/")
if not source_path.endswith("/Contents/Developer"):
source_path += "/Contents/Developer"
sdk_count = 0
for platform_name in platforms:
platform = "%s.platform" % platform_name
dest_sdk_path = "%(dest_path)s/%(platform)s" % locals()
source_sdk_path = "%(source_path)s/Platforms/%(platform)s/Developer/SDKs" % locals()
subprocess.call("sudo mkdir -p %s" % dest_sdk_path, shell=True)
for sdk in os.listdir(source_sdk_path):
has_version = any(char.isdigit() for char in sdk)
if has_version and not os.path.exists("/%s/%s" % (dest_sdk_path, sdk)):
print "Copying %s..." % sdk
real_path = os.path.realpath("%(source_sdk_path)s/%(sdk)s" % locals())
subprocess.call("sudo cp -a %(real_path)s %(dest_sdk_path)s/%(sdk)s" % locals(), shell=True)
sdk_count += 1
print "Copied %d SDKs" % sdk_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment