Commit a9ccd659 authored by Eloy Duran's avatar Eloy Duran

Add Podfile#target which scopes dependencies to static libraries.

parent 5f1bb7de
module Pod module Pod
class Podfile class Podfile
class Target
attr_reader :name, :parent, :target_dependencies
def initialize(name, parent = nil)
@name, @parent, @target_dependencies = name, parent, []
end
def lib_name
name == :default ? "libPods" : "libPods-#{name}"
end
# Returns *all* dependencies of this target, not only the target specific
# ones in `target_dependencies`.
def dependencies
@target_dependencies + (@parent ? @parent.dependencies : [])
end
end
def self.from_file(path) def self.from_file(path)
podfile = Podfile.new do podfile = Podfile.new do
eval(path.read, nil, path.to_s) eval(path.read, nil, path.to_s)
...@@ -10,7 +28,7 @@ module Pod ...@@ -10,7 +28,7 @@ module Pod
end end
def initialize(&block) def initialize(&block)
@dependencies = [] @targets = { :default => (@target = Target.new(:default)) }
instance_eval(&block) instance_eval(&block)
end end
...@@ -58,10 +76,12 @@ module Pod ...@@ -58,10 +76,12 @@ module Pod
# * http://semver.org # * http://semver.org
# * http://docs.rubygems.org/read/chapter/7 # * http://docs.rubygems.org/read/chapter/7
def dependency(name, *version_requirements) def dependency(name, *version_requirements)
@dependencies << Dependency.new(name, *version_requirements) @target.target_dependencies << Dependency.new(name, *version_requirements)
end end
attr_reader :dependencies def dependencies
@targets.values.map(&:target_dependencies).flatten
end
# Specifies that a BridgeSupport metadata should be generated from the # Specifies that a BridgeSupport metadata should be generated from the
# headers of all installed Pods. # headers of all installed Pods.
...@@ -72,6 +92,15 @@ module Pod ...@@ -72,6 +92,15 @@ module Pod
@generate_bridge_support = true @generate_bridge_support = true
end end
attr_reader :targets
def target(name, options = {})
@targets[name] = @target = Target.new(name, @target)
yield
ensure
@target = @target.parent
end
# This is to be compatible with a Specification for use in the Installer and # This is to be compatible with a Specification for use in the Installer and
# Resolver. # Resolver.
...@@ -86,13 +115,13 @@ module Pod ...@@ -86,13 +115,13 @@ module Pod
end end
def dependency_by_name(name) def dependency_by_name(name)
@dependencies.find { |d| d.name == name } dependencies.find { |d| d.name == name }
end end
def validate! def validate!
lines = [] lines = []
lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless [:osx, :ios].include?(@platform) lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless [:osx, :ios].include?(@platform)
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
......
...@@ -23,6 +23,41 @@ describe "Pod::Podfile" do ...@@ -23,6 +23,41 @@ describe "Pod::Podfile" do
podfile.generate_bridge_support?.should == true podfile.generate_bridge_support?.should == true
end end
describe "concerning targets (dependency groups)" do
before do
@podfile = Pod::Podfile.new do
target :debug do
dependency 'SSZipArchive'
end
target :test, :exclusive => true do
dependency 'JSONKit'
end
dependency 'ASIHTTPRequest'
end
end
it "returns all dependencies of all targets combined, which is used during resolving to enusre compatible dependencies" do
@podfile.dependencies.map(&:name).sort.should == %w{ ASIHTTPRequest JSONKit SSZipArchive }
end
it "adds dependencies outside of any explicit target block to the default target" do
target = @podfile.targets[:default]
target.lib_name.should == 'libPods'
target.dependencies.should == [Pod::Dependency.new('ASIHTTPRequest')]
end
it "adds dependencies of the outer target to non-exclusive targets" do
target = @podfile.targets[:debug]
target.lib_name.should == 'libPods-debug'
target.dependencies.sort_by(&:name).should == [
Pod::Dependency.new('ASIHTTPRequest'),
Pod::Dependency.new('SSZipArchive')
]
end
end
describe "concerning validations" do describe "concerning validations" do
it "raises if no platform is specified" do it "raises if no platform is specified" do
exception = lambda { exception = lambda {
......
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