Commit e9862578 authored by Fabio Pelosin's avatar Fabio Pelosin

[ExternalSources] Support the specification of a folder for the :podspec option

parent 5c634e99
...@@ -268,10 +268,9 @@ module Pod ...@@ -268,10 +268,9 @@ module Pod
# #
def fetch(sandbox) def fetch(sandbox)
UI.titled_section("Fetching podspec for `#{name}` #{description}", { :verbose_prefix => "-> " }) do UI.titled_section("Fetching podspec for `#{name}` #{description}", { :verbose_prefix => "-> " }) do
path = params[:podspec]
path = Pathname.new(path).expand_path if path.to_s.start_with?("~")
require 'open-uri' require 'open-uri'
open(path) { |io| store_podspec(sandbox, io.read) } open(podspec_uri) { |io| store_podspec(sandbox, io.read) }
end end
end end
...@@ -280,6 +279,30 @@ module Pod ...@@ -280,6 +279,30 @@ module Pod
def description def description
"from `#{params[:podspec]}`" "from `#{params[:podspec]}`"
end end
#--------------------------------------#
private
# @!group Helpers
# @return [String] The uri of the podspec appending the name of the file
# and expanding it if necessary.
#
# @note If the declared path is expanded only if the represents a path
# relative to the file system.
#
def podspec_uri
declared_path = params[:podspec].to_s
if declared_path.match(%r{^.+://})
declared_path
else
path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec"
podfile_dir = File.dirname(podfile_path || '')
absolute_path = File.expand_path(path_with_ext, podfile_dir)
absolute_path
end
end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -295,7 +318,7 @@ module Pod ...@@ -295,7 +318,7 @@ module Pod
# #
def fetch(sandbox) def fetch(sandbox)
UI.titled_section("Fetching podspec for `#{name}` #{description}", { :verbose_prefix => "-> " }) do UI.titled_section("Fetching podspec for `#{name}` #{description}", { :verbose_prefix => "-> " }) do
podspec = pod_spec_path podspec = podspec_path
store_podspec(sandbox, podspec) store_podspec(sandbox, podspec)
sandbox.store_local_path(name, podspec.dirname) sandbox.store_local_path(name, podspec.dirname)
end end
...@@ -315,7 +338,7 @@ module Pod ...@@ -315,7 +338,7 @@ module Pod
# @return [Pathname] the path of the podspec. # @return [Pathname] the path of the podspec.
# #
def pod_spec_path def podspec_path
declared_path = params[:local].to_s declared_path = params[:local].to_s
path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec" path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec"
podfile_dir = File.dirname(podfile_path || '') podfile_dir = File.dirname(podfile_path || '')
...@@ -328,5 +351,8 @@ module Pod ...@@ -328,5 +351,8 @@ module Pod
pathname pathname
end end
end end
#-------------------------------------------------------------------------#
end end
end end
...@@ -151,7 +151,8 @@ module Pod ...@@ -151,7 +151,8 @@ module Pod
before do before do
podspec_path = fixture('integration/Reachability/Reachability.podspec') podspec_path = fixture('integration/Reachability/Reachability.podspec')
dependency = Dependency.new("Reachability", :podspec => podspec_path.to_s) dependency = Dependency.new("Reachability", :podspec => podspec_path.to_s)
@external_source = ExternalSources.from_dependency(dependency, nil) podfile_path = fixture('integration/Podfile')
@external_source = ExternalSources.from_dependency(dependency, podfile_path)
end end
it "creates a copy of the podspec" do it "creates a copy of the podspec" do
...@@ -163,6 +164,40 @@ module Pod ...@@ -163,6 +164,40 @@ module Pod
it "returns the description" do it "returns the description" do
@external_source.description.should.match %r|from `.*Reachability/Reachability.podspec`| @external_source.description.should.match %r|from `.*Reachability/Reachability.podspec`|
end end
describe "Helpers" do
it "handles absolute paths" do
@external_source.stubs(:params).returns(:podspec => fixture('integration/Reachability'))
path = @external_source.send(:podspec_uri)
path.should == fixture('integration/Reachability/Reachability.podspec').to_s
end
it "handles paths when there is no podfile path" do
@external_source.stubs(:podfile_path).returns(nil)
@external_source.stubs(:params).returns(:podspec => fixture('integration/Reachability'))
path = @external_source.send(:podspec_uri)
path.should == fixture('integration/Reachability/Reachability.podspec').to_s
end
it "handles relative paths" do
@external_source.stubs(:params).returns(:podspec => 'Reachability')
path = @external_source.send(:podspec_uri)
path.should == fixture('integration/Reachability/Reachability.podspec').to_s
end
it "expands the tilde" do
@external_source.stubs(:params).returns(:podspec => '~/Reachability')
path = @external_source.send(:podspec_uri)
path.should == ENV['HOME'] + '/Reachability/Reachability.podspec'
end
it "handles urls" do
@external_source.stubs(:params).returns(:podspec => "http://www.example.com/Reachability.podspec")
path = @external_source.send(:podspec_uri)
path.should == "http://www.example.com/Reachability.podspec"
end
end
end end
#---------------------------------------------------------------------------# #---------------------------------------------------------------------------#
...@@ -197,38 +232,36 @@ module Pod ...@@ -197,38 +232,36 @@ module Pod
it "handles absolute paths" do it "handles absolute paths" do
@external_source.stubs(:params).returns(:local => fixture('integration/Reachability')) @external_source.stubs(:params).returns(:local => fixture('integration/Reachability'))
path = @external_source.send(:pod_spec_path) path = @external_source.send(:podspec_path)
path.should == fixture('integration/Reachability/Reachability.podspec') path.should == fixture('integration/Reachability/Reachability.podspec')
end end
it "handles paths when there is no podfile path" do it "handles paths when there is no podfile path" do
@external_source.stubs(:podfile_path).returns(nil) @external_source.stubs(:podfile_path).returns(nil)
@external_source.stubs(:params).returns(:local => fixture('integration/Reachability')) @external_source.stubs(:params).returns(:local => fixture('integration/Reachability'))
path = @external_source.send(:pod_spec_path) path = @external_source.send(:podspec_path)
path.should == fixture('integration/Reachability/Reachability.podspec') path.should == fixture('integration/Reachability/Reachability.podspec')
end end
it "handles relative paths" do it "handles relative paths" do
@external_source.stubs(:params).returns(:local => 'Reachability') @external_source.stubs(:params).returns(:local => 'Reachability')
path = @external_source.send(:pod_spec_path) path = @external_source.send(:podspec_path)
path.should == fixture('integration/Reachability/Reachability.podspec') path.should == fixture('integration/Reachability/Reachability.podspec')
end end
it "expands the tilde" do it "expands the tilde" do
@external_source.stubs(:params).returns(:local => '~/Reachability') @external_source.stubs(:params).returns(:local => '~/Reachability')
Pathname.any_instance.stubs(:exist?).returns(true) Pathname.any_instance.stubs(:exist?).returns(true)
path = @external_source.send(:pod_spec_path) path = @external_source.send(:podspec_path)
path.should == Pathname(ENV['HOME']) + 'Reachability/Reachability.podspec' path.should == Pathname(ENV['HOME']) + 'Reachability/Reachability.podspec'
end end
it "raises if the podspec cannot be found" do it "raises if the podspec cannot be found" do
@external_source.stubs(:params).returns(:local => temporary_directory) @external_source.stubs(:params).returns(:local => temporary_directory)
e = lambda { @external_source.send(:pod_spec_path) }.should.raise Informative e = lambda { @external_source.send(:podspec_path) }.should.raise Informative
e.message.should.match /No podspec found/ e.message.should.match /No podspec found/
end end
end end
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