lib/cocoapods-framework/xbuilder.rb in cocoapods-xcframework-0.0.5 vs lib/cocoapods-framework/xbuilder.rb in cocoapods-xcframework-0.0.6

- old
+ new

@@ -12,11 +12,11 @@ @installer = installer @source_dir = source_dir @sandbox_root = sandbox_root @spec = spec @configuration = configuration - @outputs = nil + @outputs = {} end def build UI.puts("Building framework #{@spec} with configuration #{@configuration}") UI.puts "Work dir is :#{@sandbox_root}" @@ -29,18 +29,35 @@ end build_all_device defines collect_xc_frameworks + + collect_bundles end def collect_xc_frameworks export_dir = "#{@sandbox_root}/export/**/#{@spec.name}.framework" frameworks = Pathname.glob(export_dir) - @outputs = create_xc_framework_by_frameworks frameworks + @outputs[:xcframework] = create_xc_framework_by_frameworks frameworks end + def collect_bundles + ["iphoneos","macOS","appletvos","watchos"].each do |plat| + export_dir = "#{@sandbox_root}/export/*-#{plat}/**/#{@spec.name}.bundle" + Pathname.glob(export_dir).each do |bundle| + @outputs[:bundle] = "#{@sandbox_root}/bundle" + native_platform = to_native_platform plat + path = Pathname.new "#{@sandbox_root}/bundle/#{native_platform}" + if not path.exist? + path.mkpath + end + FileUtils.cp_r(Dir["#{bundle}"],"#{path}") + end + end + end + def create_xc_framework_by_frameworks frameworks command = 'xcodebuild -create-xcframework ' frameworks.each do |framework| command << "-framework #{framework} " end @@ -81,26 +98,49 @@ def outputs target_dir if not File.exist? target_dir Pathname.new(target_dir).mkdir end outputs_xcframework target_dir + outputs_bundle target_dir new_spec_hash = generic_new_podspec_hash @spec new_spec_hash[:vendored_frameworks] = "#{@spec.name}.xcframework" + new_spec_hash[:resource_bundles] = find_bundles target_dir require 'json' spec_json = JSON.pretty_generate(new_spec_hash) << "\n" File.open("#{target_dir}/#{@spec.name}.podspec.json",'wb+') do |f| f.write(spec_json) end UI.puts "result export at :#{target_dir}" target_dir + exit -1 end + + def find_bundles target_dir + bundle_root = "#{target_dir}/bundle/" + bundle_name = "/#{@spec.name}.bundle" + pattern = "#{bundle_root}*#{bundle_name}" + result = {} + Pathname.glob(pattern).each do |bundle| + bundle_relative_path = bundle.to_s.gsub(bundle_root, "") + plat = bundle_relative_path.gsub(bundle_name,"") + result[plat] = "bundle/" + bundle_relative_path + end + puts result + result + end def outputs_xcframework target_dir - command = "cp -rp #{@outputs} #{target_dir} 2>&1" + command = "cp -rp #{@outputs[:xcframework]} #{target_dir} 2>&1" output = `#{command}`.lines.to_a if $?.exitstatus != 0 Pod::ErrorUtil.error_report command,output Process.exit -1 + end + end + + def outputs_bundle target_dir + if @outputs[:bundle] + FileUtils.cp_r(Dir[@outputs[:bundle]],target_dir) end end end end