Commit b9b9d5fa authored by Marius Rackwitz's avatar Marius Rackwitz

Add the Embed Pods Framework Build Phase in TargetIntegrator

Embed frameworks with a run script build phase
parent 58219eca
...@@ -56,6 +56,7 @@ module Pod ...@@ -56,6 +56,7 @@ module Pod
autoload :BridgeSupport, 'cocoapods/generator/bridge_support' autoload :BridgeSupport, 'cocoapods/generator/bridge_support'
autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script' autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script'
autoload :DummySource, 'cocoapods/generator/dummy_source' autoload :DummySource, 'cocoapods/generator/dummy_source'
autoload :EmbedFrameworksScript, 'cocoapods/generator/embed_frameworks_script'
autoload :Header, 'cocoapods/generator/header' autoload :Header, 'cocoapods/generator/header'
autoload :InfoPlistFile, 'cocoapods/generator/info_plist_file' autoload :InfoPlistFile, 'cocoapods/generator/info_plist_file'
autoload :PrefixHeader, 'cocoapods/generator/prefix_header' autoload :PrefixHeader, 'cocoapods/generator/prefix_header'
......
module Pod
module Generator
class EmbedFrameworksScript
# @return [Hash{String, Array{String}] Multiple lists of frameworks per
# configuration.
#
attr_reader :frameworks_by_config
# @param [Hash{String, Array{String}] frameworks_by_config
# @see frameworks_by_config
#
def initialize(frameworks_by_config)
@frameworks_by_config = frameworks_by_config
end
# Saves the resource script to the given pathname.
#
# @param [Pathname] pathname
# The path where the embed frameworks script should be saved.
#
# @return [void]
#
def save_as(pathname)
pathname.open('w') do |file|
file.puts(script)
end
File.chmod(0755, pathname.to_s)
end
private
# @!group Private Helpers
# @return [String] The contents of the embed frameworks script.
#
def script
script = INSTALL_FRAMEWORKS_FUNCTION
script += "\n" unless frameworks_by_config.values.all?(&:empty?)
frameworks_by_config.each do |config, frameworks|
unless frameworks.empty?
script += %(if [[ "$CONFIGURATION" == "#{config}" ]]; then\n)
frameworks.each do |framework|
script += " install_framework '#{framework}'\n"
end
script += "fi\n"
end
end
script
end
INSTALL_FRAMEWORKS_FUNCTION = <<EOS
#!/bin/sh
set -e
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
install_framework()
{
echo "rsync --exclude '*.h' -av ${PODS_ROOT}/$1 ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
rsync -av "${BUILT_PRODUCTS_DIR}/$1" "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
}
EOS
end
end
end
...@@ -17,6 +17,7 @@ module Pod ...@@ -17,6 +17,7 @@ module Pod
if target.requires_framework? if target.requires_framework?
create_info_plist_file create_info_plist_file
create_umbrella_header create_umbrella_header
create_embed_frameworks_script
end end
create_target_environment_header create_target_environment_header
create_bridge_support_file create_bridge_support_file
...@@ -108,6 +109,28 @@ module Pod ...@@ -108,6 +109,28 @@ module Pod
add_file_to_support_group(path) add_file_to_support_group(path)
end end
# Creates a script that embeds the frameworks to the bundle of the client
# target.
#
# @note We can't use Xcode default copy bundle resource phase, because
# we need to ensure that we only copy the resources, which are
# relevant for the current build configuration.
#
# @return [void]
#
def create_embed_frameworks_script
path = target.embed_frameworks_script_path
frameworks_by_config = {}
target.user_build_configurations.keys.each do |config|
frameworks_by_config[config] = target.pod_targets.select do |pod_target|
pod_target.include_in_build_config?(config)
end.map(&:product_name)
end
generator = Generator::EmbedFrameworksScript.new(frameworks_by_config)
generator.save_as(path)
add_file_to_support_group(path)
end
# Generates the acknowledgement files (markdown and plist) for the target. # Generates the acknowledgement files (markdown and plist) for the target.
# #
# @return [void] # @return [void]
......
...@@ -33,6 +33,7 @@ module Pod ...@@ -33,6 +33,7 @@ module Pod
update_to_cocoapods_0_34, update_to_cocoapods_0_34,
unless native_targets_to_integrate.empty? unless native_targets_to_integrate.empty?
add_pods_library add_pods_library
add_embed_frameworks_script_phase if target.requires_framework?
add_copy_resources_script_phase add_copy_resources_script_phase
add_check_manifest_lock_script_phase add_check_manifest_lock_script_phase
true true
...@@ -122,6 +123,24 @@ module Pod ...@@ -122,6 +123,24 @@ module Pod
end end
end end
# Find or create a 'Embed Pods Frameworks' Copy Files Build Phase
#
# @return [void]
#
def add_embed_frameworks_script_phase
phase_name = 'Embed Pods Frameworks'
native_targets_to_integrate.each do |native_target|
embed_build_phase = native_target.shell_script_build_phases.select { |bp| bp.name == phase_name }.first
unless embed_build_phase.present?
UI.message("Add Build Phase '#{phase_name}' to project.")
embed_build_phase = native_target.new_shell_script_build_phase(phase_name)
end
script_path = target.embed_frameworks_script_relative_path
embed_build_phase.shell_script = %("#{script_path}"\n)
embed_build_phase.show_env_vars_in_log = '0'
end
end
# Adds a shell script build phase responsible to copy the resources # Adds a shell script build phase responsible to copy the resources
# generated by the TargetDefinition to the bundle of the product of the # generated by the TargetDefinition to the bundle of the product of the
# targets. # targets.
......
...@@ -129,6 +129,12 @@ module Pod ...@@ -129,6 +129,12 @@ module Pod
support_files_dir + "#{label}-resources.sh" support_files_dir + "#{label}-resources.sh"
end end
# @return [Pathname] The absolute path of the embed frameworks script.
#
def embed_frameworks_script_path
support_files_dir + "#{label}-frameworks.sh"
end
# @return [String] The xcconfig path of the root from the `$(SRCROOT)` # @return [String] The xcconfig path of the root from the `$(SRCROOT)`
# variable of the user's project. # variable of the user's project.
# #
...@@ -151,6 +157,13 @@ module Pod ...@@ -151,6 +157,13 @@ module Pod
"${SRCROOT}/#{relative_to_srcroot(copy_resources_script_path)}" "${SRCROOT}/#{relative_to_srcroot(copy_resources_script_path)}"
end end
# @return [String] The path of the embed frameworks relative to the
# root of the user project.
#
def embed_frameworks_script_relative_path
"${SRCROOT}/#{relative_to_srcroot(embed_frameworks_script_path)}"
end
private private
# @!group Private Helpers # @!group Private Helpers
......
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Generator::EmbedFrameworksScript do
it 'returns the embed frameworks script' do
frameworks = {
'Debug' => %w(Loopback.framework Reveal.framework),
'Release' => %w(CrashlyticsFramework.framework)
}
generator = Pod::Generator::EmbedFrameworksScript.new(frameworks)
generator.send(:script).should.include <<-eos.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_framework 'Loopback.framework'
install_framework 'Reveal.framework'
fi
eos
generator.send(:script).should.include <<-eos.strip_heredoc
if [[ "$CONFIGURATION" == "Release" ]]; then
install_framework 'CrashlyticsFramework.framework'
fi
eos
end
end
end
...@@ -51,6 +51,10 @@ module Pod ...@@ -51,6 +51,10 @@ module Pod
@target.copy_resources_script_path.to_s.should.include?('Pods/Target Support Files/Pods/Pods-resources.sh') @target.copy_resources_script_path.to_s.should.include?('Pods/Target Support Files/Pods/Pods-resources.sh')
end end
it 'returns the absolute path of the frameworks script' do
@target.embed_frameworks_script_path.to_s.should.include?('Pods/Target Support Files/Pods/Pods-frameworks.sh')
end
it 'returns the absolute path of the target header file' do it 'returns the absolute path of the target header file' do
@target.target_environment_header_path.to_s.should.include?('Pods/Target Support Files/Pods/Pods-environment.h') @target.target_environment_header_path.to_s.should.include?('Pods/Target Support Files/Pods/Pods-environment.h')
end end
...@@ -71,6 +75,10 @@ module Pod ...@@ -71,6 +75,10 @@ module Pod
@target.copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh' @target.copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh'
end end
it 'returns the path of the frameworks script relative to the user project' do
@target.embed_frameworks_script_relative_path.should == '${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh'
end
it 'returns the path of the xcconfig file relative to the user project' do it 'returns the path of the xcconfig file relative to the user project' do
@target.xcconfig_relative_path('Release').should == 'Pods/Target Support Files/Pods/Pods.release.xcconfig' @target.xcconfig_relative_path('Release').should == 'Pods/Target Support Files/Pods/Pods.release.xcconfig'
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment