Commit 0cd216a6 authored by Eloy Duran's avatar Eloy Duran

Copy headers to the pod's header dir $(BUILT_PRODUCTS_DIR)/Pods/PodName by…

Copy headers to the pod's header dir $(BUILT_PRODUCTS_DIR)/Pods/PodName by default, but allow for customization by overriding copy_header_mapping(s).
parent e04d1529
......@@ -32,19 +32,6 @@ module Pod
source_files
end
def grouped_source_files_for_spec(spec)
grouped_files = {}
spec.source_files.each do |pattern|
pattern = spec.pod_destroot + pattern
pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
pattern.glob.each do |file|
file = file.relative_path_from(config.project_pods_root)
(grouped_files[file.dirname.to_s] ||= []) << file
end
end
grouped_files
end
def xcconfig
@xcconfig ||= Xcode::Config.new({
# In a workspace this is where the static library headers should be found
......@@ -61,15 +48,25 @@ module Pod
def generate_project
build_specification_sets.each do |set|
xcconfig << { 'USER_HEADER_SEARCH_PATHS' => %{"$(BUILT_PRODUCTS_DIR)/Pods/#{set.name}"} }
xcodeproj.add_group(set.name)
grouped_source_files_for_spec(set.specification).each do |dir, files|
copy_phase_uuid = xcodeproj.add_copy_header_build_phase(set.name, dir)
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)
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(file, set.name, copy_phase_uuid)
xcodeproj.add_source_file(spec.pod_destroot_name + file, spec.name, copy_phase_uuid)
end
end
xcconfig << set.specification.xcconfig
end
end
......
......@@ -125,7 +125,13 @@ module Pod
if part_of_other_pod?
part_of_specification.pod_destroot
else
config.project_pods_root + "#{@name}-#{@version}"
config.project_pods_root + @name
end
end
def pod_destroot_name
if root = pod_destroot
root.basename
end
end
......@@ -137,6 +143,56 @@ module Pod
@name.nil? && @version.nil?
end
# Returns all source files of this pod including header files.
def expanded_source_files
files = []
source_files.each do |pattern|
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)
end
end
files
end
def implementation_files
expanded_source_files.select { |f| f.extname != '.h' }
end
# Returns only the header files of this pod.
def header_files
expanded_source_files.select { |f| f.extname == '.h' }
end
# This method takes a header path and returns the location it should have
# in the pod's header dir.
#
# By default all headers are copied to the pod's header dir without any
# namespacing. You can, however, override this method in the podspec, or
# copy_header_mappings for full control.
def copy_header_mapping(from)
from.basename
end
# 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
mappings
end
end
# Returns a list of search paths where the pod's headers can be found. This
# includes the pod's header dir root and any other directories that might
# 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
end
def to_s
if from_podfile?
"podfile at `#{@defined_in_file}'"
......
......@@ -41,7 +41,7 @@ describe "A Pod::Specification loaded from a podspec" do
end
it "returns the directory where the pod should be checked out to" do
@spec.pod_destroot.should == config.project_pods_root + 'BananaLib-1.0'
@spec.pod_destroot.should == config.project_pods_root + 'BananaLib'
end
it "returns the pod's name" do
......@@ -155,6 +155,75 @@ describe "A Pod::Specification that's part of another pod's source" do
#end
end
describe "A Pod::Specification, with installed source," do
before do
config.project_pods_root = fixture('integration')
podspec = fixture('spec-repos/master/SSZipArchive/0.1.0/SSZipArchive.podspec')
@spec = Pod::Specification.from_podspec(podspec)
@destroot = fixture('integration/SSZipArchive')
end
after do
config.project_pods_root = nil
end
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) }
@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) }
@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) }
@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{
SSZipArchive.h
minizip/crypt.h
minizip/ioapi.h
minizip/mztools.h
minizip/unzip.h
minizip/zip.h
}.map { |f| Pathname.new(f) }.sort
end
it "allows for customization of header mappings by overriding copy_header_mapping" do
def @spec.copy_header_mapping(from)
Pathname.new('ns') + from.basename
end
@spec.copy_header_mappings.size.should == 1
@spec.copy_header_mappings['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
end
it "returns the user header search paths" do
def @spec.copy_header_mapping(from)
Pathname.new('ns') + from.basename
end
@spec.user_header_search_paths.should == %w{
"$(BUILT_PRODUCTS_DIR)/Pods/SSZipArchive"
"$(BUILT_PRODUCTS_DIR)/Pods/SSZipArchive/ns"
}
end
end
describe "A Pod::Specification, in general," do
it "raises if the specification does not contain the minimum required attributes" do
exception = lambda {
......
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