Commit 1d5a218c authored by Fabio Pelosin's avatar Fabio Pelosin

[FileReferencesInstaller] Move headers linking logic to the installer.

parent d059c4cb
......@@ -101,6 +101,7 @@ module Pod
install_pod_sources
run_pre_install_hooks
clean_pod_sources
link_headers
end
end
......@@ -274,7 +275,64 @@ module Pod
end
end
# Creates the link to the headers of the Pod in the sandbox.
#
# @return [void]
#
def link_headers
UI.section "Linking headers" do
pod_targets.each do |pod_target|
pod_target.file_accessors.each do |file_accessor|
headers_sandbox = Pathname.new(file_accessor.spec.root.name)
pod_target.build_headers.add_search_path(headers_sandbox)
sandbox.public_headers.add_search_path(headers_sandbox)
header_mappings(headers_sandbox, file_accessor, file_accessor.headers).each do |namespaced_path, files|
pod_target.build_headers.add_files(namespaced_path, files)
end
header_mappings(headers_sandbox, file_accessor, file_accessor.public_headers).each do |namespaced_path, files|
sandbox.public_headers.add_files(namespaced_path, files)
end
end
end
end
end
# Computes the destination sub-directory in the sandbox
#
# @param [Pathname] headers_sandbox
# The sandbox where the headers links should be stored for this
# Pod.
#
# @param [Specification::Consumer] consumer
# The consumer for which the headers need to be linked.
#
# @param [Array<Pathname>] headers
# The absolute paths of the headers which need to be mapped.
#
# @return [Hash{Pathname => Array<Pathname>}] A hash containing the
# headers folders as the keys and the absolute paths of the
# header files as the values.
#
def header_mappings(headers_sandbox, file_accessor, headers)
consumer = file_accessor.spec_consumer
dir = headers_sandbox
dir = dir + consumer.header_dir if consumer.header_dir
mappings = {}
headers.each do |header|
sub_dir = dir
if consumer.header_mappings_dir
header_mappings_dir = file_accessor.path_list.root + consumer.header_mappings_dir
relative_path = header.relative_path_from(header_mappings_dir)
sub_dir = sub_dir + relative_path.dirname
end
mappings[sub_dir] ||= []
mappings[sub_dir] << header
end
mappings
end
# Writes the Podfile and the lock files.
#
......
......@@ -39,7 +39,6 @@ module Pod
add_frameworks_bundles
add_vendored_libraries
add_resources
link_headers
end
#-----------------------------------------------------------------------#
......@@ -108,29 +107,6 @@ module Pod
end
end
# Creates the link to the headers of the Pod in the sandbox.
#
# @return [void]
#
def link_headers
UI.message "- Linking headers" do
libraries.each do |library|
library.file_accessors.each do |file_accessor|
headers_sandbox = Pathname.new(file_accessor.spec.root.name)
library.build_headers.add_search_path(headers_sandbox)
sandbox.public_headers.add_search_path(headers_sandbox)
header_mappings(headers_sandbox, file_accessor, file_accessor.headers).each do |namespaced_path, files|
library.build_headers.add_files(namespaced_path, files)
end
header_mappings(headers_sandbox, file_accessor, file_accessor.public_headers).each do |namespaced_path, files|
sandbox.public_headers.add_files(namespaced_path, files)
end
end
end
end
end
#-----------------------------------------------------------------------#
......@@ -167,41 +143,6 @@ module Pod
end
end
# Computes the destination sub-directory in the sandbox
#
# @param [Pathname] headers_sandbox
# The sandbox where the headers links should be stored for this
# Pod.
#
# @param [Specification::Consumer] consumer
# The consumer for which the headers need to be linked.
#
# @param [Array<Pathname>] headers
# The absolute paths of the headers which need to be mapped.
#
# @return [Hash{Pathname => Array<Pathname>}] A hash containing the
# headers folders as the keys and the absolute paths of the
# header files as the values.
#
def header_mappings(headers_sandbox, file_accessor, headers)
consumer = file_accessor.spec_consumer
dir = headers_sandbox
dir = dir + consumer.header_dir if consumer.header_dir
mappings = {}
headers.each do |header|
sub_dir = dir
if consumer.header_mappings_dir
header_mappings_dir = file_accessor.path_list.root + consumer.header_mappings_dir
relative_path = header.relative_path_from(header_mappings_dir)
sub_dir = sub_dir + relative_path.dirname
end
mappings[sub_dir] ||= []
mappings[sub_dir] << header
end
mappings
end
#-----------------------------------------------------------------------#
end
......
......@@ -44,24 +44,6 @@ module Pod
file_ref.path.should == "Resources/logo-sidebar.png"
end
it "links the build headers" do
@installer.install!
headers_root = @pod_target.build_headers.root
public_header = headers_root + 'BananaLib/Banana.h'
private_header = headers_root + 'BananaLib/BananaPrivate.h'
public_header.should.exist
private_header.should.exist
end
it "links the public headers" do
@installer.install!
headers_root = config.sandbox.public_headers.root
public_header = headers_root + 'BananaLib/Banana.h'
private_header = headers_root + 'BananaLib/BananaPrivate.h'
public_header.should.exist
private_header.should.not.exist
end
end
#-------------------------------------------------------------------------#
......@@ -92,41 +74,6 @@ module Pod
end
end
describe "#add_file_accessors_paths_to_pods_group" do
it "returns the header mappings" do
headers_sandbox = Pathname.new('BananaLib')
headers = [Pathname.new('BananaLib/Banana.h')]
mappings = @installer.send(:header_mappings, headers_sandbox, @file_accessor, headers)
mappings.should == {
headers_sandbox => [Pathname.new('BananaLib/Banana.h')]
}
end
it "takes into account the header dir specified in the spec" do
headers_sandbox = Pathname.new('BananaLib')
headers = [Pathname.new('BananaLib/Banana.h')]
@file_accessor.spec_consumer.stubs(:header_dir).returns('Sub_dir')
mappings = @installer.send(:header_mappings, headers_sandbox, @file_accessor, headers)
mappings.should == {
(headers_sandbox + 'Sub_dir') => [Pathname.new('BananaLib/Banana.h')]
}
end
it "takes into account the header mappings dir specified in the spec" do
headers_sandbox = Pathname.new('BananaLib')
header_1 = @file_accessor.root + 'BananaLib/sub_dir/dir_1/banana_1.h'
header_2 = @file_accessor.root + 'BananaLib/sub_dir/dir_2/banana_2.h'
headers = [ header_1, header_2 ]
@file_accessor.spec_consumer.stubs(:header_mappings_dir).returns('BananaLib/sub_dir')
mappings = @installer.send(:header_mappings, headers_sandbox, @file_accessor, headers)
mappings.should == {
(headers_sandbox + 'dir_1') => [header_1],
(headers_sandbox + 'dir_2') => [header_2],
}
end
end
end
#-------------------------------------------------------------------------#
......
......@@ -49,6 +49,7 @@ module Pod
@installer.unstub(:download_dependencies)
@installer.stubs(:create_file_accessors)
@installer.stubs(:install_pod_sources)
@installer.stubs(:link_headers)
def @installer.run_pre_install_hooks
@hook_called = true
end
......@@ -179,15 +180,86 @@ module Pod
#--------------------------------------#
describe "#clean" do
describe "#clean_pod_sources" do
it "it cleans only if the config instructs to do it" do
config.clean = false
Installer::PodSourceInstaller.any_instance.expects(:clean!).never
@installer.send(:clean_pod_sources)
Installer::PodSourceInstaller.any_instance.expects(:install!).never
end
end
#--------------------------------------#
describe "#link_headers" do
it "links the build headers" do
pod_target = PodTarget.new(nil, nil, config.sandbox)
pod_target.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')]
@installer.stubs(:pod_targets).returns([pod_target])
@installer.send(:link_headers)
headers_root = pod_target.build_headers.root
public_header = headers_root + 'BananaLib/Banana.h'
private_header = headers_root + 'BananaLib/BananaPrivate.h'
public_header.should.exist
private_header.should.exist
end
it "links the public headers" do
pod_target = PodTarget.new(nil, nil, config.sandbox)
pod_target.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')]
@installer.stubs(:pod_targets).returns([pod_target])
@installer.send(:link_headers)
headers_root = config.sandbox.public_headers.root
public_header = headers_root + 'BananaLib/Banana.h'
private_header = headers_root + 'BananaLib/BananaPrivate.h'
public_header.should.exist
private_header.should.not.exist
end
describe "#header_mappings" do
before do
@file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec')
end
it "returns the header mappings" do
headers_sandbox = Pathname.new('BananaLib')
headers = [Pathname.new('BananaLib/Banana.h')]
mappings = @installer.send(:header_mappings, headers_sandbox, @file_accessor, headers)
mappings.should == {
headers_sandbox => [Pathname.new('BananaLib/Banana.h')]
}
end
it "takes into account the header dir specified in the spec" do
headers_sandbox = Pathname.new('BananaLib')
headers = [Pathname.new('BananaLib/Banana.h')]
@file_accessor.spec_consumer.stubs(:header_dir).returns('Sub_dir')
mappings = @installer.send(:header_mappings, headers_sandbox, @file_accessor, headers)
mappings.should == {
(headers_sandbox + 'Sub_dir') => [Pathname.new('BananaLib/Banana.h')]
}
end
it "takes into account the header mappings dir specified in the spec" do
headers_sandbox = Pathname.new('BananaLib')
header_1 = @file_accessor.root + 'BananaLib/sub_dir/dir_1/banana_1.h'
header_2 = @file_accessor.root + 'BananaLib/sub_dir/dir_2/banana_2.h'
headers = [ header_1, header_2 ]
@file_accessor.spec_consumer.stubs(:header_mappings_dir).returns('BananaLib/sub_dir')
mappings = @installer.send(:header_mappings, headers_sandbox, @file_accessor, headers)
mappings.should == {
(headers_sandbox + 'dir_1') => [header_1],
(headers_sandbox + 'dir_2') => [header_2],
}
end
end
end
end
end
......@@ -210,6 +282,7 @@ module Pod
end
it "in runs the post-install hooks before serializing the Pods project" do
Installer::PodsProjectGenerator.any_instance.expects(:install)
def @installer.run_post_install_hooks
Installer::PodsProjectGenerator.any_instance.expects(:write_pod_project)
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