From f712b7a21d4aa5b4765783720126f50a2ff7d781 Mon Sep 17 00:00:00 2001 From: Amir Rajan Date: Mon, 25 Dec 2023 19:45:56 -0600 Subject: [PATCH] [iOS] [macOS] Prompt dev to create symlink to platform SDK with explicit 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. --- motion/project/xcode_config.rb | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/motion/project/xcode_config.rb b/motion/project/xcode_config.rb index 43b4cbf..063a71b 100644 --- a/motion/project/xcode_config.rb +++ b/motion/project/xcode_config.rb @@ -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) @@ -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|