Commit e08c92a0 authored by Eloy Duran's avatar Eloy Duran

By default use the same header dir for pod that are part of another pod. This…

By default use the same header dir for pod that are part of another pod. This can be changed by specifiying a custom `header_dir`. Closes #14.
parent 0cd216a6
......@@ -47,27 +47,31 @@ module Pod
end
def generate_project
puts "==> Generating Xcode project and xcconfig" unless config.silent?
user_header_search_paths = []
build_specification_sets.each do |set|
spec = set.specification
xcconfig.merge!('USER_HEADER_SEARCH_PATHS' => spec.user_header_search_paths.join(" "))
xcconfig.merge!(spec.xcconfig)
xcodeproj.add_group(spec.name)
# Only add implementation files to the compile phase
spec.implementation_files.each do |file|
xcodeproj.add_source_file(spec.pod_destroot_name + file, spec.name)
xcodeproj.add_source_file(file, spec.name)
end
# Add header files to a `copy header build phase` for each destination
# directory in the pod's header directory.
set.specification.copy_header_mappings.each do |header_dir, files|
header_dir = spec.pod_destroot_name + header_dir
copy_phase_uuid = xcodeproj.add_copy_header_build_phase(spec.name, header_dir)
files.each do |file|
xcodeproj.add_source_file(spec.pod_destroot_name + file, spec.name, copy_phase_uuid)
xcodeproj.add_source_file(file, spec.name, copy_phase_uuid)
end
end
# Collect all header search paths
user_header_search_paths.concat(spec.user_header_search_paths)
end
xcconfig.merge!('USER_HEADER_SEARCH_PATHS' => user_header_search_paths.sort.uniq.join(" "))
end
# TODO we need a spec that tests that all dependencies are first downloaded/installed
......
module Pod
def self._eval_podspec(path)
eval(path.read, nil, path.to_s)
end
class Specification
autoload :Set, 'cocoapods/specification/set'
......@@ -12,7 +16,7 @@ module Pod
end
def self.from_podspec(path)
spec = eval(path.read, nil, path.to_s)
spec = Pod._eval_podspec(path)
spec.defined_in_file = path
spec
end
......@@ -95,6 +99,13 @@ module Pod
end
alias_method :library=, :libraries=
def header_dir=(dir)
@header_dir = Pathname.new(dir)
end
def header_dir
@header_dir || pod_destroot_name
end
# Not attributes
include Config::Mixin
......@@ -150,7 +161,7 @@ module Pod
pattern = pod_destroot + pattern
pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
pattern.glob.each do |file|
files << file.relative_path_from(pod_destroot)
files << file.relative_path_from(config.project_pods_root)
end
end
files
......@@ -178,8 +189,9 @@ module Pod
# See copy_header_mapping.
def copy_header_mappings
header_files.inject({}) do |mappings, from|
to = copy_header_mapping(from)
(mappings[to.dirname.to_s] ||= []) << from
from_without_prefix = from.relative_path_from(pod_destroot_name)
to = header_dir + copy_header_mapping(from_without_prefix)
(mappings[to.dirname] ||= []) << from
mappings
end
end
......@@ -189,8 +201,8 @@ module Pod
# have been added by overriding the copy_header_mapping/copy_header_mappings
# methods.
def user_header_search_paths
dirs = [@name] + copy_header_mappings.keys.reject { |d| d == '.' }.map { |subdir| "#{@name}/#{subdir}" }
dirs.map { |dir| %{"$(BUILT_PRODUCTS_DIR)/Pods/#{dir}"} }.uniq
dirs = [header_dir] + copy_header_mappings.keys
dirs.map { |dir| %{"$(BUILT_PRODUCTS_DIR)/Pods/#{dir}"} }
end
def to_s
......
......@@ -43,7 +43,6 @@ describe "Pod::Installer" do
{ 'ASIHTTPRequest' => "Classes/*.{h,m}", 'ASIWebPageRequest' => "Classes/ASIWebPageRequest/*.{h,m}", 'Reachability' => "External/Reachability/*.{h,m}" },
{
"USER_HEADER_SEARCH_PATHS" => '"$(BUILT_PRODUCTS_DIR)/Pods" ' \
'"$(BUILT_PRODUCTS_DIR)/Pods/ASIWebPageRequest" ' \
'"$(BUILT_PRODUCTS_DIR)/Pods/ASIHTTPRequest" ' \
'"$(BUILT_PRODUCTS_DIR)/Pods/Reachability"',
"ALWAYS_SEARCH_USER_PATHS" => "YES",
......
......@@ -170,32 +170,32 @@ describe "A Pod::Specification, with installed source," do
it "returns the list of files that the source_files pattern expands to" do
files = @destroot.glob('**/*.{h,c,m}')
files = files.map { |file| file.relative_path_from(@destroot) }
files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.expanded_source_files.sort.should == files.sort
end
it "returns the list of headers" do
files = @destroot.glob('**/*.h')
files = files.map { |file| file.relative_path_from(@destroot) }
files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.header_files.sort.should == files.sort
end
it "returns the list of implementation files" do
files = @destroot.glob('**/*.{c,m}')
files = files.map { |file| file.relative_path_from(@destroot) }
files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.implementation_files.sort.should == files.sort
end
it "returns a hash of mappings from the pod's destroot to its header dirs, which by default is just the pod's header dir" do
@spec.copy_header_mappings.size.should == 1
@spec.copy_header_mappings['.'].sort.should == %w{
@spec.copy_header_mappings[Pathname.new('SSZipArchive')].sort.should == %w{
SSZipArchive.h
minizip/crypt.h
minizip/ioapi.h
minizip/mztools.h
minizip/unzip.h
minizip/zip.h
}.map { |f| Pathname.new(f) }.sort
}.map { |f| Pathname.new("SSZipArchive/#{f}") }.sort
end
it "allows for customization of header mappings by overriding copy_header_mapping" do
......@@ -203,14 +203,26 @@ describe "A Pod::Specification, with installed source," do
Pathname.new('ns') + from.basename
end
@spec.copy_header_mappings.size.should == 1
@spec.copy_header_mappings['ns'].sort.should == %w{
@spec.copy_header_mappings[Pathname.new('SSZipArchive/ns')].sort.should == %w{
SSZipArchive.h
minizip/crypt.h
minizip/ioapi.h
minizip/mztools.h
minizip/unzip.h
minizip/zip.h
}.map { |f| Pathname.new(f) }.sort
}.map { |f| Pathname.new("SSZipArchive/#{f}") }.sort
end
it "returns a hash of mappings with a custom header dir prefix" do
@spec.header_dir = 'AnotherRoot'
@spec.copy_header_mappings[Pathname.new('AnotherRoot')].sort.should == %w{
SSZipArchive.h
minizip/crypt.h
minizip/ioapi.h
minizip/mztools.h
minizip/unzip.h
minizip/zip.h
}.map { |f| Pathname.new("SSZipArchive/#{f}") }.sort
end
it "returns the user header search paths" do
......@@ -222,6 +234,17 @@ describe "A Pod::Specification, with installed source," do
"$(BUILT_PRODUCTS_DIR)/Pods/SSZipArchive/ns"
}
end
it "returns the user header search paths with a custom header dir prefix" do
@spec.header_dir = 'AnotherRoot'
def @spec.copy_header_mapping(from)
Pathname.new('ns') + from.basename
end
@spec.user_header_search_paths.should == %w{
"$(BUILT_PRODUCTS_DIR)/Pods/AnotherRoot"
"$(BUILT_PRODUCTS_DIR)/Pods/AnotherRoot/ns"
}
end
end
describe "A Pod::Specification, in general," do
......
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