ruby 快速修复所有Xcode SDK问题。当您更新Xcode时,只需运行此脚本即可。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 快速修复所有Xcode SDK问题。当您更新Xcode时,只需运行此脚本即可。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env ruby

# fix-xcode
#   Mark Rickert <mjar81@gmail.com>

# 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

以上是关于ruby 快速修复所有Xcode SDK问题。当您更新Xcode时,只需运行此脚本即可。的主要内容,如果未能解决你的问题,请参考以下文章

如何修复一些 Xcode 13 错误,例如无法正确跳转到定义?

iOS Xcode及模拟器SDK下载

AppDelegate 应用程序功能中的 Facebook SDK 错误,即使在 Xcode 6.3 中更新了 Facebook

Xcode 12 更新后快速运行 MLModel 的新错误

AWS Ruby SDK - 删除应用程序和所有相关环境

如何修复Facebook SDK“不包含bitcode”错误?