Commit 4e3dc124 authored by Eloy Duran's avatar Eloy Duran

Stash work on making specs green. This is taking a somewhat incorrect approach:

The installer should just instantiate the LocalPod class with the
platform, so that it only needs to query tha values it really needs from
the Specification.
parent 14228a83
...@@ -57,7 +57,7 @@ module Pod ...@@ -57,7 +57,7 @@ module Pod
end end
def clean_paths def clean_paths
expanded_paths(specification.clean_paths) expand_paths(specification.clean_paths)
end end
def resources def resources
...@@ -65,7 +65,9 @@ module Pod ...@@ -65,7 +65,9 @@ module Pod
end end
def header_files def header_files
source_files.select { |f| f.extname == '.h' } result = {}
source_files.each { |platform, files| result[platform] = files.select { |f| f.extname == '.h' } }
result
end end
def link_headers def link_headers
...@@ -87,7 +89,9 @@ module Pod ...@@ -87,7 +89,9 @@ module Pod
private private
def implementation_files def implementation_files
source_files.select { |f| f.extname != '.h' } result = {}
source_files.each { |platform, files| result[platform] = files.select { |f| f.extname != '.h' } }
result
end end
def relative_root def relative_root
...@@ -95,6 +99,14 @@ module Pod ...@@ -95,6 +99,14 @@ module Pod
end end
def copy_header_mappings def copy_header_mappings
hash = {}
header_files.each { |platform, files| hash[platform] = copy_header_mappings_for_files(files) }
hash
end
# TODO this is being overriden in the RestKit 0.9.4 spec, need to do
# something with that, and this method also still exists in Specification.
def copy_header_mappings_for_files(header_files)
header_files.inject({}) do |mappings, from| header_files.inject({}) do |mappings, from|
from_without_prefix = from.relative_path_from(relative_root) from_without_prefix = from.relative_path_from(relative_root)
to = specification.header_dir + specification.copy_header_mapping(from_without_prefix) to = specification.header_dir + specification.copy_header_mapping(from_without_prefix)
...@@ -103,15 +115,23 @@ module Pod ...@@ -103,15 +115,23 @@ module Pod
end end
end end
def expanded_paths(patterns, options={}) def expanded_paths(platforms_with_patterns, options = {})
patterns.map do |pattern| paths = {}
platforms_with_patterns.each do |platform, patterns|
paths[platform] = expand_paths(patterns, options)
end
paths
end
def expand_paths(patterns, options = {})
patterns.map do |pattern|
pattern = root + pattern pattern = root + pattern
if pattern.directory? && options[:glob] if pattern.directory? && options[:glob]
pattern += options[:glob] pattern += options[:glob]
end end
pattern.glob.map do |file| pattern.glob.map do |file|
if options[:relative_to_sandbox] if options[:relative_to_sandbox]
file.relative_path_from(@sandbox.root) file.relative_path_from(@sandbox.root)
else else
......
...@@ -263,7 +263,11 @@ module Pod ...@@ -263,7 +263,11 @@ module Pod
end end
def dependency_by_top_level_spec_name(name) def dependency_by_top_level_spec_name(name)
@dependencies.find { |d| d.top_level_spec_name == name } @dependencies.each do |_, platform_deps|
platform_deps.each do |dep|
return dep if dep.top_level_spec_name == name
end
end
end end
def pod_destroot def pod_destroot
...@@ -301,11 +305,13 @@ module Pod ...@@ -301,11 +305,13 @@ module Pod
# Returns all resource files of this pod, but relative to the # Returns all resource files of this pod, but relative to the
# project pods root. # project pods root.
def expanded_resources def expanded_resources
files = [] files = {}
resources.each do |pattern| resources.each do |platform, patterns|
pattern = pod_destroot + pattern patterns.each do |pattern|
pattern.glob.each do |file| pattern = pod_destroot + pattern
files << file.relative_path_from(config.project_pods_root) pattern.glob.each do |file|
(files[platform] ||= []) << file.relative_path_from(config.project_pods_root)
end
end end
end end
files files
...@@ -318,12 +324,14 @@ module Pod ...@@ -318,12 +324,14 @@ module Pod
# automatically glob for c, c++, Objective-C, and Objective-C++ # automatically glob for c, c++, Objective-C, and Objective-C++
# files. # files.
def expanded_source_files def expanded_source_files
files = [] files = {}
source_files.each do |pattern| source_files.each do |platform, patterns|
pattern = pod_destroot + pattern patterns.each do |pattern|
pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory? pattern = pod_destroot + pattern
pattern.glob.each do |file| pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
files << file.relative_path_from(config.project_pods_root) pattern.glob.each do |file|
(files[platform] ||= []) << file.relative_path_from(config.project_pods_root)
end
end end
end end
files files
...@@ -331,7 +339,7 @@ module Pod ...@@ -331,7 +339,7 @@ module Pod
# Returns only the header files of this pod. # Returns only the header files of this pod.
def header_files def header_files
expanded_source_files.select { |f| f.extname == '.h' } expanded_source_files.each { |_, files| files.select! { |f| f.extname == '.h' } }
end end
# This method takes a header path and returns the location it should have # This method takes a header path and returns the location it should have
...@@ -345,7 +353,7 @@ module Pod ...@@ -345,7 +353,7 @@ module Pod
end end
# See copy_header_mapping. # See copy_header_mapping.
def copy_header_mappings def copy_header_mappings_for_files(header_files)
header_files.inject({}) do |mappings, from| header_files.inject({}) do |mappings, from|
from_without_prefix = from.relative_path_from(pod_destroot_name) from_without_prefix = from.relative_path_from(pod_destroot_name)
to = header_dir + copy_header_mapping(from_without_prefix) to = header_dir + copy_header_mapping(from_without_prefix)
...@@ -354,12 +362,23 @@ module Pod ...@@ -354,12 +362,23 @@ module Pod
end end
end end
def copy_header_mappings
header_files.inject({}) do |hash, (platform, files)|
hash[platform] = copy_header_mappings_for_files(files)
hash
end
end
def copy_header_destinations
copy_header_mappings.map { |_, mappings| mappings.keys }.flatten.uniq
end
# Returns a list of search paths where the pod's headers can be found. This # 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 # 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 # have been added by overriding the copy_header_mapping/copy_header_mappings
# methods. # methods.
def header_search_paths def header_search_paths
dirs = [header_dir] + copy_header_mappings.keys dirs = [header_dir] + copy_header_destinations
dirs.map { |dir| %{"$(PODS_ROOT)/Headers/#{dir}"} } dirs.map { |dir| %{"$(PODS_ROOT)/Headers/#{dir}"} }
end end
......
...@@ -39,7 +39,7 @@ describe "Pod::Installer" do ...@@ -39,7 +39,7 @@ describe "Pod::Installer" do
expected = [] expected = []
installer = Pod::Installer.new(podfile) installer = Pod::Installer.new(podfile)
pods = installer.activated_specifications.map do |spec| pods = installer.activated_specifications.map do |spec|
spec.header_files.each do |header| spec.header_files[:ios].each do |header|
expected << config.project_pods_root + header expected << config.project_pods_root + header
end end
Pod::LocalPod.new(spec, installer.sandbox) Pod::LocalPod.new(spec, installer.sandbox)
......
...@@ -31,8 +31,12 @@ describe Pod::LocalPod do ...@@ -31,8 +31,12 @@ describe Pod::LocalPod do
end end
it 'returns an expanded list of source files, relative to the sandbox root' do it 'returns an expanded list of source files, relative to the sandbox root' do
@pod.source_files.sort.should == [ @pod.source_files[:ios].sort.should == [
Pathname.new("BananaLib/Classes/Banana.m"), Pathname.new("BananaLib/Classes/Banana.m"),
Pathname.new("BananaLib/Classes/Banana.h")
].sort
@pod.source_files[:osx].sort.should == [
Pathname.new("BananaLib/Classes/Banana.m"),
Pathname.new("BananaLib/Classes/Banana.h") Pathname.new("BananaLib/Classes/Banana.h")
].sort ].sort
end end
...@@ -46,7 +50,8 @@ describe Pod::LocalPod do ...@@ -46,7 +50,8 @@ describe Pod::LocalPod do
end end
it 'returns a list of header files' do it 'returns a list of header files' do
@pod.header_files.should == [Pathname.new("BananaLib/Classes/Banana.h")] @pod.header_files[:ios].should == [Pathname.new("BananaLib/Classes/Banana.h")]
@pod.header_files[:osx].should == [Pathname.new("BananaLib/Classes/Banana.h")]
end end
it 'can clean up after itself' do it 'can clean up after itself' do
......
...@@ -53,24 +53,25 @@ describe "A Pod::Specification loaded from a podspec" do ...@@ -53,24 +53,25 @@ describe "A Pod::Specification loaded from a podspec" do
end end
it "returns the pod's source files" do it "returns the pod's source files" do
@spec.source_files.should == ['Classes/*.{h,m}', 'Vendor'] @spec.source_files[:ios].should == ['Classes/*.{h,m}', 'Vendor']
@spec.source_files[:osx].should == ['Classes/*.{h,m}', 'Vendor']
end end
it "returns the pod's dependencies" do it "returns the pod's dependencies" do
expected = Pod::Dependency.new('monkey', '~> 1.0.1', '< 1.0.9') expected = Pod::Dependency.new('monkey', '~> 1.0.1', '< 1.0.9')
@spec.dependencies.should == [expected] @spec.dependencies.should == { :ios => [expected], :osx => [expected] }
@spec.dependency_by_top_level_spec_name('monkey').should == expected @spec.dependency_by_top_level_spec_name('monkey').should == expected
end end
it "returns the pod's xcconfig settings" do it "returns the pod's xcconfig settings" do
@spec.xcconfig.to_hash.should == { @spec.xcconfig[:ios].should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration' 'OTHER_LDFLAGS' => '-framework SystemConfiguration'
} }
end end
it "has a shortcut to add frameworks to the xcconfig" do it "has a shortcut to add frameworks to the xcconfig" do
@spec.frameworks = 'CFNetwork', 'CoreText' @spec.frameworks = 'CFNetwork', 'CoreText'
@spec.xcconfig.to_hash.should == { @spec.xcconfig[:ios].should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration ' \ 'OTHER_LDFLAGS' => '-framework SystemConfiguration ' \
'-framework CFNetwork ' \ '-framework CFNetwork ' \
'-framework CoreText' '-framework CoreText'
...@@ -79,7 +80,7 @@ describe "A Pod::Specification loaded from a podspec" do ...@@ -79,7 +80,7 @@ describe "A Pod::Specification loaded from a podspec" do
it "has a shortcut to add libraries to the xcconfig" do it "has a shortcut to add libraries to the xcconfig" do
@spec.libraries = 'z', 'xml2' @spec.libraries = 'z', 'xml2'
@spec.xcconfig.to_hash.should == { @spec.xcconfig[:ios].should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration -lz -lxml2' 'OTHER_LDFLAGS' => '-framework SystemConfiguration -lz -lxml2'
} }
end end
...@@ -97,10 +98,9 @@ describe "A Pod::Specification loaded from a podspec" do ...@@ -97,10 +98,9 @@ describe "A Pod::Specification loaded from a podspec" do
it "adds compiler flags if ARC is required" do it "adds compiler flags if ARC is required" do
@spec.requires_arc = true @spec.requires_arc = true
@spec.compiler_flags.should == " -fobjc-arc" @spec.compiler_flags.should == { :ios => "-fobjc-arc", :osx => "-fobjc-arc" }
@spec.compiler_flags = "-Wunused-value" @spec.compiler_flags = "-Wunused-value"
@spec.compiler_flags.should == "-Wunused-value -fobjc-arc" @spec.compiler_flags.should == { :ios => "-fobjc-arc -Wunused-value", :osx => "-fobjc-arc -Wunused-value" }
end end
end end
...@@ -120,13 +120,13 @@ describe "A Pod::Specification that's part of another pod's source" do ...@@ -120,13 +120,13 @@ describe "A Pod::Specification that's part of another pod's source" do
dep = Pod::Dependency.new('monkey', '>= 1') dep = Pod::Dependency.new('monkey', '>= 1')
@spec.dependencies.should.not == [dep] @spec.dependencies.should.not == [dep]
dep.only_part_of_other_pod = true dep.only_part_of_other_pod = true
@spec.dependencies.should == [dep] @spec.dependencies.should == { :ios => [dep], :osx => [dep] }
end end
it "adds a dependency on the other pod's source *and* the library" do it "adds a dependency on the other pod's source *and* the library" do
@spec.part_of_dependency = 'monkey', '>= 1' @spec.part_of_dependency = 'monkey', '>= 1'
@spec.should.be.part_of_other_pod @spec.should.be.part_of_other_pod
@spec.dependencies.should == [Pod::Dependency.new('monkey', '>= 1')] @spec.dependencies[:ios].should == [Pod::Dependency.new('monkey', '>= 1')]
end end
it "searches the sources for a matching specification if it has not been assigned by the Resolver yet (e.g. the search command)" do it "searches the sources for a matching specification if it has not been assigned by the Resolver yet (e.g. the search command)" do
...@@ -161,18 +161,18 @@ describe "A Pod::Specification, with installed source," do ...@@ -161,18 +161,18 @@ describe "A Pod::Specification, with installed source," do
it "returns the list of files that the source_files pattern expand to" do it "returns the list of files that the source_files pattern expand to" do
files = @destroot.glob('**/*.{h,c,m}') files = @destroot.glob('**/*.{h,c,m}')
files = files.map { |file| file.relative_path_from(config.project_pods_root) } files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.expanded_source_files.sort.should == files.sort @spec.expanded_source_files[:ios].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(config.project_pods_root) } files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.header_files.sort.should == files.sort @spec.header_files[:ios].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[:ios].size.should == 1
@spec.copy_header_mappings[Pathname.new('SSZipArchive')].sort.should == %w{ @spec.copy_header_mappings[:ios][Pathname.new('SSZipArchive')].sort.should == %w{
SSZipArchive.h SSZipArchive.h
minizip/crypt.h minizip/crypt.h
minizip/ioapi.h minizip/ioapi.h
...@@ -186,8 +186,8 @@ describe "A Pod::Specification, with installed source," do ...@@ -186,8 +186,8 @@ describe "A Pod::Specification, with installed source," do
def @spec.copy_header_mapping(from) def @spec.copy_header_mapping(from)
Pathname.new('ns') + from.basename Pathname.new('ns') + from.basename
end end
@spec.copy_header_mappings.size.should == 1 @spec.copy_header_mappings[:ios].size.should == 1
@spec.copy_header_mappings[Pathname.new('SSZipArchive/ns')].sort.should == %w{ @spec.copy_header_mappings[:ios][Pathname.new('SSZipArchive/ns')].sort.should == %w{
SSZipArchive.h SSZipArchive.h
minizip/crypt.h minizip/crypt.h
minizip/ioapi.h minizip/ioapi.h
...@@ -199,7 +199,7 @@ describe "A Pod::Specification, with installed source," do ...@@ -199,7 +199,7 @@ describe "A Pod::Specification, with installed source," do
it "returns a hash of mappings with a custom header dir prefix" do it "returns a hash of mappings with a custom header dir prefix" do
@spec.header_dir = 'AnotherRoot' @spec.header_dir = 'AnotherRoot'
@spec.copy_header_mappings[Pathname.new('AnotherRoot')].sort.should == %w{ @spec.copy_header_mappings[:ios][Pathname.new('AnotherRoot')].sort.should == %w{
SSZipArchive.h SSZipArchive.h
minizip/crypt.h minizip/crypt.h
minizip/ioapi.h minizip/ioapi.h
...@@ -231,11 +231,13 @@ describe "A Pod::Specification, with installed source," do ...@@ -231,11 +231,13 @@ describe "A Pod::Specification, with installed source," do
end end
it "returns the list of files that the resources pattern expand to" do it "returns the list of files that the resources pattern expand to" do
@spec.expanded_resources.should == [] @spec.expanded_resources.should == {}
@spec.resource = 'LICEN*' @spec.resource = 'LICEN*'
@spec.expanded_resources.map(&:to_s).should == %w{ SSZipArchive/LICENSE } @spec.expanded_resources[:ios].map(&:to_s).should == %w{ SSZipArchive/LICENSE }
@spec.expanded_resources[:osx].map(&:to_s).should == %w{ SSZipArchive/LICENSE }
@spec.resources = 'LICEN*', 'Readme.*' @spec.resources = 'LICEN*', 'Readme.*'
@spec.expanded_resources.map(&:to_s).should == %w{ SSZipArchive/LICENSE SSZipArchive/Readme.markdown } @spec.expanded_resources[:ios].map(&:to_s).should == %w{ SSZipArchive/LICENSE SSZipArchive/Readme.markdown }
@spec.expanded_resources[:osx].map(&:to_s).should == %w{ SSZipArchive/LICENSE SSZipArchive/Readme.markdown }
end end
end end
...@@ -363,8 +365,10 @@ describe "A Pod::Specification subspec" do ...@@ -363,8 +365,10 @@ describe "A Pod::Specification subspec" do
it "depends on the parent spec, if it is a subspec" do it "depends on the parent spec, if it is a subspec" do
dependency = Pod::Dependency.new('MainSpec', '1.2.3').tap { |d| d.only_part_of_other_pod = true } dependency = Pod::Dependency.new('MainSpec', '1.2.3').tap { |d| d.only_part_of_other_pod = true }
@spec.subspecs.first.dependencies.should == [dependency] @spec.subspecs.first.dependencies[:ios].should == [dependency]
@spec.subspecs.first.subspecs.first.dependencies.should == [dependency, Pod::Dependency.new('MainSpec/FirstSubSpec', '1.2.3')] @spec.subspecs.first.dependencies[:osx].should == [dependency]
@spec.subspecs.first.subspecs.first.dependencies[:ios].should == [dependency, Pod::Dependency.new('MainSpec/FirstSubSpec', '1.2.3')]
@spec.subspecs.first.subspecs.first.dependencies[:osx].should == [dependency, Pod::Dependency.new('MainSpec/FirstSubSpec', '1.2.3')]
end end
it "automatically forwards undefined attributes to the top level parent" do it "automatically forwards undefined attributes to the top level parent" do
...@@ -400,13 +404,15 @@ describe "A Pod::Specification with :local source" do ...@@ -400,13 +404,15 @@ describe "A Pod::Specification with :local source" do
it "returns the list of files that the source_files pattern expand to within the local path" do it "returns the list of files that the source_files pattern expand to within the local path" do
files = fixture("integration/JSONKit").glob('**/*.{h,m}') files = fixture("integration/JSONKit").glob('**/*.{h,m}')
files = files.map { |file| file.relative_path_from(config.project_pods_root) } files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.expanded_source_files.sort.should == files.sort @spec.expanded_source_files[:ios].sort.should == files.sort
@spec.expanded_source_files[:osx].sort.should == files.sort
end end
it "returns the list of headers that the source_files pattern expand to within the local path" do it "returns the list of headers that the source_files pattern expand to within the local path" do
files = fixture("integration/JSONKit").glob('**/*.{h}') files = fixture("integration/JSONKit").glob('**/*.{h}')
files = files.map { |file| file.relative_path_from(config.project_pods_root) } files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.header_files.sort.should == files.sort @spec.header_files[:ios].sort.should == files.sort
@spec.header_files[:osx].sort.should == files.sort
end end
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