-
-
Save vineetchoudhary/b09c3f40ca29d36c8863 to your computer and use it in GitHub Desktop.
Quick fix to all your Xcode SDK issues. When you update Xcode, just run this script and all is well.
This file contains hidden or 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/env ruby | |
# fix-xcode | |
# Mark Rickert <[email protected]> | |
# Symlinks all your old SDKs to Xcode.app every time it is updated. | |
# Create a directory called /SDKs and run this script. | |
# | |
# Each time you upgrade Xcode, run fix-xcode. | |
require 'FileUtils' | |
def main | |
# Find all the SDKs in Xcode.app that aren't symlinks. | |
Dir.glob("#{xcode_path}/Platforms/*.platform/Developer/SDKs/*.sdk") do |sdk| | |
basename = sdk.split('/').last | |
if File.symlink?(sdk) | |
puts "#{basename} is already symlinked... skipping.\n" | |
next | |
end | |
puts "Processing: #{basename}\n" | |
# Remove the old version if it exists | |
destination = "#{sdk_path}/#{basename}" | |
if File.directory?(destination) | |
puts " - Removing existing SDK: #{destination}.\n" | |
FileUtils.rm_rf destination | |
end | |
puts " - Moving the Xcode version into place in #{sdk_path}.\n" | |
FileUtils.mv sdk, sdk_path | |
end | |
Dir.glob("#{sdk_path}/*.sdk") do |sdk| | |
sdk_name = sdk.split("/").last | |
sdk_platform = sdk_name.match(/[a-zA-Z]{3,}/)[0] | |
ln_dest = "#{xcode_path}/Platforms/#{sdk_platform}.platform/Developer/SDKs/#{sdk_name}" | |
puts " - Symlinking #{sdk_platform}.\n" | |
FileUtils.ln_sf sdk, ln_dest | |
end | |
puts "\nDone! Your SDKs now live in #{sdk_path} and are symlinked properly into the Xcode.app.\n\n" | |
end | |
def xcode_path | |
`xcode-select --print-path`.chomp | |
end | |
def sdk_path | |
"/SDKs" | |
end | |
def remove_sdk version | |
# Remove the iOS SDK from xcode. | |
version = version.to_s << ".0" if version.to_s.length == 1 | |
puts "-" * 29 | |
puts "Removing the iOS #{version} SDK from the Xcode Bundle." | |
puts "-" * 29 | |
removing = "#{xcode_path}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS#{version}.sdk" | |
if File.exist? removing | |
FileUtils.rm_rf removing | |
puts "SDK successfully removed. Please restart Xcode." | |
else | |
puts "Couldn't find that SDK at path: #{removing}" | |
end | |
end | |
if ARGV.count == 2 | |
if ARGV[0] == "remove" | |
abort "Please pass another parameter specifying what SDK to remove." unless ARGV[1] | |
remove_sdk "#{ARGV[1]}" | |
end | |
else | |
puts "-" * 29 | |
puts "Running Fixing Xcode.app SDK Paths." | |
puts "-" * 29 | |
main | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks this saved my day