Skip to content

Commit

Permalink
[iOS] [macOS] Prompt dev to create symlink to platform SDK with expli…
Browse files Browse the repository at this point in the history
…cit version if it doesn't exist.

Starting in Xcode 15.0.1, the SDK directories no longer have a
directory with an explicit version number.

For example:

Before 15.0.1:

- MacOSX.platform:
  Root platform dir: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  Sub-directories:
  - MacOSX.sdk
  - MacOSX14.0.sdk

- iPhoneOS.platform:
  Root platform dir: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
  Sub-directories:
  - iPhoneOS.sdk
  - iPhoneOS17.0.sdk

- iPhoneSimulator.platform:
  Root platform dir: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
  Sub-directories:
  - iPhoneSimulator.sdk
  - iPhoneSimulator17.0.sdk

After:

- MacOSX.platform:
  Root platform dir: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  Sub-directories:
  - MacOSX.sdk

- iPhoneOS.platform:
  Root platform dir: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
  Sub-directories:
  - iPhoneOS.sdk

- iPhoneSimulator.platform:
  Root platform dir: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
  Sub-directories:
  - iPhoneSimulator.sdk

The initialization of XcodeConfig checks for the SDK directories with
an explicit version name. If it doesn't exist, the developer is
prompted to create a symlink. This isn't explicitly run in case `sudo`
is needed.
  • Loading branch information
amirrajan committed Dec 26, 2023
1 parent 98caa03 commit f712b7a
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions motion/project/xcode_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,63 @@ def initialize(project_dir, build_mode)
@vendor_projects = []
@version = '1.0'
@swift_version = `xcrun swift -version`.strip.match(/Apple Swift version ([\d\.]+)/)[1]
XcodeConfig.check_for_sdk_dir_with_explicit_version(xcode_developer_dir: xcode_dir, platform_names: self.platforms)
end

def XcodeConfig.check_for_sdk_dir_with_explicit_version(xcode_developer_dir:, platform_names:)
platform_names.each do |platform|
sdk_version = get_sdk_version(xcode_developer_dir: xcode_developer_dir,
platform_name: platform)
without_version_dir = sdk_dir_without_version(xcode_developer_dir: xcode_developer_dir,
platform_name: platform)
with_version_dir = sdk_dir_with_version(xcode_developer_dir: xcode_developer_dir,
platform_name: platform)
if !Dir.exist?(with_version_dir) && Dir.exist?(without_version_dir)
App.fail <<~S
* ERROR: Explicit SDK directory required.
Please run the following command to create an explicitly named SDK directory (you may need to use sudo):
ln -s #{without_version_dir} #{with_version_dir}
S
end
end
end

def XcodeConfig.sdk_dir_without_version(xcode_developer_dir:, platform_name:)
xcode_developer_dir = File.expand_path(xcode_developer_dir)
sdk_dir = File.join(xcode_developer_dir, "Platforms/#{platform_name}.platform/Developer/SDKs/#{platform_name}.sdk")
end

def XcodeConfig.sdk_dir_with_version(xcode_developer_dir:, platform_name:)
xcode_developer_dir = File.expand_path(xcode_developer_dir)
version = get_sdk_version(xcode_developer_dir: xcode_developer_dir, platform_name: platform_name)
sdk_dir = File.join(xcode_developer_dir, "Platforms/#{platform_name}.platform/Developer/SDKs/#{platform_name}#{version}.sdk")
end

def XcodeConfig.sdk_settings_path(xcode_developer_dir:, platform_name:)
xcode_developer_dir = File.expand_path(xcode_developer_dir)
platform_dir = File.join(xcode_developer_dir, "Platforms/#{platform_name}.platform")
sdk_settings_path = File.join(platform_dir, "Developer", "SDKs", "#{platform_name}.sdk", "SDKSettings.plist")
sdk_settings_path
end

def XcodeConfig.get_sdk_version(xcode_developer_dir:, platform_name:)
xcode_developer_dir = File.expand_path(xcode_developer_dir)
platform_dir = File.join(xcode_developer_dir, "Platforms/#{platform_name}.platform")
sdk_settings_path = File.join(platform_dir, "Developer", "SDKs", "#{platform_name}.sdk", "SDKSettings.plist")
if !File.exist?(sdk_settings_path)
puts <<~S
* ERROR: SDKSettings.plist not found.
Looking for SDKSettings.plist at #{sdk_settings_path}
XCode may be incorrectly installed. Please try reinstalling XCode.
S
exit 1
end
plist_buddy_cmd = "/usr/libexec/PlistBuddy -c \"Print :Version\" #{sdk_settings_path}"
sdk_version = `#{plist_buddy_cmd}`.strip
sdk_version
end

def xcode_dir=(xcode_dir)
Expand Down Expand Up @@ -328,6 +385,24 @@ def platform_dir(platform)
File.join(platforms_dir, platform + '.platform')
end

def XcodeConfig.derived_sdk_version(xcode_developer_dir:, platform_name:)
xcode_developer_dir = File.expand_path(xcode_developer_dir)
platform_dir = File.join(xcode_developer_dir, "Platforms/#{platform_name}.platform")
sdk_settings_path = File.join(platform_dir, "Developer", "SDKs", "#{platform_name}.sdk", "SDKSettings.plist")
if !File.exist?(sdk_settings_path)
puts <<~S
* ERROR: SDKSettings.plist not found.
Looking for SDKSettings.plist at #{sdk_settings_path}
XCode may be incorrectly installed. Please try reinstalling XCode.
S
exit 1
end
plist_buddy_cmd = "/usr/libexec/PlistBuddy -c \"Print :Version\" #{sdk_settings_path}"
sdk_version = `#{plist_buddy_cmd}`.strip
sdk_version
end

def sdk_version
@sdk_version ||= begin
versions = Dir.glob(File.join(platforms_dir, "#{deploy_platform}.platform/Developer/SDKs/#{deploy_platform}[1-9]*.sdk")).sort.map do |path|
Expand Down

0 comments on commit f712b7a

Please sign in to comment.