lib/cocoapods-rome/post_install.rb in cocoapods-rome-0.0.1 vs lib/cocoapods-rome/post_install.rb in cocoapods-rome-0.0.2

- old
+ new

@@ -1,17 +1,32 @@ - Pod::HooksManager.register('cocoapods-rome', :post_install) do |installer_context| - sandbox_root = installer_context.sandbox_root - sandbox = Pod::Sandbox.new(sandbox_root) + sandbox_root = Pathname(installer_context.sandbox_root) + sandbox = Pod::Sandbox.new(sandbox_root) - puts 'Building frameworks' + build_dir = sandbox_root.parent + 'build' + destination = sandbox_root.parent + 'Rome' - FileUtils.rmtree('build') - Dir.chdir(sandbox.project_path.dirname) do - `xcodebuild -project #{sandbox.project_path.basename} -scheme Pods -configuration Release` - end + Pod::UI.puts 'Building frameworks' - `mv build/Release/Pods/*.framework build` - FileUtils.rmtree('build/Pods.build') - FileUtils.rmtree('build/Release') - `mv build Rome` + build_dir.rmtree if build_dir.directory? + Dir.chdir(sandbox.project_path.dirname) do + targets = installer_context.umbrella_targets.select { |t| t.specs.any? }.map(&:cocoapods_target_label) + targets.each do |target| + Pod::Executable.execute_command 'xcodebuild', %(-project #{sandbox.project_path.basename} -scheme #{target} -configuration Release), true + 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*/Pods*/*.framework') + frameworks_by_target = frameworks.group_by { |f| f.to_s =~ %r{build/Release[^/]*/Pods-?([^/]*)/} && destination + $1 } + + 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? + frameworks_by_target.each do |dest, frameworks| + FileUtils.mkdir_p dest + FileUtils.cp_r frameworks, dest, :remove_destination => true + end + build_dir.rmtree if build_dir.directory? end