lib/cocoapods-rome/post_install.rb in cocoapods-rome-0.1.0 vs lib/cocoapods-rome/post_install.rb in cocoapods-rome-0.2.0

- old
+ new

@@ -1,7 +1,11 @@ +CONFIGURATION = "Release" +DEVICE = "iphoneos" +SIMULATOR = "iphonesimulator" + def xcodebuild(sandbox, target, sdk='macosx') - Pod::Executable.execute_command 'xcodebuild', %W(-project #{sandbox.project_path.basename} -scheme #{target} -configuration Release -sdk #{sdk}), true + Pod::Executable.execute_command 'xcodebuild', %W(-project #{sandbox.project_path.basename} -scheme #{target} -configuration #{CONFIGURATION} -sdk #{sdk}), true end Pod::HooksManager.register('cocoapods-rome', :post_install) do |installer_context| sandbox_root = Pathname(installer_context.sandbox_root) sandbox = Pod::Sandbox.new(sandbox_root) @@ -13,35 +17,56 @@ build_dir.rmtree if build_dir.directory? Dir.chdir(sandbox.project_path.dirname) do targets = installer_context.umbrella_targets.select { |t| t.specs.any? } targets.each do |target| + target_label = target.cocoapods_target_label if target.platform_name == :ios - xcodebuild(sandbox, target.cocoapods_target_label, 'iphoneos') - xcodebuild(sandbox, target.cocoapods_target_label, 'iphonesimulator') + xcodebuild(sandbox, target_label, DEVICE) + xcodebuild(sandbox, target_label, SIMULATOR) - target.specs.each do |spec| - device_lib = "#{build_dir}/Release-iphoneos/#{spec.name}.framework/#{spec.name}" - simulator_lib = "#{build_dir}/Release-iphonesimulator/#{spec.name}.framework/#{spec.name}" - `lipo -create -output "#{build_dir}/#{spec.name}" #{device_lib} #{simulator_lib}` + spec_names = target.specs.map { |spec| spec.root.name }.uniq + spec_names.each do |root_name| + executable_path = "#{build_dir}/#{root_name}" + device_lib = "#{build_dir}/#{CONFIGURATION}-#{DEVICE}/#{target_label}/#{root_name}.framework/#{root_name}" + device_framework_lib = File.dirname(device_lib) + simulator_lib = "#{build_dir}/#{CONFIGURATION}-#{SIMULATOR}/#{target_label}/#{root_name}.framework/#{root_name}" - FileUtils.mv "#{build_dir}/#{spec.name}", device_lib - Pathname.new("#{build_dir}/Release-iphonesimulator/#{spec.name}.framework").rmtree + next unless File.file?(device_lib) && File.file?(simulator_lib) + + lipo_log = `lipo -create -output #{executable_path} #{device_lib} #{simulator_lib}` + puts lipo_log unless File.exist?(executable_path) + + FileUtils.mv executable_path, device_lib + FileUtils.mv device_framework_lib, build_dir end else - xcodebuild(sandbox, target.cocoapods_target_label) + xcodebuild(sandbox, target_label) end end end raise Pod::Informative, 'The build directory was not found in the expected location.' unless build_dir.directory? - frameworks = Pathname.glob(build_dir + 'Release*/*.framework').reject { |f| f.to_s =~ /Pods*\.framework/ } + frameworks = Pathname.glob("#{build_dir}/**/*.framework").reject { |f| f.to_s =~ /Pods*\.framework/ } Pod::UI.puts "Built #{frameworks.count} #{'frameworks'.pluralize(frameworks.count)}" - Pod::UI.puts "Copying frameworks to `#{destination.relative_path_from Pathname.pwd}`" destination.rmtree if destination.directory? + + installer_context.umbrella_targets.each do |umbrella| + umbrella.specs.each do |spec| + consumer = spec.consumer(umbrella.platform_name) + file_accessor = Pod::Sandbox::FileAccessor.new(sandbox.pod_dir(spec.root.name), consumer) + frameworks += file_accessor.vendored_libraries + frameworks += file_accessor.vendored_frameworks + end + end + frameworks.uniq! + + Pod::UI.puts "Copying #{frameworks.count} #{'frameworks'.pluralize(frameworks.count)} " \ + "to `#{destination.relative_path_from Pathname.pwd}`" + frameworks.each do |framework| FileUtils.mkdir_p destination FileUtils.cp_r framework, destination, :remove_destination => true end build_dir.rmtree if build_dir.directory?