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
end
def clean_paths
expanded_paths(specification.clean_paths)
expand_paths(specification.clean_paths)
end
def resources
......@@ -65,7 +65,9 @@ module Pod
end
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
def link_headers
......@@ -87,7 +89,9 @@ module Pod
private
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
def relative_root
......@@ -95,6 +99,14 @@ module Pod
end
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|
from_without_prefix = from.relative_path_from(relative_root)
to = specification.header_dir + specification.copy_header_mapping(from_without_prefix)
......@@ -103,15 +115,23 @@ module Pod
end
end
def expanded_paths(patterns, options={})
patterns.map do |pattern|
def expanded_paths(platforms_with_patterns, options = {})
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
if pattern.directory? && options[:glob]
pattern += options[:glob]
end
pattern.glob.map do |file|
pattern.glob.map do |file|
if options[:relative_to_sandbox]
file.relative_path_from(@sandbox.root)
else
......
......@@ -263,7 +263,11 @@ module Pod
end
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
def pod_destroot
......@@ -301,11 +305,13 @@ module Pod
# Returns all resource files of this pod, but relative to the
# project pods root.
def expanded_resources
files = []
resources.each do |pattern|
pattern = pod_destroot + pattern
pattern.glob.each do |file|
files << file.relative_path_from(config.project_pods_root)
files = {}
resources.each do |platform, patterns|
patterns.each do |pattern|
pattern = pod_destroot + pattern
pattern.glob.each do |file|
(files[platform] ||= []) << file.relative_path_from(config.project_pods_root)
end
end
end
files
......@@ -318,12 +324,14 @@ module Pod
# automatically glob for c, c++, Objective-C, and Objective-C++
# 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(config.project_pods_root)
files = {}
source_files.each do |platform, patterns|
patterns.each do |pattern|
pattern = pod_destroot + pattern
pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
pattern.glob.each do |file|
(files[platform] ||= []) << file.relative_path_from(config.project_pods_root)
end
end
end
files
......@@ -331,7 +339,7 @@ module Pod
# Returns only the header files of this pod.
def header_files
expanded_source_files.select { |f| f.extname == '.h' }
expanded_source_files.each { |_, files| files.select! { |f| f.extname == '.h' } }
end
# This method takes a header path and returns the location it should have
......@@ -345,7 +353,7 @@ module Pod
end
# See copy_header_mapping.
def copy_header_mappings
def copy_header_mappings_for_files(header_files)
header_files.inject({}) do |mappings, from|
from_without_prefix = from.relative_path_from(pod_destroot_name)
to = header_dir + copy_header_mapping(from_without_prefix)
......@@ -354,12 +362,23 @@ module Pod
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
# 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 header_search_paths
dirs = [header_dir] + copy_header_mappings.keys
dirs = [header_dir] + copy_header_destinations
dirs.map { |dir| %{"$(PODS_ROOT)/Headers/#{dir}"} }
end
......
......@@ -39,7 +39,7 @@ describe "Pod::Installer" do
expected = []
installer = Pod::Installer.new(podfile)
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
end
Pod::LocalPod.new(spec, installer.sandbox)
......
......@@ -31,8 +31,12 @@ describe Pod::LocalPod do
end
it 'returns an expanded list of source files, relative to the sandbox root' do
@pod.source_files.sort.should == [
Pathname.new("BananaLib/Classes/Banana.m"),
@pod.source_files[:ios].sort.should == [
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")
].sort
end
......@@ -46,7 +50,8 @@ describe Pod::LocalPod do
end
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
it 'can clean up after itself' do
......
......@@ -53,24 +53,25 @@ describe "A Pod::Specification loaded from a podspec" do
end
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
it "returns the pod's dependencies" do
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
end
it "returns the pod's xcconfig settings" do
@spec.xcconfig.to_hash.should == {
@spec.xcconfig[:ios].should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration'
}
end
it "has a shortcut to add frameworks to the xcconfig" do
@spec.frameworks = 'CFNetwork', 'CoreText'
@spec.xcconfig.to_hash.should == {
@spec.xcconfig[:ios].should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration ' \
'-framework CFNetwork ' \
'-framework CoreText'
......@@ -79,7 +80,7 @@ describe "A Pod::Specification loaded from a podspec" do
it "has a shortcut to add libraries to the xcconfig" do
@spec.libraries = 'z', 'xml2'
@spec.xcconfig.to_hash.should == {
@spec.xcconfig[:ios].should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration -lz -lxml2'
}
end
......@@ -97,10 +98,9 @@ describe "A Pod::Specification loaded from a podspec" do
it "adds compiler flags if ARC is required" do
@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.should == "-Wunused-value -fobjc-arc"
@spec.compiler_flags.should == { :ios => "-fobjc-arc -Wunused-value", :osx => "-fobjc-arc -Wunused-value" }
end
end
......@@ -120,13 +120,13 @@ describe "A Pod::Specification that's part of another pod's source" do
dep = Pod::Dependency.new('monkey', '>= 1')
@spec.dependencies.should.not == [dep]
dep.only_part_of_other_pod = true
@spec.dependencies.should == [dep]
@spec.dependencies.should == { :ios => [dep], :osx => [dep] }
end
it "adds a dependency on the other pod's source *and* the library" do
@spec.part_of_dependency = 'monkey', '>= 1'
@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
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
it "returns the list of files that the source_files pattern expand to" do
files = @destroot.glob('**/*.{h,c,m}')
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
it "returns the list of headers" do
files = @destroot.glob('**/*.h')
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
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[Pathname.new('SSZipArchive')].sort.should == %w{
@spec.copy_header_mappings[:ios].size.should == 1
@spec.copy_header_mappings[:ios][Pathname.new('SSZipArchive')].sort.should == %w{
SSZipArchive.h
minizip/crypt.h
minizip/ioapi.h
......@@ -186,8 +186,8 @@ describe "A Pod::Specification, with installed source," do
def @spec.copy_header_mapping(from)
Pathname.new('ns') + from.basename
end
@spec.copy_header_mappings.size.should == 1
@spec.copy_header_mappings[Pathname.new('SSZipArchive/ns')].sort.should == %w{
@spec.copy_header_mappings[:ios].size.should == 1
@spec.copy_header_mappings[:ios][Pathname.new('SSZipArchive/ns')].sort.should == %w{
SSZipArchive.h
minizip/crypt.h
minizip/ioapi.h
......@@ -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
@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
minizip/crypt.h
minizip/ioapi.h
......@@ -231,11 +231,13 @@ describe "A Pod::Specification, with installed source," do
end
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.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.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
......@@ -363,8 +365,10 @@ describe "A Pod::Specification 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 }
@spec.subspecs.first.dependencies.should == [dependency]
@spec.subspecs.first.subspecs.first.dependencies.should == [dependency, Pod::Dependency.new('MainSpec/FirstSubSpec', '1.2.3')]
@spec.subspecs.first.dependencies[:ios].should == [dependency]
@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
it "automatically forwards undefined attributes to the top level parent" 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
files = fixture("integration/JSONKit").glob('**/*.{h,m}')
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
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 = 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
......
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