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

Move `platform` from Podfile to TargetDefinition.

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