Class: Fastlane::Actions::XcodeprojMergeAction
- Inherits:
-
BaseAction
- Object
- Action
- BaseAction
- Fastlane::Actions::XcodeprojMergeAction
- Defined in:
- lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb
Class Method Summary collapse
- .add_channel_badge(folder_path) ⇒ Object
- .add_channel_sdk_library ⇒ Object
- .add_channel_sdk_resources ⇒ Object
- .addFileToTarget(filename) ⇒ Object
- .build_app_action ⇒ Object
-
.clean_search_paths(setting_name, relative_path) ⇒ Object
封装通用处理逻辑.
- .createProjectFiles ⇒ Object
-
.getAllRes(rootDir) ⇒ Object
查询所有文件.
- .getDesgroup(resGroup) ⇒ Object
- .initData ⇒ Object
-
.isEmbedFramework(filename) ⇒ Object
是否在动态库集合.
- .merge_nygameinfo ⇒ Object
- .removeBuildPhaseFilesRecursively(aGroup) ⇒ Object
- .run(params) ⇒ Object
- .update_channel_config ⇒ Object
- .xcodeproj_merge ⇒ Object
Methods inherited from BaseAction
Class Method Details
.add_channel_badge(folder_path) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 390 def self.add_channel_badge(folder_path) xcassets_ref = nil storyboard_ref = nil appiconset_path = nil channel_icon_path = nil launch_image = nil lane_context[:target].resources_build_phase.files.each do |item| if item.file_ref.path.end_with?(".xcassets") appiconset_path = File.join(item.file_ref.real_path.to_s) puts "ZHUIXI---appiconset_path: #{appiconset_path}" FileUtils.cp_r(appiconset_path, File.join(lane_context[:zhuixi_path])) channel_icon_path = File.join(lane_context[:zhuixi_path], File.basename(appiconset_path)) xcassets_ref = item.file_ref end if item.file_ref.path.end_with?(".storyboard") launch_screen_path = File.join(item.file_ref.real_path.to_s) puts "ZHUIXI---launch_screen_path: #{launch_screen_path}" storyboard_ref = item.file_ref end if item.file_ref.path.include?("LaunchImage.png") puts "ZHUIXI---LaunchImage: #{item.file_ref.path}" launch_image = item.file_ref end end isLaunchImageIncluded = false subfolders = Dir.glob("#{folder_path}/*").select { |f| File.directory?(f) } is_launch_image_folder = subfolders.any? { |f| if f.include?("launchimage") isLaunchImageIncluded = true end } # Fastlane::Helper::ZhuixiBuildAppHelper.clean_storyboard_cache(storyboard_ref.real_path.to_s, lane_context[:selectPlatformName]) lane_context[:target].resources_build_phase.remove_file_reference(xcassets_ref) if xcassets_ref lane_context[:target].resources_build_phase.remove_file_reference(storyboard_ref) if storyboard_ref && isLaunchImageIncluded lane_context[:target].resources_build_phase.remove_file_reference(launch_image) if launch_image && isLaunchImageIncluded # 删除文件引用对应的文件 # xcassets_ref.remove_from_project if xcassets_ref storyboard_ref.remove_from_project if storyboard_ref && isLaunchImageIncluded launch_image.remove_from_project if launch_image && isLaunchImageIncluded channel_icon_ref = lane_context[:group].new_file(channel_icon_path) lane_context[:target].resources_build_phase.add_file_reference(channel_icon_ref) if channel_icon_ref badge_path = Fastlane::Helper::ZhuixiBuildAppHelper.get_badge_path(folder_path, lane_context[:selectPlatformName]) if File.exist?(badge_path) puts "ZHUIXI---角标路径:\n" + badge_path badge = MiniMagick::Image.open(badge_path) Dir.glob("#{channel_icon_path}/**/*.png").each do |image_path| puts "image_path: #{image_path}" image = MiniMagick::Image.open(image_path) height = image.height width = image.width result = image.composite(badge) do |c| c.compose "Over" c.gravity "SouthEast" c.resize "#{width}x#{height}" # 调整为原图大小 end result.write(image_path) end end end |
.add_channel_sdk_library ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 263 def self.add_channel_sdk_library() channel_resources_folder = File.join(lane_context[:zhuixi_path], "resources") add_channel_badge(channel_resources_folder) merge_nygameinfo() lane_context[:project].save getAllRes(channel_resources_folder) build_app_action() end |
.add_channel_sdk_resources ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 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 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 119 def self.add_channel_sdk_resources() # 设置DEBUG_INFORMATION_FORMAT lane_context[:target].build_configuration_list.build_configurations.each do |config| config.build_settings["DEBUG_INFORMATION_FORMAT"] = "dwarf" end # 获取 Info.plist 文件的 Build Setting info_plist_build_setting = lane_context[:target].build_configuration_list.get_setting("INFOPLIST_FILE") info_plist_path = info_plist_build_setting["Release"] info_plist_absolute_path = File.(info_plist_path, File.dirname(lane_context[:cha_project_path])) # 复制 Info.plist 文件到指定目录 FileUtils.cp(info_plist_absolute_path, File.join(lane_context[:zhuixi_path], "Info.plist")) # 2. 读取 info.plist 文件 info_plist_data = Plist.parse_xml(File.join(lane_context[:zhuixi_path], "Info.plist")) # 如果 info_plist_data 没有 LSApplicationQueriesSchemes 配置,先创建一个空数组 info_plist_data["LSApplicationQueriesSchemes"] ||= [] # 修改 Bundle Identifier 和 Display Name info_plist_data["CFBundleIdentifier"] = lane_context[:configParams]["gamePackageName"] info_plist_data["CFBundleDisplayName"] = lane_context[:configParams]["gamename"] info_plist_data["UILaunchStoryboardName"] = "LaunchScreen" # 3. 读取 TempInfo.plist 文件 temp_info_plist_data = Plist.parse_xml(File.join(lane_context[:zhuixi_path], "TempInfo.plist")) # # 添加 TempInfo.plist 中不存在的 LSApplicationQueriesSchemes 配置到 info.plist 文件 # temp_info_plist_data["LSApplicationQueriesSchemes"].each do |scheme| # info_plist_data["LSApplicationQueriesSchemes"] << scheme unless info_plist_data["LSApplicationQueriesSchemes"].include?(scheme) # end temp_info_plist_data.each do |key, value| info_plist_data[key] = value end # 5. 写入 info.plist 文件 File.write(File.join(lane_context[:zhuixi_path], "Info.plist"), info_plist_data.to_plist) config_info_plist_data = Plist.parse_xml(File.join(lane_context[:zhuixi_path], "ConfigInfo.plist")) system_frameworks = config_info_plist_data["systemFrameworks"] system_libraries = config_info_plist_data["systemLibraries"] # Add the system frameworks to the Xcode project unless system_frameworks.nil? || system_frameworks.empty? frameworks_group = lane_context[:project].frameworks_group # Find or create the "Frameworks" group system_frameworks.each do |framework| framework_path = "Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/#{framework}" unless ref = frameworks_group.find_file_by_path(framework_path) ref = frameworks_group.new_file(framework_path, :developer_dir) end unless lane_context[:target].frameworks_build_phase.include?(ref) lane_context[:target].frameworks_build_phase.add_file_reference(ref, true) end end end # Add the system libraries to the Xcode project unless system_libraries.nil? || system_libraries.empty? libraries_group = lane_context[:project].frameworks_group system_libraries.each do |library| libraries_path = "Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/#{library}" unless ref = libraries_group.files.find { |ref| ref.path == path } ref = libraries_group.new_file(libraries_path, :developer_dir) end unless lane_context[:target].frameworks_build_phase.include? (ref) lane_context[:target].frameworks_build_phase.add_file_reference(ref, true) end end end #设置渠道工程的info路径 lane_context[:target].build_configuration_list.build_configurations.each do |config| config.build_settings["INFOPLIST_FILE"] = File.join(lane_context[:zhuixi_path], "Info.plist") end #更新部分渠道配置文件 update_channel_config() lane_context[:project].save add_channel_sdk_library() end |
.addFileToTarget(filename) ⇒ Object
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 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 289 def self.addFileToTarget(filename) if filename != "." and filename != ".." and filename != ".DS_Store" # puts filename file_ref = lane_context[:group].new_reference(filename) if filename.to_s.end_with?("pbobjc.m", "pbobjc.mm") lane_context[:target].add_file_references(file_ref, "-fno-objc-arc") elsif filename.to_s.end_with?(".framework", ".a") lib_real_path = File::dirname(filename) if filename.to_s.end_with?(".framework") and !"".eql? lib_real_path config_list_fra = lane_context[:target].build_configuration_list.get_setting("FRAMEWORK_SEARCH_PATHS") old_fra_list = config_list_fra["Release"] if !old_fra_list || "$(inherited)".eql?(old_fra_list) old_fra_list = [] old_fra_list.push("$(inherited)") end old_fra_list.push(lib_real_path) lane_context[:target].build_configuration_list.set_setting("FRAMEWORK_SEARCH_PATHS", old_fra_list) end if filename.to_s.end_with?(".a") and !"".eql? lib_real_path config_list_lib = lane_context[:target].build_configuration_list.get_setting("LIBRARY_SEARCH_PATHS") old_lib_list = config_list_lib["Release"] if !old_lib_list || "$(inherited)".eql?(old_lib_list) old_lib_list = [] old_lib_list.push("$(inherited)") end old_lib_list.push(lib_real_path) lane_context[:target].build_configuration_list.set_setting("LIBRARY_SEARCH_PATHS", old_lib_list) end #项目中可能有多个copy files build phases,找到刚刚创建的那个,然后把xx.framework引入 if !"".eql? lib_real_path and isEmbedFramework(filename) = false lane_context[:target].copy_files_build_phases.each do |phase| if phase.name == "Embed Frameworks" = true phase.add_file_reference(file_ref) phase.dst_subfolder_spec = "10" phase.files.each do |file| file.settings = { "ATTRIBUTES" => ["CodeSignOnCopy", "RemoveHeadersOnCopy"] } end end end unless = lane_context[:target].new_copy_files_build_phase("Embed Frameworks") .dst_subfolder_spec = "10" .add_file_reference(file_ref) .files.each do |file| file.settings = { "ATTRIBUTES" => ["CodeSignOnCopy", "RemoveHeadersOnCopy"] } end end end lane_context[:target].frameworks_build_phase.add_file_reference(file_ref, true) elsif filename.to_s.end_with?(".plist", ".bundle", ".png", ".storyboard", ".json") lane_context[:target].resources_build_phase.add_file_reference(file_ref, true) elsif filename.to_s.end_with?(".m", ".mm", ".cpp") lane_context[:target].source_build_phase.add_file_reference(file_ref, true) # elsif (!filename.to_s.end_with?(".h")) # lane_context[:target].add_resources([file_ref]) end end end |
.build_app_action ⇒ Object
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 456 def self.build_app_action() other_action.recreate_schemes(project: lane_context[:cha_project_path]) schemefile = "" Find.find(File.join(lane_context[:cha_project_path], "xcuserdata")) do |schemefilepath| if schemefilepath.include? ".xcscheme" new_schemefilepath = File.join(File.dirname(schemefilepath), File.basename(schemefilepath, ".xcscheme") + "_" + lane_context[:platform_id].to_s + ".xcscheme") File.rename(schemefilepath, new_schemefilepath) schemefile = File.basename(new_schemefilepath, ".xcscheme") end end lane_context[:project].save() puts lane_context[:configParams] = Time.now.strftime("%Y%m%d%H%M%S") output_name = lane_context[:configParams]["gamename"] + "_" + lane_context[:platform_id].to_s + "_" + lane_context[:selectPlatformName] + "_" + other_action.gym( project: lane_context[:cha_project_path], output_name: output_name, export_method: lane_context[:export_method], # clean: true, silent: true, export_options: { provisioningProfiles: { lane_context[:configParams]["gamePackageName"] => lane_context[:provisioning_profile_name], }, }, ) end |
.clean_search_paths(setting_name, relative_path) ⇒ Object
封装通用处理逻辑
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 102 def self.clean_search_paths(setting_name, relative_path) search_paths = lane_context[:target].build_configuration_list.get_setting(setting_name) search_paths.each do |config, paths| if paths.is_a?(String) paths = [paths] end paths.delete_if { |path| path.include?(relative_path) } # 保存设置 lane_context[:target].build_configuration_list.set_setting(setting_name, paths) puts "Cleaned #{setting_name}: #{paths}" end end |
.createProjectFiles ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 25 def self.createProjectFiles initData() if (File::exist?(lane_context[:cha_project_path])) # FileUtils.remove_dir(destFile, force = false) FileUtils.remove_dir(lane_context[:cha_project_path], force = true) puts "渠道xcodeproj删除成功" + lane_context[:cha_project_path] # FileUtils.rm_rf(lane_context[:cha_project_path], :secure=>true) end Dir::mkdir(lane_context[:cha_project_path], mode = 0777) Dir.glob(File.join(lane_context[:ori_xcodeproj_path], "*")) do |file| unless File.basename(file) == "xcshareddata" # 检查是否在 Copy Bundle Resources 目录中 dest = File.join(lane_context[:cha_project_path], File.basename(file)) FileUtils.cp_r(file, dest) end end # FileUtils.cp(@ori_pbxproj_path, lane_context[:cha_project_path]) # FileUtils.cp_r(@ori_workspace_path, @cha_workspace_path) # FileUtils.cp_r(@ori_scheme_dir, lane_context[:cha_project_path]) unless File::exist?(lane_context[:cha_project_path]) puts "渠道创建失败" return end end |
.getAllRes(rootDir) ⇒ Object
查询所有文件
274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 274 def self.getAllRes(rootDir) isfile = rootDir.to_s.end_with?(".framework", ".bundle", ".png", ".storyboard", ".json") launchimage_path = lane_context[:configParams]["channel_orientation"] == "portrait" ? "launchimage-landscape" : "launchimage-portrait" if File.directory?(rootDir) and !isfile Dir.foreach(rootDir) do |filepath| if filepath != "." and filepath != ".." and filepath != ".DS_Store" and filepath != launchimage_path getAllRes(rootDir + "/" + filepath) end end else puts "ZHUIXI---文件路径:\n" + rootDir addFileToTarget(rootDir) end end |
.getDesgroup(resGroup) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 82 def self.getDesgroup(resGroup) resGroup.groups.each do |group| if group.display_name == "resources" lane_context[:cha_resources_path] = group.real_path removeBuildPhaseFilesRecursively(group) relative_path = group.real_path.to_s.sub(lane_context[:project].project_dir.to_s, "") puts "ZHUIXI---relative_path: #{relative_path}" # 调用 clean_search_paths("FRAMEWORK_SEARCH_PATHS", relative_path) clean_search_paths("LIBRARY_SEARCH_PATHS", relative_path) clean_search_paths("HEADER_SEARCH_PATHS", relative_path) group.clear else getDesgroup(group) end end end |
.initData ⇒ Object
53 54 55 56 57 58 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 53 def self.initData() ori_xcodeproj_dir = File::dirname(lane_context[:ori_xcodeproj_path]) ori_project_name_pre = File.basename(lane_context[:ori_xcodeproj_path], ".xcodeproj") cha_project_name = ori_project_name_pre + "_" + lane_context[:platform_id].to_s + ".xcodeproj" lane_context[:cha_project_path] = File.join(ori_xcodeproj_dir, cha_project_name) end |
.isEmbedFramework(filename) ⇒ Object
是否在动态库集合
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 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 231 def self.isEmbedFramework(filename) framework_path = filename.to_s framework_name = File.basename(framework_path, ".*") # 提取 .framework 文件的名称 # 在 .framework 目录中搜索与文件名相同的文件 file_path = Dir.glob("#{framework_path}/#{framework_name}").first if file_path.nil? UI.error("File not found for #{framework_name}.") return false end # 使用 file 命令查看文件类型 file_output = sh("file #{file_path}") # 检查文件类型中是否包含 "dynamic" 或 "shared",表示动态库 is_dynamic_library = file_output.include?("dynamic") || file_output.include?("shared") if is_dynamic_library # 文件是动态库 # 执行相应的操作 # ... puts "文件是动态库 #{framework_name}" return true else # 文件是静态库 # 执行其他操作 # ... puts "文件是静态库 #{framework_name}" return false end return false end |
.merge_nygameinfo ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 359 def self.merge_nygameinfo() channel_resources_folder = File.join(lane_context[:zhuixi_path], "resources") filepath = File.join(channel_resources_folder, "nygameinfo.plist") # channel_storyboard_path = File.join(channel_resources_folder, "LaunchScreen.storyboard") # Fastlane::Helper::ZhuixiBuildAppHelper.clean_storyboard_cache(channel_storyboard_path, lane_context[:selectPlatformName]) puts lane_context[:configParams] other_action.update_plist( plist_path: filepath, block: proc do |plist| if plist[:requestURL.to_s] plist.delete(:requestURL.to_s) end lane_context[:configParams].each do |key, value| case key when :gamename.to_s plist[:game_name.to_s] = value.to_s when :gameappid.to_s plist[:game_appid.to_s] = value.to_s when :gameid.to_s plist["game_id"] = value.to_s when :gameurl.to_s plist[:ff_url.to_s] = value.to_s else plist[key] = value.to_s end end end, ) end |
.removeBuildPhaseFilesRecursively(aGroup) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 60 def self.removeBuildPhaseFilesRecursively(aGroup) aGroup.files.each do |file| if file.real_path.to_s.end_with?(".m", ".mm") lane_context[:target].source_build_phase.remove_file_reference(file) elsif file.real_path.to_s.end_with?(".h") lane_context[:target].headers_build_phase.remove_file_reference(file) elsif file.real_path.to_s.end_with?(".plist", ".bundle", ".txt") lane_context[:target].resources_build_phase.remove_file_reference(file) elsif file.real_path.to_s.end_with?(".framework", ".a") lane_context[:target].frameworks_build_phase.remove_file_reference(file) lane_context[:target].copy_files_build_phases.each do |item| if item.name == "Embed Frameworks" item.remove_file_reference(file) end end end end aGroup.groups.each do |group| removeBuildPhaseFilesRecursively(group) end end |
.run(params) ⇒ Object
10 11 12 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 10 def self.run(params) xcodeproj_merge() end |
.update_channel_config ⇒ Object
199 200 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 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 199 def self.update_channel_config() if lane_context[:selectPlatformName] == "神起" vconfig_json = File.join( lane_context[:zhuixi_path], "resources", "SDKs", "VCConfig.json" ) json = JSON.parse(File.read(vconfig_json)) json["appId"] = lane_context[:configParams][:channel_appid.to_s] json["appKey"] = lane_context[:configParams][:channel_appkey.to_s] File.open(vconfig_json, "w") do |f| f.puts JSON.pretty_generate(json) end elsif lane_context[:selectPlatformName] == "奇界" other_action.update_plist( plist_path: lane_context[:zhuixi_path] + "/resources/SDKs/BRSDK.plist", block: proc do |plist| plist["direction"] = lane_context[:configParams][:channel_orientation.to_s] == "landscape" ? "2" : "1" end, ) elsif lane_context[:selectPlatformName] == "527" other_action.update_plist( plist_path: lane_context[:zhuixi_path] + "/resources/SDKs/QnAggSdkRes.bundle/Params.plist", block: proc do |plist| plist["appID"] = lane_context[:configParams][:channel_appid.to_s] plist["appKey"] = lane_context[:configParams][:channel_appkey.to_s] end, ) end end |
.xcodeproj_merge ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fastlane/plugin/zhuixi_build_app/actions/xcodeproj_merge_action.rb', line 14 def self.xcodeproj_merge() createProjectFiles() lane_context[:project] = Xcodeproj::Project.open(lane_context[:cha_project_path]) lane_context[:target] = lane_context[:project].targets.first lane_context[:group] = lane_context[:project].main_group.find_subpath(File.join("zhuixi"), true) lane_context[:group].set_source_tree("SOURCE_ROOT") # 把group的source_tree设置成 'SOURCE_ROOT' getDesgroup(lane_context[:project].main_group) # FileUtils.rm_rf(Dir.glob(File.join(lane_context[:cha_resources_path], "*"))) add_channel_sdk_resources() end |