Class: BB::PodUtils
- Inherits:
-
Object
- Object
- BB::PodUtils
- Defined in:
- lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb
Class Method Summary collapse
-
.above_xcode_16_version ⇒ Object
xcode16以上.
-
.above_xcode_26_version ⇒ Object
xcode26以上.
-
.below_xcode_15_version ⇒ Object
xcode15以下.
-
.below_xcode_16_version ⇒ Object
xcode16以下.
-
.below_xcode_26_version ⇒ Object
xcode26以下.
-
.compare_xcode_14_version ⇒ Object
xcode14以上,14以后不再支持armv7(32位设备).
-
.compare_xcode_15_version ⇒ Object
xcode15以上.
-
.getInfoPlistPath ⇒ Object
获取info配置文件路径.
-
.getProjectBundleIdentifier ⇒ Object
获取包名.
-
.getProjectDevelopmentTeam ⇒ Object
证书团队id.
-
.getProjectPath ⇒ Object
获取工程路径.
-
.getProjectRootPath ⇒ Object
获取工程根目录路径.
-
.getValueFromInfoPlist(key) ⇒ Object
获取info配置key对应的值.
-
.getXcodeprojPath ⇒ Object
xcode目录.
-
.xcode_version ⇒ Object
获取Xcode版本.
Class Method Details
.above_xcode_16_version ⇒ Object
xcode16以上
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 187 def self.above_xcode_16_version current_version = xcode_version if current_version.nil? puts "未找到安装的Xcode版本。".red else puts "当前Xcode版本:#{current_version}" num_ver = current_version.to_i return num_ver >= 16 end return false end |
.above_xcode_26_version ⇒ Object
xcode26以上
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 203 def self.above_xcode_26_version current_version = xcode_version if current_version.nil? puts "未找到安装的Xcode版本。".red else puts "当前Xcode版本:#{current_version}" num_ver = current_version.to_i return num_ver >= 26 end return false end |
.below_xcode_15_version ⇒ Object
xcode15以下
167 168 169 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 167 def self.below_xcode_15_version return !compare_xcode_15_version end |
.below_xcode_16_version ⇒ Object
xcode16以下
183 184 185 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 183 def self.below_xcode_16_version return !above_xcode_16_version end |
.below_xcode_26_version ⇒ Object
xcode26以下
199 200 201 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 199 def self.below_xcode_26_version return !above_xcode_26_version end |
.compare_xcode_14_version ⇒ Object
xcode14以上,14以后不再支持armv7(32位设备)
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 155 def self.compare_xcode_14_version current_version = xcode_version if current_version.nil? puts "未找到安装的Xcode版本。".red else puts "当前Xcode版本:#{current_version}" num_ver = current_version.to_i return num_ver >= 14 end return false end |
.compare_xcode_15_version ⇒ Object
xcode15以上
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 171 def self.compare_xcode_15_version current_version = xcode_version if current_version.nil? puts "未找到安装的Xcode版本。".red else puts "当前Xcode版本:#{current_version}" num_ver = current_version.to_i return num_ver >= 15 end return false end |
.getInfoPlistPath ⇒ Object
获取info配置文件路径
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 75 def self.getInfoPlistPath # 1) 优先通过主 App Target 的 build setting `INFOPLIST_FILE` 获取(最准确) begin project = Xcodeproj::Project.open(getXcodeprojPath) app_targets = project.targets.select { |t| t.product_type == "com.apple.product-type.application" } if !app_targets.empty? target = app_targets.find { |t| !t.name.include?("Extension") && !t.name.include?("Tests") } || app_targets.first config = target.build_configurations.find { |c| c.name == "Release" } || target.build_configurations.first plist_rel = config&.build_settings&.[]('INFOPLIST_FILE') if plist_rel && !plist_rel.to_s.strip.empty? plist_rel = plist_rel.to_s.gsub('"', '') project_dir = File.dirname(getXcodeprojPath) plist_path = File.(plist_rel, project_dir) if File.exist?(plist_path) # puts "Info.plist(主Target): #{plist_path}".yellow return plist_path end end end rescue => e puts "解析主 Target Info.plist 失败,fallback 到扫描。原因: #{e}".yellow end # 2) 兼容旧逻辑:如果工程内存在固定位置则使用 path = File.join(getProjectPath, "bbframework/Resources/Info.plist") if File.exist?(path) return path end # 3) 最后 fallback:递归扫描(存在 Extension/Test 时可能拿错,所以放最后) info_path = "" search_dir = getProjectPath Find.find(search_dir) do |path| name = File.basename(path) if FileTest.directory?(path) && (name == 'Pods' || name.include?('.xcodeproj') || name.include?('Tests')) Find.prune elsif FileTest.file?(path) && name.end_with?('Info.plist') puts "Info.plist 文件路径:#{path}" info_path = path end end if File.exist?(info_path) return info_path end # puts "无法找到工程Info.plist配置文件,工程目录:#{getProjectPath} @hm确认".red return nil end |
.getProjectBundleIdentifier ⇒ Object
获取包名
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 33 def self.getProjectBundleIdentifier projectBundleIdentifierKey = "PRODUCT_BUNDLE_IDENTIFIER" value = getValueFromInfoPlist(projectBundleIdentifierKey) if #{value} == #{projectBundleIdentifierKey} project = Xcodeproj::Project.open(getXcodeprojPath) project.targets.each do |target| target.build_configurations.each do |config| value = config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] if value && !value.empty? break end end if value && !value.empty? break end end puts "xcodeproj BundleIdentifier:#{value}" return value else puts "info BundleIdentifier:#{value}" return value end end |
.getProjectDevelopmentTeam ⇒ Object
证书团队id
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 58 def self.getProjectDevelopmentTeam value = "" project = Xcodeproj::Project.open(getXcodeprojPath) project.targets.each do |target| target.build_configurations.each do |config| value = config.build_settings['DEVELOPMENT_TEAM'] if value && !value.empty? # 做你的处理 break end end end puts "xcodeproj DevelopmentTeam:#{value}" return value end |
.getProjectPath ⇒ Object
获取工程路径
18 19 20 21 22 23 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 18 def self.getProjectPath path = Dir.pwd # puts "Project Path:#{path}".yellow raise Informative, "#{path} File no exist, please check" unless File.exist?(path) return path end |
.getProjectRootPath ⇒ Object
获取工程根目录路径
11 12 13 14 15 16 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 11 def self.getProjectRootPath path = File.("..", getProjectPath) # puts "Project Root Path:#{path}".red raise Informative, "#{path} File no exist, please check" unless File.exist?(path) return path end |
.getValueFromInfoPlist(key) ⇒ Object
获取info配置key对应的值
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 127 def self.getValueFromInfoPlist(key) plistPath = getInfoPlistPath if !plistPath.nil? # PlistBuddy 读取根节点键:`Print :Key`;同时路径要带引号 print_key = key.to_s.start_with?(":") ? key.to_s : ":#{key}" value = `/usr/libexec/PlistBuddy -c "Print #{print_key}" "#{plistPath}" 2>/dev/null` value = value.rstrip() puts "#{key} => #{value} (plist: #{plistPath})" return value end return "" end |
.getXcodeprojPath ⇒ Object
xcode目录
25 26 27 28 29 30 31 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 25 def self.getXcodeprojPath name = Dir.glob("*.xcodeproj")[0] path = File.join(getProjectPath, name) # puts "xcodeproj:#{path}" raise Informative, "#{path} File no exist, please check" unless File.exist?(path) return path end |
.xcode_version ⇒ Object
获取Xcode版本
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb', line 140 def self.xcode_version xcode_version_output = `xcode-select -p` return nil if xcode_version_output.empty? xcode_path = xcode_version_output.chomp version_output = `xcodebuild -version` # Extract the Xcode version number version_match = version_output.match(/Xcode (\d+(\.\d+)+)/) return nil if version_match.nil? xcode_version = version_match[1] return xcode_version end |