Module: Pindo::XcodeBuildHelper
- Included in:
- Command::Deploy::Configproj, Command::Ipa::Import, Command::Ipa::Output
- Defined in:
- lib/pindo/module/xcode/xcodebuildhelper.rb
Instance Method Summary collapse
- #backup_podfile_lock(project_dir: nil, app_config_dir: nil, appversion: nil) ⇒ Object
- #install_google_plist(project_dir: nil, app_config_dir: nil) ⇒ Object
- #modify_info_plist(project_dir: nil, proj_name: nil, config_json: nil) ⇒ Object
- #modify_infoplist_version(plist_file_name: nil, config_json: nil, target_name: nil) ⇒ Object
- #modify_maintarget_info_plist(plist_file_name: nil, config_json: nil, target_name: nil) ⇒ Object
- #modify_project_config(project_dir: nil, proj_name: nil, config_json: nil) ⇒ Object
- #pull_podfile_lock(project_dir: nil, app_config_dir: nil) ⇒ Object
Instance Method Details
#backup_podfile_lock(project_dir: nil, app_config_dir: nil, appversion: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pindo/module/xcode/xcodebuildhelper.rb', line 44 def backup_podfile_lock(project_dir:nil, app_config_dir:nil, appversion:nil) begin proj_pod_file = File.join(project_dir, "Podfile.lock") FileUtils.cp_r(proj_pod_file, File.join(app_config_dir, "Podfile.lock")) git_addpush_repo(path:app_config_dir, message:"#{appversion} backup podfile.lock", commit_file_params:["Podfile.lock"]) bytes = File.binread(proj_pod_file) checksum = Digest::MD5.hexdigest(bytes) build_verify_file = File.join(app_config_dir, "build_verify.json") build_verify_json = nil begin build_verify_json = JSON.parse(File.read(build_verify_file)) rescue => error end build_verify_json = build_verify_json || {} build_verify_json["output_code_commit"] = git_latest_commit_id(local_repo_dir:project_dir) build_verify_json["output_config_commit"] = git_latest_commit_id(local_repo_dir:app_config_dir) build_verify_json["output_podfile_checksum"] = checksum build_verify_json["output_time"] = Time.now.strftime('%y/%m/%d %H:%M:%S') File.open(build_verify_file, "w") do |file| file.write(JSON.pretty_generate(build_verify_json)) file.close end git_addpush_repo(path:app_config_dir, message:"backup #{appversion} output info", commit_file_params:["build_verify.json"]) rescue => error raise Informative, "保存Podfile.lock 文件失败!!!" end end |
#install_google_plist(project_dir: nil, app_config_dir: nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pindo/module/xcode/xcodebuildhelper.rb', line 76 def install_google_plist(project_dir:nil, app_config_dir:nil) project_fullname = Dir.glob(File.join(project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} project_obj = Xcodeproj::Project.open(project_fullname) select_target = project_obj.targets.select { |target| target.product_type.include?(Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application]) }.first file_ref = select_target.resources_build_phase.files_references.select { |file| file.display_name.include?("GoogleService-Info.plist") }.first if !file_ref.nil? xcode_googleinfo_path = file_ref.real_path if !File.exist?(File.join(app_config_dir, "GoogleService-Info.plist")) raise Informative, "缺少 GoogleService-Info.plist ==> #{app_config_dir}!!!" else FileUtils.cp(File.join(app_config_dir, "GoogleService-Info.plist"), xcode_googleinfo_path) end if !File.exist?(xcode_googleinfo_path) raise Informative, "拷贝 GoogleService-Info.plist 失败!!==> #{xcode_googleinfo_path}!!!" end end end |
#modify_info_plist(project_dir: nil, proj_name: nil, config_json: nil) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/pindo/module/xcode/xcodebuildhelper.rb', line 287 def modify_info_plist(project_dir:nil, proj_name:nil, config_json:nil) ## Main Info.plist proj_fullname = File.join(project_dir, proj_name) + ".xcodeproj" project_obj = Xcodeproj::Project.open(proj_fullname) info_plist_path = nil project_obj.targets.each do |target| temp_info = target.build_configurations.first.build_settings['INFOPLIST_FILE'] if !temp_info.nil? info_plist_path = File.join(project_dir, temp_info) end # if target.product_type.to_s.eql?("com.apple.product-type.application") && !File.exist?(info_plist_path) # info_plist_array = Dir.glob(File.join(project_dir, target.name, "**", "Info.plist")) # if info_plist_array.size == 1 # info_plist_path = info_plist_array.first # else # raise Informative, "Missing Target #{target.name.to_s} Info.plist !!! Modify Info.plist Error !!!" # end # end if target.product_type.to_s.eql?("com.apple.product-type.application") && (info_plist_path.nil? || !File.exist?(info_plist_path)) raise Informative, "Target #{target.name.to_s} 没有找到Info.plist, 修改Info.plist出错了!!" end if target.product_type.to_s.eql?("com.apple.product-type.application") then modify_maintarget_info_plist(plist_file_name:info_plist_path, config_json:config_json, target_name:proj_name) end modify_infoplist_version(plist_file_name:info_plist_path, config_json:config_json, target_name:target.name.to_s) end end |
#modify_infoplist_version(plist_file_name: nil, config_json: nil, target_name: nil) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/pindo/module/xcode/xcodebuildhelper.rb', line 140 def modify_infoplist_version(plist_file_name:nil, config_json:nil, target_name:nil) if File.exist?(plist_file_name) info_plist_dict = Xcodeproj::Plist.read_from_path(plist_file_name) info_plist_dict["CFBundleIdentifier"] = "$(PRODUCT_BUNDLE_IDENTIFIER)" exe_binary_name = config_json['app_info']["app_display_name"] exe_binary_name = exe_binary_name.gsub(/ /, ''); exe_binary_name = exe_binary_name.gsub(/\'/, ''); info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["app_display_name"] if !info_plist_dict["CFBundleName"].nil? info_plist_dict["CFBundleName"] = exe_binary_name end if config_json['app_info']["imessage_display_name"] && target_name && target_name.end_with?("iMessage") info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["imessage_display_name"] end if config_json['app_info']["extension_display_name"] && target_name && target_name.end_with?("Extension") info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["extension_display_name"] end if config_json['app_info']["extensionad_display_name"] && target_name && target_name.end_with?("ExtensionAd") info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["extensionad_display_name"] end if config_json['app_info']["extensionporn_display_name"] && target_name && target_name.end_with?("ExtensionPorn") info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["extensionporn_display_name"] end if config_json['app_info']["keyboard_display_name"] && target_name && target_name.end_with?("Keyboard") info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["keyboard_display_name"] end if config_json['app_info']["siri_display_name"] && target_name && target_name.end_with?("Keyboard") info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["siri_display_name"] end if config_json['app_info']["siriui_display_name"] && target_name && target_name.end_with?("iMessage") info_plist_dict["CFBundleDisplayName"] = config_json['app_info']["siriui_display_name"] end unless config_json['app_info']["app_version"] raise Informative, "config.json Missing app_info app_version !!!" end info_plist_dict["CFBundleShortVersionString"] = config_json['app_info']["app_version"] unless config_json['app_info']["app_build_version"] raise Informative, "config.json Missing app_info app_build_version !!!" end info_plist_dict["CFBundleVersion"] = config_json['app_info']["app_build_version"] Xcodeproj::Plist.write_to_path(info_plist_dict, plist_file_name) end end |
#modify_maintarget_info_plist(plist_file_name: nil, config_json: nil, target_name: nil) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/pindo/module/xcode/xcodebuildhelper.rb', line 201 def modify_maintarget_info_plist(plist_file_name:nil, config_json:nil, target_name:nil) if File.exist?(plist_file_name) info_plist_dict = Xcodeproj::Plist.read_from_path(plist_file_name) info_plist_dict.delete("AccountKitClientToken") if info_plist_dict["Fabric"] info_plist_dict.delete('Fabric') end if info_plist_dict["UIRequiredDeviceCapabilities"] && !info_plist_dict["UIRequiredDeviceCapabilities"].first.nil? && info_plist_dict["UIRequiredDeviceCapabilities"].first == "armv7" raise Informative, "Info.plist里面有多余的Key UIRequiredDeviceCapabilities armv7" end if !config_json['app_info']['admob_app_id'].nil? && config_json['app_info']['admob_app_id'].include?("__________config") raise Informative, "config.json 配置文件key :admob_app_id 包含初始值未修改, 配置正确的值或者删除!!!" end if !info_plist_dict["GADApplicationIdentifier"].nil? && config_json['app_info']['admob_app_id'].nil? raise Informative, "工程Info.plist中有 Admob 配置,config.json缺少 Admob 配置参数!!!" end if !config_json['app_info']['admob_app_id'].nil? info_plist_dict["GADApplicationIdentifier"] = config_json['app_info']['admob_app_id'] end if !config_json['app_info']['applovin_app_id'].nil? && config_json['app_info']['applovin_app_id'].include?("__________config") raise Informative, "config.json 配置文件key :applovin_app_id 包含初始值未修改, 配置正确的值或者删除!!!" end if !info_plist_dict["AppLovinSdkKey"].nil? && config_json['app_info']['applovin_app_id'].nil? raise Informative, "工程Info.plist中有 AppLovin 配置,config.json缺少 AppLovin 配置参数!!!" end if !info_plist_dict["AppLovinSdkKey"].nil? && !config_json['app_info']['applovin_app_id'].nil? info_plist_dict["AppLovinSdkKey"] = config_json['app_info']['applovin_app_id'] else info_plist_dict.delete('AppLovinSdkKey') end # if config_json['app_setting'] && config_json['app_setting']['applovin_app_id'] # info_plist_dict["AppLovinSdkKey"] = config_json['app_setting']['applovin_app_id'] # elsif config_json['app_setting'] && config_json['app_setting']['kGUKeyApplovinAppId'] # info_plist_dict["AppLovinSdkKey"] = config_json['app_setting']['kGUKeyApplovinAppId'] # else # info_plist_dict.delete('AppLovinSdkKey') # end info_plist_dict["CFBundleURLTypes"] = [] item0 = {} item0["CFBundleTypeRole"] = "Editor" item0["CFBundleURLName"] = "$(PRODUCT_BUNDLE_IDENTIFIER)" item0["CFBundleURLSchemes"] = [] item0["CFBundleURLSchemes"] << "$(PRODUCT_BUNDLE_IDENTIFIER)" info_plist_dict["CFBundleURLTypes"] << item0 if config_json['app_info'] && config_json['app_info']['facebook_app_id'] info_plist_dict["FacebookAppID"] = config_json['app_info']['facebook_app_id'] if config_json['app_info']['facebook_client_token'].nil? raise Informative, "config.json FB Token 是空的" end info_plist_dict["FacebookClientToken"] = config_json['app_info']['facebook_client_token'] info_plist_dict["FacebookDisplayName"] = config_json['app_info']['app_display_name'] item1 = {} item1["CFBundleTypeRole"] = "Editor" item1["CFBundleURLSchemes"] = [] item1["CFBundleURLSchemes"] << "fb" + config_json['app_info']['facebook_app_id'] info_plist_dict["CFBundleURLTypes"] << item1 else info_plist_dict.delete('FacebookAppID') info_plist_dict.delete('FacebookClientToken') info_plist_dict.delete('FacebookDisplayName') end Xcodeproj::Plist.write_to_path(info_plist_dict, plist_file_name) end end |
#modify_project_config(project_dir: nil, proj_name: nil, config_json: nil) ⇒ Object
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 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/pindo/module/xcode/xcodebuildhelper.rb', line 98 def modify_project_config(project_dir:nil, proj_name:nil, config_json:nil) proj_fullname = File.join(project_dir, proj_name) + ".xcodeproj" project_obj = Xcodeproj::Project.open(proj_fullname) ios_deployment_targe = "14.0" if config_json && config_json['project_info'] && config_json['project_info']['ios_deployment_targe'] ios_deployment_targe = config_json['project_info']['ios_deployment_targe'] end project_obj.targets.each do |target| exe_binary_name = config_json['app_info']['app_display_name'] exe_binary_name = exe_binary_name.gsub(/ /, ''); exe_binary_name = exe_binary_name.gsub(/\'/, ''); target.build_configurations.each do |config| config.build_settings['CURRENT_PROJECT_VERSION'] = config_json['app_info']['app_build_version'] config.build_settings['MARKETING_VERSION'] = config_json['app_info']['app_version'] config.build_settings['INFOPLIST_KEY_CFBundleDisplayName'] = config_json['app_info']['app_display_name'] end target_name_map = get_target_name_map if target.product_type.include?(Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application]) target.build_configurations.each do |config| config.build_settings['PRODUCT_NAME'] = exe_binary_name config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_targe end elsif target_name_map.each do |k, v| if target.name.to_s.end_with?(k) target.build_configurations.each do |config| config.build_settings['PRODUCT_NAME'] = exe_binary_name + k end end end end end project_obj.save end |
#pull_podfile_lock(project_dir: nil, app_config_dir: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pindo/module/xcode/xcodebuildhelper.rb', line 11 def pull_podfile_lock(project_dir:nil, app_config_dir:nil) begin src_pod_file = File.join(app_config_dir, "Podfile.lock") build_verify_file = File.join(app_config_dir, "build_verify.json") build_verify_json = nil begin build_verify_json = JSON.parse(File.read(build_verify_file)) rescue => error end build_verify_json = build_verify_json || {} build_verify_json["release_code_commit"] = git_latest_commit_id(local_repo_dir:project_dir) build_verify_json["release_config_commit"] = git_latest_commit_id(local_repo_dir:app_config_dir) bytes = File.binread(src_pod_file) checksum = Digest::MD5.hexdigest(bytes) build_verify_json["release_podfile_checksum"] = checksum build_verify_json["release_time"] = Time.now.strftime('%y/%m/%d %H:%M:%S') File.open(build_verify_file, "w") do |file| file.write(JSON.pretty_generate(build_verify_json)) file.close end git_addpush_repo(path:app_config_dir, message:"back release info", commit_file_params:["build_verify.json"]) if File.exist?(src_pod_file) FileUtils.cp_r(src_pod_file, File.join(project_dir, "Podfile.lock")) end rescue => error raise Informative, "获取Podfile.lock 文件失败!!!" end end |