Skip to content

Commit

Permalink
[post-install] Add dSYM generation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Renzo Crisóstomo authored and Renzo Crisóstomo committed Apr 9, 2018
1 parent 65bdd86 commit a9e071d
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions lib/cocoapods-rome/post_install.rb
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -31,21 +30,48 @@ 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

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'

Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit a9e071d

Please sign in to comment.