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|
specs = files.take_and_map do |file|
case file
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$}
s = Dir.glob("spec/**/#{$1}_spec.rb")
s unless s.empty?
......
......@@ -76,8 +76,8 @@ module Pod
version.empty? ? @name : "#{@name} (#{version})"
end
def specification_from_sandbox(sandbox)
@external_source.specification_from_sandbox(sandbox)
def specification_from_sandbox(sandbox, platform)
@external_source.specification_from_sandbox(sandbox, platform)
end
# Taken from RubyGems 1.3.7
......@@ -128,36 +128,37 @@ module Pod
end
class AbstractExternalSource
include Config::Mixin
attr_reader :name, :params
def initialize(name, params)
@name, @params = name, params
end
def specification_from_sandbox(sandbox)
if local_pod = sandbox.installed_pod_named(name)
def specification_from_sandbox(sandbox, platform)
if local_pod = sandbox.installed_pod_named(name, platform)
local_pod.specification
else
copy_external_source_into_sandbox(sandbox)
local_pod = sandbox.installed_pod_named(name)
local_pod.clean if Config.instance.clean
local_pod = sandbox.installed_pod_named(name, platform)
local_pod.clean if config.clean?
local_pod.specification
end
end
def ==(other_source)
return if other_source.nil?
name == other_source.name &&
params == other_source.params
name == other_source.name && params == other_source.params
end
end
class GitSource < AbstractExternalSource
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.download
downloader.clean if Config.instance.clean
downloader.clean if config.clean?
end
end
......@@ -174,7 +175,7 @@ module Pod
def copy_external_source_into_sandbox(sandbox)
output_path = sandbox.root + "Local Podspecs/#{name}.podspec"
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|
output_path.open('w') { |f| f << io.read }
end
......
......@@ -44,7 +44,8 @@ module Pod
def install_dependencies!
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 : ''
should_install = !pod.exists? && !spec.local?
......@@ -115,7 +116,9 @@ module Pod
lock_file.open('w') do |file|
file.puts "PODS:"
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|
if deps.empty?
file.puts " - #{name}"
......
......@@ -55,7 +55,8 @@ module Pod
@target = @project.targets.new_static_library(@target_definition.label)
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)
# TODO: this doesn't need to be done here, it has nothing to do with the target
......
......@@ -2,13 +2,14 @@ module Pod
class LocalPod
attr_reader :specification
attr_reader :sandbox
attr_reader :platform
def initialize(specification, sandbox)
@specification, @sandbox = specification, sandbox
def initialize(specification, sandbox, platform)
@specification, @sandbox, @platform = specification, sandbox, platform
end
def self.from_podspec(podspec, sandbox)
new(Specification.from_file(podspec), sandbox)
def self.from_podspec(podspec, sandbox, platform)
new(Specification.from_file(podspec), sandbox, platform)
end
def root
......@@ -57,7 +58,7 @@ module Pod
end
def clean_paths
expand_paths(specification.clean_paths)
expanded_paths(specification.clean_paths)
end
def resources
......@@ -65,9 +66,7 @@ module Pod
end
def header_files
result = {}
source_files.each { |platform, files| result[platform] = files.select { |f| f.extname == '.h' } }
result
source_files.select { |f| f.extname == '.h' }
end
def link_headers
......@@ -78,7 +77,7 @@ module Pod
def add_to_target(target)
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
......@@ -89,24 +88,16 @@ module Pod
private
def implementation_files
result = {}
source_files.each { |platform, files| result[platform] = files.select { |f| f.extname != '.h' } }
result
source_files.select { |f| f.extname != '.h' }
end
def relative_root
root.relative_path_from(@sandbox.root)
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)
def copy_header_mappings
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)
......@@ -116,14 +107,8 @@ module Pod
end
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 = platforms_with_patterns.is_a?(Hash) ? (platforms_with_patterns[@platform.to_sym] || []) : platforms_with_patterns
p platforms_with_patterns if patterns.nil?
patterns.map do |pattern|
pattern = root + pattern
......
......@@ -15,13 +15,14 @@ module Pod
def resolve
@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?
@loaded_specs = []
find_dependency_sets(@podfile, target_definition.dependencies)
result[target_definition] = @specs.values_at(*@loaded_specs).sort_by(&:name)
result
# TODO @podfile.platform will change to target_definition.platform
find_dependency_sets(@podfile, target_definition.dependencies, @podfile.platform)
targets_and_specs[target_definition] = @specs.values_at(*@loaded_specs).sort_by(&:name)
end
# Specification doesn't need to know more about the context, so we assign
......@@ -32,17 +33,20 @@ module Pod
end
end
result
targets_and_specs
end
private
def find_cached_set(dependency)
def find_cached_set(dependency, platform)
@cached_sets[dependency.name] ||= begin
if dependency.specification
Specification::Set::External.new(dependency.specification)
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)
else
@cached_sources.search(dependency)
......@@ -50,13 +54,13 @@ module Pod
end
end
def find_dependency_sets(dependent_specification, dependencies)
def find_dependency_sets(dependent_specification, dependencies, platform)
@log_indent += 1
dependencies.each do |dependency|
puts ' ' * @log_indent + "- #{dependency}" if config.verbose?
set = find_cached_set(dependency)
set = find_cached_set(dependency, platform)
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)
# Get a reference to the spec that’s actually being loaded.
# If it’s a subspec dependency, e.g. 'RestKit/Network', then
......@@ -72,7 +76,8 @@ module Pod
@specs[spec.name] = 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
@log_indent -= 1
......
......@@ -54,9 +54,9 @@ module Pod
end
end
def installed_pod_named(name)
def installed_pod_named(name, platform)
if spec_path = podspec_for_name(name)
LocalPod.from_podspec(spec_path, self)
LocalPod.from_podspec(spec_path, self, platform)
end
end
end
......
......@@ -34,11 +34,11 @@ module Pod
@define_for_platforms = [:osx, :ios]
#@dependencies, @source_files, @resources, @clean_paths, @subspecs = [], [], [], [], []
@clean_paths, @subspecs = [], []
@dependencies, @source_files, @resources = {}, {}, {}
@dependencies, @source_files, @resources = { :ios => [], :osx => [] }, { :ios => [], :osx => [] }, { :ios => [], :osx => [] }
@platform = Platform.new(nil)
#@xcconfig = Xcodeproj::Config.new
@xcconfig = {}
@compiler_flags = {}
@xcconfig = { :ios => Xcodeproj::Config.new, :osx => Xcodeproj::Config.new }
@compiler_flags = { :ios => '', :osx => '' }
end
# Attributes **without** multiple platform support
......@@ -167,7 +167,7 @@ module Pod
def xcconfig=(build_settings)
@define_for_platforms.each do |platform|
(@xcconfig[platform] ||= Xcodeproj::Config.new).merge!(build_settings)
@xcconfig[platform].merge!(build_settings)
end
end
attr_reader :xcconfig
......@@ -187,11 +187,7 @@ module Pod
attr_reader :compiler_flags
def compiler_flags=(flags)
@define_for_platforms.each do |platform|
if @compiler_flags[platform]
@compiler_flags[platform] << ' ' << flags
else
@compiler_flags[platform] = flags.dup
end
end
end
......@@ -199,7 +195,7 @@ module Pod
name, *version_requirements = name_and_version_requirements.flatten
dep = Dependency.new(name, *version_requirements)
@define_for_platforms.each do |platform|
(@dependencies[platform] ||= []) << dep
@dependencies[platform] << dep
end
dep
end
......@@ -239,7 +235,7 @@ module Pod
end
def wrapper?
source_files.empty? && !subspecs.empty?
source_files.values.flatten.empty? && !subspecs.empty?
end
def subspec_by_name(name)
......
Subproject commit 5e19daf9a13f708108483037f9cd2c778f239475
Subproject commit e69109bd31a191be333e9b502c83e7da9e789e04
......@@ -19,7 +19,7 @@ describe Pod::Installer::TargetInstaller do
@sandbox = Pod::Sandbox.new(TMP_POD_ROOT)
@specification = fixture_spec('banana-lib/BananaLib.podspec')
@pods = [Pod::LocalPod.new(@specification, @sandbox)]
@pods = [Pod::LocalPod.new(@specification, @sandbox, platform)]
end
def do_install!
......
......@@ -42,7 +42,7 @@ describe "Pod::Installer" do
spec.header_files[:ios].each do |header|
expected << config.project_pods_root + header
end
Pod::LocalPod.new(spec, installer.sandbox)
Pod::LocalPod.new(spec, installer.sandbox, podfile.platform)
end
installer.target_installers.first.bridge_support_generator_for(pods, installer.sandbox).headers.should == expected
end
......
......@@ -6,7 +6,7 @@ describe Pod::LocalPod do
before do
@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)
end
......@@ -31,11 +31,7 @@ describe Pod::LocalPod do
end
it 'returns an expanded list of source files, relative to the sandbox root' do
@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 == [
@pod.source_files.sort.should == [
Pathname.new("BananaLib/Classes/Banana.m"),
Pathname.new("BananaLib/Classes/Banana.h")
].sort
......@@ -50,8 +46,7 @@ describe Pod::LocalPod do
end
it 'returns a list of header files' do
@pod.header_files[:ios].should == [Pathname.new("BananaLib/Classes/Banana.h")]
@pod.header_files[:osx].should == [Pathname.new("BananaLib/Classes/Banana.h")]
@pod.header_files.should == [Pathname.new("BananaLib/Classes/Banana.h")]
end
it 'can clean up after itself' do
......
......@@ -98,9 +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 == { :ios => "-fobjc-arc", :osx => "-fobjc-arc" }
@spec.compiler_flags.should == { :ios => " -fobjc-arc", :osx => " -fobjc-arc" }
@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
......@@ -447,7 +447,7 @@ describe "A Pod::Specification, concerning its attributes that support different
end
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 }
end
......@@ -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
@spec.compiler_flags.should == {
:ios => '-Wdeprecated-implementations -fobjc-arc',
:osx => '-Wfloat-equal -fobjc-arc'
:ios => ' -Wdeprecated-implementations -fobjc-arc',
:osx => ' -Wfloat-equal -fobjc-arc'
}
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