Commit fcdd011c authored by Eloy Duran's avatar Eloy Duran

LocalPod only returns file lists for the platform of the current target.

And lots of misc. work. Still failing: https://gist.github.com/9fffdffb35da111e6442
parent 4e3dc124
...@@ -6,7 +6,7 @@ process do |files| ...@@ -6,7 +6,7 @@ process do |files|
specs = files.take_and_map do |file| specs = files.take_and_map do |file|
case file case file
when %r{lib/cocoapods/installer.+\.rb$} when %r{lib/cocoapods/installer.+\.rb$}
['spec/unit/installer_spec.rb', 'spec/unit/target_installer_spec.rb'] ['spec/unit/installer_spec.rb', 'spec/unit/installer/target_installer_spec.rb']
when %r{lib/cocoapods/(.+?)\.rb$} when %r{lib/cocoapods/(.+?)\.rb$}
s = Dir.glob("spec/**/#{$1}_spec.rb") s = Dir.glob("spec/**/#{$1}_spec.rb")
s unless s.empty? s unless s.empty?
......
...@@ -76,8 +76,8 @@ module Pod ...@@ -76,8 +76,8 @@ module Pod
version.empty? ? @name : "#{@name} (#{version})" version.empty? ? @name : "#{@name} (#{version})"
end end
def specification_from_sandbox(sandbox) def specification_from_sandbox(sandbox, platform)
@external_source.specification_from_sandbox(sandbox) @external_source.specification_from_sandbox(sandbox, platform)
end end
# Taken from RubyGems 1.3.7 # Taken from RubyGems 1.3.7
...@@ -128,36 +128,37 @@ module Pod ...@@ -128,36 +128,37 @@ module Pod
end end
class AbstractExternalSource class AbstractExternalSource
include Config::Mixin
attr_reader :name, :params attr_reader :name, :params
def initialize(name, params) def initialize(name, params)
@name, @params = name, params @name, @params = name, params
end end
def specification_from_sandbox(sandbox) def specification_from_sandbox(sandbox, platform)
if local_pod = sandbox.installed_pod_named(name) if local_pod = sandbox.installed_pod_named(name, platform)
local_pod.specification local_pod.specification
else else
copy_external_source_into_sandbox(sandbox) copy_external_source_into_sandbox(sandbox)
local_pod = sandbox.installed_pod_named(name) local_pod = sandbox.installed_pod_named(name, platform)
local_pod.clean if Config.instance.clean local_pod.clean if config.clean?
local_pod.specification local_pod.specification
end end
end end
def ==(other_source) def ==(other_source)
return if other_source.nil? return if other_source.nil?
name == other_source.name && name == other_source.name && params == other_source.params
params == other_source.params
end end
end end
class GitSource < AbstractExternalSource class GitSource < AbstractExternalSource
def copy_external_source_into_sandbox(sandbox) def copy_external_source_into_sandbox(sandbox)
puts " * Pre-downloading: '#{name}'" unless Config.instance.silent? puts " * Pre-downloading: '#{name}'" unless config.silent?
Downloader.for_target(sandbox.root + name, @params).tap do |downloader| Downloader.for_target(sandbox.root + name, @params).tap do |downloader|
downloader.download downloader.download
downloader.clean if Config.instance.clean downloader.clean if config.clean?
end end
end end
...@@ -174,7 +175,7 @@ module Pod ...@@ -174,7 +175,7 @@ module Pod
def copy_external_source_into_sandbox(sandbox) def copy_external_source_into_sandbox(sandbox)
output_path = sandbox.root + "Local Podspecs/#{name}.podspec" output_path = sandbox.root + "Local Podspecs/#{name}.podspec"
output_path.dirname.mkpath output_path.dirname.mkpath
puts " * Fetching podspec for `#{name}' from: #{@params[:podspec]}" unless Config.instance.silent? puts " * Fetching podspec for `#{name}' from: #{@params[:podspec]}" unless config.silent?
open(@params[:podspec]) do |io| open(@params[:podspec]) do |io|
output_path.open('w') { |f| f << io.read } output_path.open('w') { |f| f << io.read }
end end
......
...@@ -44,7 +44,8 @@ module Pod ...@@ -44,7 +44,8 @@ module Pod
def install_dependencies! def install_dependencies!
activated_specifications.map do |spec| activated_specifications.map do |spec|
LocalPod.new(spec, sandbox).tap do |pod| # TODO @podfile.platform will change to target_definition.platform
LocalPod.new(spec, sandbox, @podfile.platform).tap do |pod|
marker = config.verbose ? "\n-> ".green : '' marker = config.verbose ? "\n-> ".green : ''
should_install = !pod.exists? && !spec.local? should_install = !pod.exists? && !spec.local?
...@@ -115,7 +116,9 @@ module Pod ...@@ -115,7 +116,9 @@ module Pod
lock_file.open('w') do |file| lock_file.open('w') do |file|
file.puts "PODS:" file.puts "PODS:"
pods.map do |pod| pods.map do |pod|
[pod.specification.to_s, pod.specification.dependencies.map(&:to_s).sort] # TODO this should list _all_ the pods, so merge the platforms
dependencies = pod.specification.dependencies.values.flatten.uniq
[pod.specification.to_s, dependencies.map(&:to_s).sort]
end.sort_by(&:first).each do |name, deps| end.sort_by(&:first).each do |name, deps|
if deps.empty? if deps.empty?
file.puts " - #{name}" file.puts " - #{name}"
......
...@@ -55,7 +55,8 @@ module Pod ...@@ -55,7 +55,8 @@ module Pod
@target = @project.targets.new_static_library(@target_definition.label) @target = @project.targets.new_static_library(@target_definition.label)
pods.each do |pod| pods.each do |pod|
xcconfig.merge!(pod.specification.xcconfig) # TODO add methods like xcconfig to LocalPod as well? (which returns the correct platform)
xcconfig.merge!(pod.specification.xcconfig[@podfile.platform.to_sym])
pod.add_to_target(@target) pod.add_to_target(@target)
# TODO: this doesn't need to be done here, it has nothing to do with the target # TODO: this doesn't need to be done here, it has nothing to do with the target
......
...@@ -2,13 +2,14 @@ module Pod ...@@ -2,13 +2,14 @@ module Pod
class LocalPod class LocalPod
attr_reader :specification attr_reader :specification
attr_reader :sandbox attr_reader :sandbox
attr_reader :platform
def initialize(specification, sandbox) def initialize(specification, sandbox, platform)
@specification, @sandbox = specification, sandbox @specification, @sandbox, @platform = specification, sandbox, platform
end end
def self.from_podspec(podspec, sandbox) def self.from_podspec(podspec, sandbox, platform)
new(Specification.from_file(podspec), sandbox) new(Specification.from_file(podspec), sandbox, platform)
end end
def root def root
...@@ -57,7 +58,7 @@ module Pod ...@@ -57,7 +58,7 @@ module Pod
end end
def clean_paths def clean_paths
expand_paths(specification.clean_paths) expanded_paths(specification.clean_paths)
end end
def resources def resources
...@@ -65,9 +66,7 @@ module Pod ...@@ -65,9 +66,7 @@ module Pod
end end
def header_files def header_files
result = {} source_files.select { |f| f.extname == '.h' }
source_files.each { |platform, files| result[platform] = files.select { |f| f.extname == '.h' } }
result
end end
def link_headers def link_headers
...@@ -78,7 +77,7 @@ module Pod ...@@ -78,7 +77,7 @@ module Pod
def add_to_target(target) def add_to_target(target)
implementation_files.each do |file| implementation_files.each do |file|
target.add_source_file(file, nil, specification.compiler_flags) target.add_source_file(file, nil, specification.compiler_flags[@platform.to_sym])
end end
end end
...@@ -89,24 +88,16 @@ module Pod ...@@ -89,24 +88,16 @@ module Pod
private private
def implementation_files def implementation_files
result = {} source_files.select { |f| f.extname != '.h' }
source_files.each { |platform, files| result[platform] = files.select { |f| f.extname != '.h' } }
result
end end
def relative_root def relative_root
root.relative_path_from(@sandbox.root) root.relative_path_from(@sandbox.root)
end 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 # 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. # something with that, and this method also still exists in Specification.
def copy_header_mappings_for_files(header_files) def copy_header_mappings
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)
...@@ -116,14 +107,8 @@ module Pod ...@@ -116,14 +107,8 @@ module Pod
end end
def expanded_paths(platforms_with_patterns, options = {}) def expanded_paths(platforms_with_patterns, options = {})
paths = {} patterns = platforms_with_patterns.is_a?(Hash) ? (platforms_with_patterns[@platform.to_sym] || []) : platforms_with_patterns
platforms_with_patterns.each do |platform, patterns| p platforms_with_patterns if patterns.nil?
paths[platform] = expand_paths(patterns, options)
end
paths
end
def expand_paths(patterns, options = {})
patterns.map do |pattern| patterns.map do |pattern|
pattern = root + pattern pattern = root + pattern
......
...@@ -15,13 +15,14 @@ module Pod ...@@ -15,13 +15,14 @@ module Pod
def resolve def resolve
@specs = {} @specs = {}
targets_and_specs = {}
result = @podfile.target_definitions.values.inject({}) do |result, target_definition| @podfile.target_definitions.values.each do |target_definition|
puts "\nResolving dependencies for target `#{target_definition.name}'".green if config.verbose? puts "\nResolving dependencies for target `#{target_definition.name}'".green if config.verbose?
@loaded_specs = [] @loaded_specs = []
find_dependency_sets(@podfile, target_definition.dependencies) # TODO @podfile.platform will change to target_definition.platform
result[target_definition] = @specs.values_at(*@loaded_specs).sort_by(&:name) find_dependency_sets(@podfile, target_definition.dependencies, @podfile.platform)
result targets_and_specs[target_definition] = @specs.values_at(*@loaded_specs).sort_by(&:name)
end end
# Specification doesn't need to know more about the context, so we assign # Specification doesn't need to know more about the context, so we assign
...@@ -32,17 +33,20 @@ module Pod ...@@ -32,17 +33,20 @@ module Pod
end end
end end
result targets_and_specs
end end
private private
def find_cached_set(dependency) def find_cached_set(dependency, platform)
@cached_sets[dependency.name] ||= begin @cached_sets[dependency.name] ||= begin
if dependency.specification if dependency.specification
Specification::Set::External.new(dependency.specification) Specification::Set::External.new(dependency.specification)
elsif external_source = dependency.external_source elsif external_source = dependency.external_source
specification = external_source.specification_from_sandbox(@sandbox) # The platform isn't actually being used by the LocalPod instance
# that's being used behind the scenes, but passing it anyways for
# completeness sake.
specification = external_source.specification_from_sandbox(@sandbox, platform)
Specification::Set::External.new(specification) Specification::Set::External.new(specification)
else else
@cached_sources.search(dependency) @cached_sources.search(dependency)
...@@ -50,13 +54,13 @@ module Pod ...@@ -50,13 +54,13 @@ module Pod
end end
end end
def find_dependency_sets(dependent_specification, dependencies) def find_dependency_sets(dependent_specification, dependencies, platform)
@log_indent += 1 @log_indent += 1
dependencies.each do |dependency| dependencies.each do |dependency|
puts ' ' * @log_indent + "- #{dependency}" if config.verbose? puts ' ' * @log_indent + "- #{dependency}" if config.verbose?
set = find_cached_set(dependency) set = find_cached_set(dependency, platform)
set.required_by(dependent_specification) set.required_by(dependent_specification)
# Ensure we don't resolve the same spec twice # Ensure we don't resolve the same spec twice for one target
unless @loaded_specs.include?(dependency.name) unless @loaded_specs.include?(dependency.name)
# Get a reference to the spec that’s actually being loaded. # Get a reference to the spec that’s actually being loaded.
# If it’s a subspec dependency, e.g. 'RestKit/Network', then # If it’s a subspec dependency, e.g. 'RestKit/Network', then
...@@ -72,7 +76,8 @@ module Pod ...@@ -72,7 +76,8 @@ module Pod
@specs[spec.name] = spec @specs[spec.name] = spec
# And recursively load the dependencies of the spec. # And recursively load the dependencies of the spec.
find_dependency_sets(spec, spec.dependencies) # TODO fix the need to return an empty arrayf if there are no deps for the given platform
find_dependency_sets(spec, (spec.dependencies[platform.to_sym] || []), platform)
end end
end end
@log_indent -= 1 @log_indent -= 1
......
...@@ -54,9 +54,9 @@ module Pod ...@@ -54,9 +54,9 @@ module Pod
end end
end end
def installed_pod_named(name) def installed_pod_named(name, platform)
if spec_path = podspec_for_name(name) if spec_path = podspec_for_name(name)
LocalPod.from_podspec(spec_path, self) LocalPod.from_podspec(spec_path, self, platform)
end end
end end
end end
......
...@@ -34,11 +34,11 @@ module Pod ...@@ -34,11 +34,11 @@ module Pod
@define_for_platforms = [:osx, :ios] @define_for_platforms = [:osx, :ios]
#@dependencies, @source_files, @resources, @clean_paths, @subspecs = [], [], [], [], [] #@dependencies, @source_files, @resources, @clean_paths, @subspecs = [], [], [], [], []
@clean_paths, @subspecs = [], [] @clean_paths, @subspecs = [], []
@dependencies, @source_files, @resources = {}, {}, {} @dependencies, @source_files, @resources = { :ios => [], :osx => [] }, { :ios => [], :osx => [] }, { :ios => [], :osx => [] }
@platform = Platform.new(nil) @platform = Platform.new(nil)
#@xcconfig = Xcodeproj::Config.new #@xcconfig = Xcodeproj::Config.new
@xcconfig = {} @xcconfig = { :ios => Xcodeproj::Config.new, :osx => Xcodeproj::Config.new }
@compiler_flags = {} @compiler_flags = { :ios => '', :osx => '' }
end end
# Attributes **without** multiple platform support # Attributes **without** multiple platform support
...@@ -167,7 +167,7 @@ module Pod ...@@ -167,7 +167,7 @@ module Pod
def xcconfig=(build_settings) def xcconfig=(build_settings)
@define_for_platforms.each do |platform| @define_for_platforms.each do |platform|
(@xcconfig[platform] ||= Xcodeproj::Config.new).merge!(build_settings) @xcconfig[platform].merge!(build_settings)
end end
end end
attr_reader :xcconfig attr_reader :xcconfig
...@@ -187,11 +187,7 @@ module Pod ...@@ -187,11 +187,7 @@ module Pod
attr_reader :compiler_flags attr_reader :compiler_flags
def compiler_flags=(flags) def compiler_flags=(flags)
@define_for_platforms.each do |platform| @define_for_platforms.each do |platform|
if @compiler_flags[platform]
@compiler_flags[platform] << ' ' << flags @compiler_flags[platform] << ' ' << flags
else
@compiler_flags[platform] = flags.dup
end
end end
end end
...@@ -199,7 +195,7 @@ module Pod ...@@ -199,7 +195,7 @@ module Pod
name, *version_requirements = name_and_version_requirements.flatten name, *version_requirements = name_and_version_requirements.flatten
dep = Dependency.new(name, *version_requirements) dep = Dependency.new(name, *version_requirements)
@define_for_platforms.each do |platform| @define_for_platforms.each do |platform|
(@dependencies[platform] ||= []) << dep @dependencies[platform] << dep
end end
dep dep
end end
...@@ -239,7 +235,7 @@ module Pod ...@@ -239,7 +235,7 @@ module Pod
end end
def wrapper? def wrapper?
source_files.empty? && !subspecs.empty? source_files.values.flatten.empty? && !subspecs.empty?
end end
def subspec_by_name(name) def subspec_by_name(name)
......
Subproject commit 5e19daf9a13f708108483037f9cd2c778f239475 Subproject commit e69109bd31a191be333e9b502c83e7da9e789e04
...@@ -19,7 +19,7 @@ describe Pod::Installer::TargetInstaller do ...@@ -19,7 +19,7 @@ describe Pod::Installer::TargetInstaller do
@sandbox = Pod::Sandbox.new(TMP_POD_ROOT) @sandbox = Pod::Sandbox.new(TMP_POD_ROOT)
@specification = fixture_spec('banana-lib/BananaLib.podspec') @specification = fixture_spec('banana-lib/BananaLib.podspec')
@pods = [Pod::LocalPod.new(@specification, @sandbox)] @pods = [Pod::LocalPod.new(@specification, @sandbox, platform)]
end end
def do_install! def do_install!
......
...@@ -42,7 +42,7 @@ describe "Pod::Installer" do ...@@ -42,7 +42,7 @@ describe "Pod::Installer" do
spec.header_files[:ios].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, podfile.platform)
end end
installer.target_installers.first.bridge_support_generator_for(pods, installer.sandbox).headers.should == expected installer.target_installers.first.bridge_support_generator_for(pods, installer.sandbox).headers.should == expected
end end
......
...@@ -6,7 +6,7 @@ describe Pod::LocalPod do ...@@ -6,7 +6,7 @@ describe Pod::LocalPod do
before do before do
@sandbox = temporary_sandbox @sandbox = temporary_sandbox
@pod = Pod::LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), @sandbox) @pod = Pod::LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), @sandbox, Pod::Platform.new(:ios))
copy_fixture_to_pod('banana-lib', @pod) copy_fixture_to_pod('banana-lib', @pod)
end end
...@@ -31,11 +31,7 @@ describe Pod::LocalPod do ...@@ -31,11 +31,7 @@ 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[:ios].sort.should == [ @pod.source_files.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.m"),
Pathname.new("BananaLib/Classes/Banana.h") Pathname.new("BananaLib/Classes/Banana.h")
].sort ].sort
...@@ -50,8 +46,7 @@ describe Pod::LocalPod do ...@@ -50,8 +46,7 @@ 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[:ios].should == [Pathname.new("BananaLib/Classes/Banana.h")] @pod.header_files.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
......
...@@ -98,9 +98,9 @@ describe "A Pod::Specification loaded from a podspec" do ...@@ -98,9 +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 == { :ios => "-fobjc-arc", :osx => "-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 == { :ios => "-fobjc-arc -Wunused-value", :osx => "-fobjc-arc -Wunused-value" } @spec.compiler_flags.should == { :ios => " -fobjc-arc -Wunused-value", :osx => " -fobjc-arc -Wunused-value" }
end end
end end
...@@ -447,7 +447,7 @@ describe "A Pod::Specification, concerning its attributes that support different ...@@ -447,7 +447,7 @@ describe "A Pod::Specification, concerning its attributes that support different
end end
it "returns the same list of compiler flags for each platform" do it "returns the same list of compiler flags for each platform" do
compiler_flags = '-Wdeprecated-implementations -fobjc-arc' compiler_flags = ' -Wdeprecated-implementations -fobjc-arc'
@spec.compiler_flags.should == { :ios => compiler_flags, :osx => compiler_flags } @spec.compiler_flags.should == { :ios => compiler_flags, :osx => compiler_flags }
end end
...@@ -502,8 +502,8 @@ describe "A Pod::Specification, concerning its attributes that support different ...@@ -502,8 +502,8 @@ describe "A Pod::Specification, concerning its attributes that support different
it "returns the same list of compiler flags for each platform" do it "returns the same list of compiler flags for each platform" do
@spec.compiler_flags.should == { @spec.compiler_flags.should == {
:ios => '-Wdeprecated-implementations -fobjc-arc', :ios => ' -Wdeprecated-implementations -fobjc-arc',
:osx => '-Wfloat-equal -fobjc-arc' :osx => ' -Wfloat-equal -fobjc-arc'
} }
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