From a9e071d5c4a1cffa34c858de29049586a04f4446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renzo=20Cris=C3=B3stomo?= Date: Thu, 9 Feb 2017 15:23:48 +0100 Subject: [PATCH] [post-install] Add dSYM generation Enable debug information to specific target to enable dSYM generation. This will generate a directory with the dSYM files per platform. It only supports 'iphoneos' and 'iphonesimulator' for now. --- lib/cocoapods-rome/post_install.rb | 53 +++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/lib/cocoapods-rome/post_install.rb b/lib/cocoapods-rome/post_install.rb index a5f621e..fb3309d 100644 --- a/lib/cocoapods-rome/post_install.rb +++ b/lib/cocoapods-rome/post_install.rb @@ -1,23 +1,22 @@ require 'fourflusher' -CONFIGURATION = "Release" PLATFORMS = { 'iphonesimulator' => 'iOS', 'appletvsimulator' => 'tvOS', 'watchsimulator' => 'watchOS' } -def build_for_iosish_platform(sandbox, build_dir, target, device, simulator) +def build_for_iosish_platform(sandbox, build_dir, target, device, simulator, configuration) deployment_target = target.platform_deployment_target target_label = target.cocoapods_target_label - xcodebuild(sandbox, target_label, device, deployment_target) - xcodebuild(sandbox, target_label, simulator, deployment_target) + xcodebuild(sandbox, target_label, device, deployment_target, configuration) + xcodebuild(sandbox, target_label, simulator, deployment_target, configuration) spec_names = target.specs.map { |spec| [spec.root.name, spec.root.module_name] }.uniq spec_names.each do |root_name, module_name| executable_path = "#{build_dir}/#{root_name}" - device_lib = "#{build_dir}/#{CONFIGURATION}-#{device}/#{root_name}/#{module_name}.framework/#{module_name}" + device_lib = "#{build_dir}/#{configuration}-#{device}/#{root_name}/#{module_name}.framework/#{module_name}" device_framework_lib = File.dirname(device_lib) - simulator_lib = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{root_name}/#{module_name}.framework/#{module_name}" + simulator_lib = "#{build_dir}/#{configuration}-#{simulator}/#{root_name}/#{module_name}.framework/#{module_name}" next unless File.file?(device_lib) && File.file?(simulator_lib) @@ -31,14 +30,39 @@ def build_for_iosish_platform(sandbox, build_dir, target, device, simulator) end end -def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil) - args = %W(-project #{sandbox.project_path.realdirpath} -scheme #{target} -configuration #{CONFIGURATION} -sdk #{sdk}) +def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil, configuration) + args = %W(-project #{sandbox.project_path.realdirpath} -scheme #{target} -configuration #{configuration} -sdk #{sdk}) platform = PLATFORMS[sdk] args += Fourflusher::SimControl.new.destination(:oldest, platform, deployment_target) unless platform.nil? Pod::Executable.execute_command 'xcodebuild', args, true end +def enable_debug_information(project_path, configuration) + project = Xcodeproj::Project.open(project_path) + project.targets.each do |target| + config = target.build_configurations.find { |config| config.name.eql? configuration } + config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf-with-dsym' + config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO' + end + project.save +end + +def copy_dsym_files(dsym_destination, configuration) + dsym_destination.rmtree if dsym_destination.directory? + platforms = ['iphoneos', 'iphonesimulator'] + platforms.each do |platform| + dsym = Pathname.glob("build/#{configuration}-#{platform}/**/*.dSYM") + dsym.each do |dsym| + destination = dsym_destination + platform + FileUtils.mkdir_p destination + FileUtils.cp_r dsym, destination, :remove_destination => true + end + end +end + Pod::HooksManager.register('cocoapods-rome', :post_install) do |installer_context, user_options| + enable_dsym = user_options.fetch('dsym', true) + configuration = user_options.fetch('configuration', true) if user_options["pre_compile"] user_options["pre_compile"].call(installer_context) end @@ -46,6 +70,8 @@ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil) sandbox_root = Pathname(installer_context.sandbox_root) sandbox = Pod::Sandbox.new(sandbox_root) + enable_debug_information(sandbox.project_path, configuration) if enable_dsym + build_dir = sandbox_root.parent + 'build' destination = sandbox_root.parent + 'Rome' @@ -55,10 +81,10 @@ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil) targets = installer_context.umbrella_targets.select { |t| t.specs.any? } targets.each do |target| case target.platform_name - when :ios then build_for_iosish_platform(sandbox, build_dir, target, 'iphoneos', 'iphonesimulator') - when :osx then xcodebuild(sandbox, target.cocoapods_target_label) - when :tvos then build_for_iosish_platform(sandbox, build_dir, target, 'appletvos', 'appletvsimulator') - when :watchos then build_for_iosish_platform(sandbox, build_dir, target, 'watchos', 'watchsimulator') + when :ios then build_for_iosish_platform(sandbox, build_dir, target, 'iphoneos', 'iphonesimulator', configuration) + when :osx then xcodebuild(sandbox, target.cocoapods_target_label, configuration) + when :tvos then build_for_iosish_platform(sandbox, build_dir, target, 'appletvos', 'appletvsimulator', configuration) + when :watchos then build_for_iosish_platform(sandbox, build_dir, target, 'watchos', 'watchsimulator', configuration) else raise "Unknown platform '#{target.platform_name}'" end end @@ -89,5 +115,8 @@ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil) FileUtils.mkdir_p destination FileUtils.cp_r framework, destination, :remove_destination => true end + + copy_dsym_files(sandbox_root.parent + 'dSYM', configuration) if enable_dsym + build_dir.rmtree if build_dir.directory? end