Commit 3f9aa837 authored by Gwendal Roué's avatar Gwendal Roué

[#221] Pod::Sandbox#build_header_storage and Pod::Sandbox#public_header_storage

Those methods return Pod::HeaderStorage instances, managing respectively build headers and public headers.

Those objects replace and encapsulate former Pod::Sandbox#headers_root, add_header_file, add_header_files and header_search_paths methods.

For instance, instead of sandbox.header_search_paths, write sandbox.build_header_storage.search_paths.
parent 85308974
......@@ -71,7 +71,7 @@ module Pod
pod.link_headers
end
xcconfig.merge!('HEADER_SEARCH_PATHS' => quoted(sandbox.header_search_paths).join(" "))
xcconfig.merge!('HEADER_SEARCH_PATHS' => quoted(sandbox.build_header_storage.search_paths).join(" "))
support_files_group = @project.group("Targets Support Files").create_group(@target_definition.label)
support_files_group.create_files(target_support_files)
......
......@@ -75,9 +75,20 @@ module Pod
source_files.select { |f| f.extname == '.h' }
end
def public_header_files
if specification.public_header_files[@platform.name]
expanded_paths(specification.public_header_files, :glob => '*.h', :relative_to_sandbox => true)
else
header_files
end
end
def link_headers
copy_header_mappings.each do |namespaced_path, files|
@sandbox.add_header_files(namespaced_path, files)
@sandbox.build_header_storage.add_files(namespaced_path, files)
end
copy_public_header_mappings.each do |namespaced_path, files|
@sandbox.public_header_storage.add_files(namespaced_path, files)
end
end
......@@ -116,6 +127,16 @@ module Pod
end
end
# TODO comment about copy_header_mappings may well apply to this method as well
def copy_public_header_mappings
public_header_files.inject({}) do |mappings, from|
from_without_prefix = from.relative_path_from(relative_root)
to = specification.header_dir + specification.copy_header_mapping(from_without_prefix)
(mappings[to.dirname] ||= []) << from
mappings
end
end
def expanded_paths(platforms_with_patterns, options = {})
patterns = platforms_with_patterns.is_a?(Hash) ? platforms_with_patterns[@platform.name] : platforms_with_patterns
patterns.map do |pattern|
......
......@@ -3,12 +3,16 @@ require 'fileutils'
module Pod
class Sandbox
attr_reader :root
attr_reader :build_header_storage
attr_reader :public_header_storage
HEADERS_DIR = "Headers"
PUBLIC_HEADERS_DIR = "Headers"
BUILD_HEADERS_DIR = "BuildHeaders"
def initialize(path)
@root = Pathname.new(path)
@header_search_paths = [HEADERS_DIR]
@build_header_storage = HeaderStorage.new(self, BUILD_HEADERS_DIR)
@public_header_storage = HeaderStorage.new(self, PUBLIC_HEADERS_DIR)
FileUtils.mkdir_p(@root)
end
......@@ -17,33 +21,13 @@ module Pod
root.rmtree
end
def headers_root
root + HEADERS_DIR
end
def project_path
root + "Pods.xcodeproj"
end
def add_header_file(namespace_path, relative_header_path)
namespaced_header_path = headers_root + namespace_path
namespaced_header_path.mkpath unless File.exist?(namespaced_header_path)
source = (root + relative_header_path).relative_path_from(namespaced_header_path)
Dir.chdir(namespaced_header_path) { FileUtils.ln_sf(source, relative_header_path.basename)}
@header_search_paths << namespaced_header_path.relative_path_from(root)
namespaced_header_path + relative_header_path.basename
end
def add_header_files(namespace_path, relative_header_paths)
relative_header_paths.map { |path| add_header_file(namespace_path, path) }
end
def header_search_paths
@header_search_paths.uniq.map { |path| "${PODS_ROOT}/#{path}" }
end
def prepare_for_install
headers_root.rmtree if headers_root.exist?
build_header_storage.prepare_for_install
public_header_storage.prepare_for_install
end
def podspec_for_name(name)
......@@ -60,4 +44,37 @@ module Pod
end
end
end
class HeaderStorage
def initialize(sandbox, base_dir)
@sandbox = sandbox
@base_dir = base_dir
@search_paths = [base_dir]
end
def root
@sandbox.root + @base_dir
end
def add_file(namespace_path, relative_header_path)
namespaced_header_path = @sandbox.root + @base_dir + namespace_path
namespaced_header_path.mkpath unless File.exist?(namespaced_header_path)
source = (@sandbox.root + relative_header_path).relative_path_from(namespaced_header_path)
Dir.chdir(namespaced_header_path) { FileUtils.ln_sf(source, relative_header_path.basename)}
@search_paths << namespaced_header_path.relative_path_from(@sandbox.root)
namespaced_header_path + relative_header_path.basename
end
def add_files(namespace_path, relative_header_paths)
relative_header_paths.map { |path| add_file(namespace_path, path) }
end
def search_paths
@search_paths.uniq.map { |path| "${PODS_ROOT}/#{path}" }
end
def prepare_for_install
root.rmtree if root.exist?
end
end
end
......@@ -33,6 +33,7 @@ describe "Pod::Command::Spec#create" do
spec.source.should == { :git => 'http://EXAMPLE/Bananas.git', :tag => '0.0.1' }
spec.description.should == 'An optional longer description of Bananas.'
spec.source_files[:ios].should == ['Classes', 'Classes/**/*.{h,m}']
spec.public_header_files[:ios].should == nil
end
it "correctly creates a podspec from github" do
......
......@@ -51,7 +51,7 @@ describe Pod::Installer::TargetInstaller do
it 'adds the sandbox header search paths to the xcconfig, with quotes' do
do_install!
@installer.xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include("\"#{@sandbox.header_search_paths.join('" "')}\"")
@installer.xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include("\"#{@sandbox.build_header_storage.search_paths.join('" "')}\"")
end
it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do
......
......@@ -61,7 +61,7 @@ describe Pod::LocalPod do
it "can link it's headers into the sandbox" do
@pod.link_headers
expected_header_path = @sandbox.headers_root + "BananaLib/Banana.h"
expected_header_path = @sandbox.build_header_storage.root + "BananaLib/Banana.h"
expected_header_path.should.be.symlink
File.read(expected_header_path).should == (@sandbox.root + @pod.header_files[0]).read
end
......@@ -147,7 +147,7 @@ describe "A Pod::LocalPod, with installed source," do
def @spec.copy_header_mapping(from)
Pathname.new('ns') + from.basename
end
@spec.header_search_paths.should == %w{
@spec.build_header_storage.search_paths.should == %w{
"$(PODS_ROOT)/Headers/SSZipArchive"
"$(PODS_ROOT)/Headers/SSZipArchive/ns"
}
......@@ -158,7 +158,7 @@ describe "A Pod::LocalPod, with installed source," do
def @spec.copy_header_mapping(from)
Pathname.new('ns') + from.basename
end
@spec.header_search_paths.should == %w{
@spec.build_header_storage.search_paths.should == %w{
"$(PODS_ROOT)/Headers/AnotherRoot"
"$(PODS_ROOT)/Headers/AnotherRoot/ns"
}
......
......@@ -24,7 +24,7 @@ describe Pod::Sandbox do
end
it "returns it's headers root" do
@sandbox.headers_root.should == Pathname.new(File.join(TMP_POD_ROOT, "Headers"))
@sandbox.build_header_storage.root.should == Pathname.new(File.join(TMP_POD_ROOT, "Headers"))
end
it "can add namespaced headers to it's header path using symlinks and return the relative path" do
......@@ -32,7 +32,7 @@ describe Pod::Sandbox do
namespace_path = Pathname.new("ExampleLib")
relative_header_path = Pathname.new("ExampleLib/Headers/MyHeader.h")
File.open(@sandbox.root + relative_header_path, "w") { |file| file.write('hello') }
symlink_path = @sandbox.add_header_file(namespace_path, relative_header_path)
symlink_path = @sandbox.build_header_storage.add_file(namespace_path, relative_header_path)
symlink_path.should.be.symlink
File.read(symlink_path).should == 'hello'
end
......@@ -47,7 +47,7 @@ describe Pod::Sandbox do
relative_header_paths.each do |path|
File.open(@sandbox.root + path, "w") { |file| file.write('hello') }
end
symlink_paths = @sandbox.add_header_files(namespace_path, relative_header_paths)
symlink_paths = @sandbox.build_header_storage.add_files(namespace_path, relative_header_paths)
symlink_paths.each do |path|
path.should.be.symlink
File.read(path).should == "hello"
......@@ -64,7 +64,7 @@ describe Pod::Sandbox do
relative_header_paths.each do |path|
File.open(@sandbox.root + path, "w") { |file| file.write('hello') }
end
@sandbox.add_header_files(namespace_path, relative_header_paths)
@sandbox.build_header_storage.add_files(namespace_path, relative_header_paths)
@sandbox.header_search_paths.should.include("${PODS_ROOT}/Headers/ExampleLib")
end
......@@ -74,6 +74,6 @@ describe Pod::Sandbox do
it 'clears out its headers root when preparing for install' do
@sandbox.prepare_for_install
@sandbox.headers_root.should.not.exist
@sandbox.build_header_storage.root.should.not.exist
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