module Pod class PodTarget < Target alias_method :old_resource_paths, :resource_paths def resource_paths resource_paths = old_resource_paths # 没有使用二进制不处理 return resource_paths unless self.use_binary # 遍历所有的resources resource_paths.each do |name, resources| resources.map! {|resource_file| resource_extname = Pathname.new(resource_file).basename.extname # 如果文件不需要编译,跳过 next resource_file unless self.class.resource_extension_compilable?(resource_extname) # 确定编译后的文件名称 output_extname = self.class.output_extension_for_resource(resource_extname) output_file_name = "#{Pathname.new(resource_file).basename.sub_ext('')}#{output_extname}" # 从framework中查找编译后的文件 file_accessors.each do |file_accessor| file_accessor.vendored_frameworks.each do |framework_file| framework_name = Pathname.new(framework_file).basename.sub_ext('').to_s # 只处理和当前target module_name相同的framework,否则跳过 next if self.product_module_name != framework_name # xcframework和framework文件分别处理,而且只查找.framework根目录下的文件 if '.xcframework' == Pathname.new(framework_file).basename.extname files = Dir.glob("#{framework_file}/**/#{framework_name}.framework/#{output_file_name}") next if files.size == 0 # 没有查找到文件跳过 if Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0') resource_file = "${PODS_XCFRAMEWORKS_BUILD_DIR}/#{self.name}/#{framework_name}.framework/#{output_file_name}" else resource_file = "${PODS_CONFIGURATION_BUILD_DIR}/#{framework_name}.framework/#{output_file_name}" end else files = Dir.glob("#{framework_file}/#{output_file_name}") next if files.size == 0 # 没有查找到文件跳过 resource_path = Pathname.new("#{framework_file}/#{output_file_name}") # 真实路径 resource_file = "${PODS_ROOT}/#{resource_path.relative_path_from(self.sandbox.root)}" end end end resource_file }.reject!(&:nil?) end resource_paths end end class Target # @since 1.5.0 class BuildSettings # missing framework header search paths def missing_framework_header_search_path(pt) paths = [] pt.file_accessors.each do |file_accessor| # xcframeworks greater_than_or_equal_to_1_10_0 = Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0') greater_than_or_equal_to_1_11_0 = Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.11.0') file_accessor.vendored_xcframeworks.map { |path| if greater_than_or_equal_to_1_11_0 Xcode::XCFramework.new(file_accessor.spec.name, path) else Xcode::XCFramework.new(path) end }.each { |xcfwk| xcfwk.slices.each { |slice| fwk_name = slice.path.basename if greater_than_or_equal_to_1_11_0 paths.push "${PODS_XCFRAMEWORKS_BUILD_DIR}/#{xcfwk.target_name}/#{fwk_name}/Headers" elsif greater_than_or_equal_to_1_10_0 paths.push "${PODS_XCFRAMEWORKS_BUILD_DIR}/#{fwk_name.to_s.gsub(/\.framework$/, '')}/#{fwk_name}/Headers" else paths.push "${PODS_CONFIGURATION_BUILD_DIR}/#{fwk_name}/Headers" end } } # Cocoapods 1.9.x bugs if Gem::Version.new(Pod::VERSION) < Gem::Version.new('1.10.0') file_accessor.vendored_xcframeworks.each { |path| Dir.glob("#{path.to_s}/**/*.framework").each do |fwk_path| header_path = Pathname.new("#{fwk_path}/Headers") next unless header_path.exist? paths.push "${PODS_ROOT}/#{header_path.relative_path_from(pt.sandbox.root)}" end } end # frameworks (file_accessor.vendored_frameworks - file_accessor.vendored_xcframeworks).each { |framework| header_path = Pathname.new("#{framework}/Headers") next unless header_path.exist? paths.push "${PODS_ROOT}/#{header_path.relative_path_from(pt.sandbox.root)}" } end replace_xcconfig_configuration_paths(paths) paths.uniq end # replace different configuration xcconfig def replace_xcconfig_configuration_paths(paths) xcconfig_configuration_alias = Jxedt.config.xcconfig_configuration_alias support_configurations = Jxedt.config.support_configurations match_configuration = support_configurations.join('|') paths.map! { |path| if path =~ /#{xcconfig_configuration_alias}-(#{match_configuration})/ configuration = @configuration.to_s.downcase matchs = support_configurations.select {|name| name.downcase == configuration } path.gsub!(/#{xcconfig_configuration_alias}-(#{match_configuration})/, "#{xcconfig_configuration_alias}-#{matchs.first}") if matchs.count == 1 end path } paths end # A subclass that generates build settings for a `PodTarget` class AggregateTargetSettings # @return [Array] alias_method :old_raw_header_search_paths, :_raw_header_search_paths def _raw_header_search_paths header_search_paths = old_raw_header_search_paths header_search_paths.concat pod_targets.flat_map { |pt| search_paths = [] search_paths.concat missing_framework_header_search_path(pt) if pt.frame_header_search_paths_enable? search_paths } header_search_paths.uniq end end # A subclass that generates build settings for a {PodTarget} class PodTargetSettings # @return [Array] alias_method :old_raw_header_search_paths, :_raw_header_search_paths def _raw_header_search_paths header_search_paths = old_raw_header_search_paths # 两个条件都满足时添加header_search_paths header_search_paths.concat dependent_targets.flat_map { |pt| missing_framework_header_search_path(pt) } if target.should_build? && target.frame_header_search_paths_enable? header_search_paths.uniq end # 按照规则替换framework_search_paths,兼容不同的configuration # 从编译上来说,仅仅替换了framework_search_paths的路径就够了 # @return [Array] alias_method :old_raw_framework_search_paths, :_raw_framework_search_paths def _raw_framework_search_paths framework_search_paths = old_raw_framework_search_paths replace_xcconfig_configuration_paths(framework_search_paths) framework_search_paths end end end end end