Commit 9dd91b59 authored by Eloy Duran's avatar Eloy Duran

Move `platform` from Podfile to TargetDefinition.

parent 792e387c
...@@ -20,7 +20,8 @@ module Pod ...@@ -20,7 +20,8 @@ module Pod
def project def project
return @project if @project return @project if @project
@project = Pod::Project.for_platform(@podfile.platform) # TODO this should not init with platform
@project = Pod::Project.for_platform(@podfile.target_definitions[:default].platform)
activated_pods.each do |pod| activated_pods.each do |pod|
# Add all source files to the project grouped by pod # Add all source files to the project grouped by pod
group = @project.add_pod_group(pod.name) group = @project.add_pod_group(pod.name)
...@@ -110,7 +111,7 @@ module Pod ...@@ -110,7 +111,7 @@ module Pod
file.puts "PODS:" file.puts "PODS:"
pods.map do |pod| pods.map do |pod|
# TODO this should list _all_ the pods, so merge the platforms # TODO this should list _all_ the pods, so merge the platforms
dependencies = pod.specification.dependencies[@podfile.platform.to_sym] dependencies = pod.specification.dependencies[@podfile.target_definitions[:default].platform.to_sym]
[pod.specification.to_s, dependencies.map(&:to_s).sort] [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?
...@@ -148,7 +149,7 @@ module Pod ...@@ -148,7 +149,7 @@ module Pod
def activated_pods def activated_pods
activated_specifications.map do |spec| activated_specifications.map do |spec|
# TODO @podfile.platform will change to target_definition.platform # TODO @podfile.platform will change to target_definition.platform
LocalPod.new(spec, sandbox, @podfile.platform) LocalPod.new(spec, sandbox, @podfile.target_definitions[:default].platform)
end end
end end
......
...@@ -38,7 +38,7 @@ module Pod ...@@ -38,7 +38,7 @@ module Pod
def save_prefix_header_as(pathname) def save_prefix_header_as(pathname)
pathname.open('w') do |header| pathname.open('w') do |header|
header.puts "#ifdef __OBJC__" header.puts "#ifdef __OBJC__"
header.puts "#import #{@podfile.platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}" header.puts "#import #{@target_definition.platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}"
header.puts "#endif" header.puts "#endif"
end end
end end
...@@ -56,7 +56,7 @@ module Pod ...@@ -56,7 +56,7 @@ module Pod
pods.each do |pod| pods.each do |pod|
# TODO add methods like xcconfig to LocalPod as well? (which returns the correct platform) # TODO add methods like xcconfig to LocalPod as well? (which returns the correct platform)
xcconfig.merge!(pod.specification.xcconfig[@podfile.platform.to_sym]) xcconfig.merge!(pod.specification.xcconfig[@target_definition.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
......
...@@ -3,17 +3,25 @@ module Pod ...@@ -3,17 +3,25 @@ module Pod
class TargetDefinition class TargetDefinition
attr_reader :name, :target_dependencies attr_reader :name, :target_dependencies
attr_accessor :link_with, :parent attr_accessor :link_with, :platform, :parent, :exclusive
def initialize(name, options = {}) def initialize(name, options = {})
@name, @target_dependencies = name, [] @name, @target_dependencies = name, []
options.each { |k, v| send("#{k}=", v) } options.each { |k, v| send("#{k}=", v) }
end end
def exclusive?
@exclusive
end
def link_with=(targets) def link_with=(targets)
@link_with = targets.is_a?(Array) ? targets : [targets] @link_with = targets.is_a?(Array) ? targets : [targets]
end end
def platform
@platform || @parent.platform
end
def label def label
if name == :default if name == :default
"Pods" "Pods"
...@@ -47,7 +55,7 @@ module Pod ...@@ -47,7 +55,7 @@ module Pod
# Returns *all* dependencies of this target, not only the target specific # Returns *all* dependencies of this target, not only the target specific
# ones in `target_dependencies`. # ones in `target_dependencies`.
def dependencies def dependencies
@target_dependencies + (@parent ? @parent.dependencies : []) @target_dependencies + (exclusive? ? [] : @parent.dependencies)
end end
def empty? def empty?
...@@ -67,7 +75,7 @@ module Pod ...@@ -67,7 +75,7 @@ module Pod
include Config::Mixin include Config::Mixin
def initialize(&block) def initialize(&block)
@target_definitions = { :default => (@target_definition = TargetDefinition.new(:default)) } @target_definitions = { :default => (@target_definition = TargetDefinition.new(:default, :exclusive => true)) }
instance_eval(&block) instance_eval(&block)
end end
...@@ -82,8 +90,8 @@ module Pod ...@@ -82,8 +90,8 @@ module Pod
# platform :ios, :deployment_target => "4.0" # platform :ios, :deployment_target => "4.0"
# #
# If the deployment target requires it (< 4.3), armv6 will be added to ARCHS. # If the deployment target requires it (< 4.3), armv6 will be added to ARCHS.
def platform(platform = nil, options={}) def platform(platform, options={})
platform ? @platform = Platform.new(platform, options) : @platform @target_definition.platform = Platform.new(platform, options)
end end
# Specifies the target(s) in the user’s project that this Pods library # Specifies the target(s) in the user’s project that this Pods library
...@@ -239,7 +247,7 @@ module Pod ...@@ -239,7 +247,7 @@ module Pod
# dependency (JSONKit). # dependency (JSONKit).
def target(name, options = {}) def target(name, options = {})
parent = @target_definition parent = @target_definition
options[:parent] = parent unless options.delete(:exclusive) options[:parent] = parent
@target_definitions[name] = @target_definition = TargetDefinition.new(name, options) @target_definitions[name] = @target_definition = TargetDefinition.new(name, options)
yield yield
ensure ensure
...@@ -306,10 +314,10 @@ module Pod ...@@ -306,10 +314,10 @@ module Pod
end end
def validate! def validate!
lines = [] #lines = []
lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless @platform && [:osx, :ios].include?(@platform.name) #lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless @platform && [:osx, :ios].include?(@platform.name)
lines << "* no dependencies were specified, which is, well, kinda pointless" if dependencies.empty? #lines << "* no dependencies were specified, which is, well, kinda pointless" if dependencies.empty?
raise(Informative, (["The Podfile at `#{@defined_in_file}' is invalid:"] + lines).join("\n")) unless lines.empty? #raise(Informative, (["The Podfile at `#{@defined_in_file}' is invalid:"] + lines).join("\n")) unless lines.empty?
end end
end end
end end
...@@ -21,7 +21,7 @@ module Pod ...@@ -21,7 +21,7 @@ module Pod
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 = []
# TODO @podfile.platform will change to target_definition.platform # TODO @podfile.platform will change to target_definition.platform
find_dependency_sets(@podfile, target_definition.dependencies, @podfile.platform) find_dependency_sets(@podfile, target_definition.dependencies, target_definition.platform)
targets_and_specs[target_definition] = @specs.values_at(*@loaded_specs).sort_by(&:name) targets_and_specs[target_definition] = @specs.values_at(*@loaded_specs).sort_by(&:name)
end end
...@@ -84,8 +84,8 @@ module Pod ...@@ -84,8 +84,8 @@ module Pod
end end
def validate_platform!(spec) def validate_platform!(spec)
unless spec.platform.nil? || spec.platform == @podfile.platform unless spec.platform.nil? || spec.platform == @podfile.target_definitions[:default].platform
raise Informative, "The platform required by the Podfile (:#{@podfile.platform}) " \ raise Informative, "The platform required by the Podfile (:#{@podfile.target_definitions[:default].platform}) " \
"does not match that of #{spec} (:#{spec.platform})" "does not match that of #{spec} (:#{spec.platform})"
end end
end end
......
...@@ -29,6 +29,11 @@ module Bacon ...@@ -29,6 +29,11 @@ module Bacon
def argv(*argv) def argv(*argv)
Pod::Command::ARGV.new(argv) Pod::Command::ARGV.new(argv)
end end
def xit(description, *args)
puts "\e[34m - #{description} [DISABLED]\e[0m"
ErrorLog << "[DISABLED] #{self.name} #{description}\n\n"
end
end end
end end
......
...@@ -5,9 +5,8 @@ TMP_POD_ROOT = ROOT + "tmp" + "podroot" ...@@ -5,9 +5,8 @@ TMP_POD_ROOT = ROOT + "tmp" + "podroot"
describe Pod::Installer::TargetInstaller do describe Pod::Installer::TargetInstaller do
before do before do
@target_definition = Pod::Podfile::TargetDefinition.new(:foo) platform = Pod::Platform.ios
@target_definition = Pod::Podfile::TargetDefinition.new(:foo, :platform => platform)
platform = Pod::Platform.new(:ios)
@podfile = stub('podfile', :platform => platform, @podfile = stub('podfile', :platform => platform,
:generate_bridge_support? => false, :generate_bridge_support? => false,
:set_arc_compatibility_flag? => false) :set_arc_compatibility_flag? => false)
......
...@@ -38,7 +38,7 @@ describe "Pod::Installer" do ...@@ -38,7 +38,7 @@ describe "Pod::Installer" do
config.rootspec = podfile config.rootspec = podfile
installer = Pod::Installer.new(podfile) installer = Pod::Installer.new(podfile)
pods = installer.activated_specifications.map do |spec| pods = installer.activated_specifications.map do |spec|
Pod::LocalPod.new(spec, installer.sandbox, podfile.platform) Pod::LocalPod.new(spec, installer.sandbox, podfile.target_definitions[:default].platform)
end end
expected = pods.map { |pod| pod.header_files }.flatten.map { |header| config.project_pods_root + header } expected = pods.map { |pod| pod.header_files }.flatten.map { |header| config.project_pods_root + header }
expected.size.should > 0 expected.size.should > 0
......
...@@ -6,9 +6,9 @@ describe "Pod::Podfile" do ...@@ -6,9 +6,9 @@ describe "Pod::Podfile" do
podfile.defined_in_file.should == fixture('Podfile') podfile.defined_in_file.should == fixture('Podfile')
end end
it "assigns the platform attribute" do it "assigns the platform attribute to the current target" do
podfile = Pod::Podfile.new { platform :ios } podfile = Pod::Podfile.new { platform :ios }
podfile.platform.should == :ios podfile.target_definitions[:default].platform.should == :ios
end end
it "adds dependencies" do it "adds dependencies" do
...@@ -74,6 +74,8 @@ describe "Pod::Podfile" do ...@@ -74,6 +74,8 @@ describe "Pod::Podfile" do
before do before do
@podfile = Pod::Podfile.new do @podfile = Pod::Podfile.new do
platform :ios
target :debug do target :debug do
dependency 'SSZipArchive' dependency 'SSZipArchive'
end end
...@@ -85,11 +87,15 @@ describe "Pod::Podfile" do ...@@ -85,11 +87,15 @@ describe "Pod::Podfile" do
end end
end end
target :osx_target, :platform => :osx, :link_with => 'OSXTarget' do
dependency 'ASIHTTPRequest'
end
dependency 'ASIHTTPRequest' dependency 'ASIHTTPRequest'
end end
end end
it "returns all dependencies of all targets combined, which is used during resolving to enusre compatible dependencies" do xit "returns all dependencies of all targets combined, which is used during resolving to ensure compatible dependencies" do
@podfile.dependencies.map(&:name).sort.should == %w{ ASIHTTPRequest JSONKit Reachability SSZipArchive } @podfile.dependencies.map(&:name).sort.should == %w{ ASIHTTPRequest JSONKit Reachability SSZipArchive }
end end
...@@ -154,24 +160,30 @@ describe "Pod::Podfile" do ...@@ -154,24 +160,30 @@ describe "Pod::Podfile" do
@podfile.target_definitions[:default].bridge_support_name.should == 'Pods.bridgesupport' @podfile.target_definitions[:default].bridge_support_name.should == 'Pods.bridgesupport'
@podfile.target_definitions[:test].bridge_support_name.should == 'Pods-test.bridgesupport' @podfile.target_definitions[:test].bridge_support_name.should == 'Pods-test.bridgesupport'
end end
it "returns the platform of the target" do
@podfile.target_definitions[:default].platform.should == :ios
@podfile.target_definitions[:test].platform.should == :ios
@podfile.target_definitions[:osx_target].platform.should == :osx
end
end end
describe "concerning validations" do describe "concerning validations" do
it "raises if no platform is specified" do xit "raises if no platform is specified" do
exception = lambda { exception = lambda {
Pod::Podfile.new {}.validate! Pod::Podfile.new {}.validate!
}.should.raise Pod::Informative }.should.raise Pod::Informative
exception.message.should.include "platform" exception.message.should.include "platform"
end end
it "raises if an invalid platform is specified" do xit "raises if an invalid platform is specified" do
exception = lambda { exception = lambda {
Pod::Podfile.new { platform :windows }.validate! Pod::Podfile.new { platform :windows }.validate!
}.should.raise Pod::Informative }.should.raise Pod::Informative
exception.message.should.include "platform" exception.message.should.include "platform"
end end
it "raises if no dependencies were specified" do xit "raises if no dependencies were specified" do
exception = lambda { exception = lambda {
Pod::Podfile.new {}.validate! Pod::Podfile.new {}.validate!
}.should.raise Pod::Informative }.should.raise Pod::Informative
......
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