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