Skip to content

Commit

Permalink
[FileReferencesInstaller] Fix crash on #header_mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Feb 27, 2013
1 parent 748ea86 commit 9d9e4a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
10 changes: 5 additions & 5 deletions lib/cocoapods/installer/file_references_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ def link_headers
sandbox.build_headers.add_search_path(headers_sandbox)
sandbox.public_headers.add_search_path(headers_sandbox)

consumer = file_accessor.spec_consumer
header_mappings(headers_sandbox, consumer, file_accessor.headers).each do |namespaced_path, files|
header_mappings(headers_sandbox, file_accessor, file_accessor.headers).each do |namespaced_path, files|
sandbox.build_headers.add_files(namespaced_path, files)
end

header_mappings(headers_sandbox, consumer, file_accessor.public_headers).each do |namespaced_path, files|
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
Expand Down Expand Up @@ -154,15 +153,16 @@ def file_accessors
# headers folders as the keys and the absolute paths of the
# header files as the values.
#
def header_mappings(headers_sandbox, consumer, headers)
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 = Pathname.new(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
Expand Down
24 changes: 10 additions & 14 deletions spec/unit/installer/file_references_installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,33 @@ module Pod

it "returns the header mappings" do
headers_sandbox = Pathname.new('BananaLib')
consumer = @file_accessor.spec_consumer
headers = [Pathname.new('BananaLib/Banana.h')]
mappings = @installer.send(:header_mappings, headers_sandbox, consumer, headers)
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')
consumer = @file_accessor.spec_consumer
headers = [Pathname.new('BananaLib/Banana.h')]
consumer.stubs(:header_dir).returns('Sub_dir')
mappings = @installer.send(:header_mappings, headers_sandbox, consumer, headers)
@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')
consumer = @file_accessor.spec_consumer
headers = [
Pathname.new('BananaLib/sub_dir/dir_1/banana_1.h'),
Pathname.new('BananaLib/sub_dir/dir_2/banana_2.h'),
]
consumer.stubs(:header_mappings_dir).returns('BananaLib/sub_dir')
mappings = @installer.send(:header_mappings, headers_sandbox, consumer, headers)
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') => [Pathname.new('BananaLib/sub_dir/dir_1/banana_1.h')],
(headers_sandbox + 'dir_2') => [Pathname.new('BananaLib/sub_dir/dir_2/banana_2.h')],
(headers_sandbox + 'dir_1') => [header_1],
(headers_sandbox + 'dir_2') => [header_2],
}
end

Expand Down

0 comments on commit 9d9e4a5

Please sign in to comment.