Commit c048d1cb authored by Fabio Pelosin's avatar Fabio Pelosin

[ExternalSources::LocalSource] Improve handling of paths.

- Added support for tilde expansion
- Added support for relative paths
- Always return absolute paths for the Podspec.
parent a24f3975
...@@ -9,7 +9,7 @@ module Pod ...@@ -9,7 +9,7 @@ module Pod
# external source class associated with the option specified in the # external source class associated with the option specified in the
# hash. # hash.
# #
def self.from_dependency(dependency) def self.from_dependency(dependency, podfile_path)
name = dependency.root_name name = dependency.root_name
params = dependency.external_source params = dependency.external_source
...@@ -21,7 +21,7 @@ module Pod ...@@ -21,7 +21,7 @@ module Pod
end end
if klass if klass
klass.new(name, params) klass.new(name, params, podfile_path)
else else
msg = "Unknown external source parameters for `#{name}`: `#{params}`" msg = "Unknown external source parameters for `#{name}`: `#{params}`"
raise Informative, msg raise Informative, msg
...@@ -43,11 +43,19 @@ module Pod ...@@ -43,11 +43,19 @@ module Pod
# #
attr_reader :params attr_reader :params
# @return [String] the path where the podfile is defined to resolve
# relative paths.
#
attr_reader :podfile_path
# @param [String] name @see name # @param [String] name @see name
# @param [Hash] params @see params # @param [Hash] params @see params
# @param [String] podfile_path @see podfile_path
# #
def initialize(name, params) def initialize(name, params, podfile_path)
@name, @params = name, params @name = name
@params = params
@podfile_path = podfile_path
end end
# @return [Bool] whether an external source source is equal to another # @return [Bool] whether an external source source is equal to another
...@@ -136,12 +144,12 @@ module Pod ...@@ -136,12 +144,12 @@ module Pod
UI.info("->".green + " Pre-downloading: `#{name}`") do UI.info("->".green + " Pre-downloading: `#{name}`") do
target = sandbox.root + name target = sandbox.root + name
target.rmtree if target.exist? target.rmtree if target.exist?
downloader = Downloader.for_target(target, @params) downloader = Downloader.for_target(target, params)
downloader.download downloader.download
sandbox.store_podspec(name, target + "#{name}.podspec", true) sandbox.store_podspec(name, target + "#{name}.podspec", true)
sandbox.store_pre_downloaded_pod(name) sandbox.store_pre_downloaded_pod(name)
if downloader.options_specific? if downloader.options_specific?
source = @params source = params
else else
source = downloader.checkout_options source = downloader.checkout_options
end end
...@@ -176,10 +184,10 @@ module Pod ...@@ -176,10 +184,10 @@ module Pod
# @see AbstractExternalSource#description # @see AbstractExternalSource#description
# #
def description def description
"from `#{@params[:git]}`".tap do |description| "from `#{params[:git]}`".tap do |description|
description << ", commit `#{@params[:commit]}`" if @params[:commit] description << ", commit `#{params[:commit]}`" if params[:commit]
description << ", branch `#{@params[:branch]}`" if @params[:branch] description << ", branch `#{params[:branch]}`" if params[:branch]
description << ", tag `#{@params[:tag]}`" if @params[:tag] description << ", tag `#{params[:tag]}`" if params[:tag]
end end
end end
end end
...@@ -210,10 +218,10 @@ module Pod ...@@ -210,10 +218,10 @@ module Pod
# @see AbstractExternalSource#description # @see AbstractExternalSource#description
# #
def description def description
"from `#{@params[:svn]}`".tap do |description| "from `#{params[:svn]}`".tap do |description|
description << ", folder `#{@params[:folder]}`" if @params[:folder] description << ", folder `#{params[:folder]}`" if params[:folder]
description << ", tag `#{@params[:tag]}`" if @params[:tag] description << ", tag `#{params[:tag]}`" if params[:tag]
description << ", revision `#{@params[:revision]}`" if @params[:revision] description << ", revision `#{params[:revision]}`" if params[:revision]
end end
end end
end end
...@@ -244,8 +252,8 @@ module Pod ...@@ -244,8 +252,8 @@ module Pod
# @see AbstractExternalSource#description # @see AbstractExternalSource#description
# #
def description def description
"from `#{@params[:hg]}`".tap do |description| "from `#{params[:hg]}`".tap do |description|
description << ", revision `#{@params[:revision]}`" if @params[:revision] description << ", revision `#{params[:revision]}`" if params[:revision]
end end
end end
end end
...@@ -260,8 +268,8 @@ module Pod ...@@ -260,8 +268,8 @@ module Pod
# @see AbstractExternalSource#copy_external_source_into_sandbox # @see AbstractExternalSource#copy_external_source_into_sandbox
# #
def copy_external_source_into_sandbox(sandbox) def copy_external_source_into_sandbox(sandbox)
UI.info("->".green + " Fetching podspec for `#{name}` from: #{@params[:podspec]}") do UI.info("->".green + " Fetching podspec for `#{name}` from: #{params[:podspec]}") do
path = @params[:podspec] path = params[:podspec]
path = Pathname.new(path).expand_path if path.to_s.start_with?("~") path = Pathname.new(path).expand_path if path.to_s.start_with?("~")
require 'open-uri' require 'open-uri'
open(path) { |io| sandbox.store_podspec(name, io.read, true) } open(path) { |io| sandbox.store_podspec(name, io.read, true) }
...@@ -271,7 +279,7 @@ module Pod ...@@ -271,7 +279,7 @@ module Pod
# @see AbstractExternalSource#description # @see AbstractExternalSource#description
# #
def description def description
"from `#{@params[:podspec]}`" "from `#{params[:podspec]}`"
end end
end end
...@@ -288,13 +296,13 @@ module Pod ...@@ -288,13 +296,13 @@ module Pod
# #
def copy_external_source_into_sandbox(sandbox) def copy_external_source_into_sandbox(sandbox)
sandbox.store_podspec(name, pod_spec_path, true) sandbox.store_podspec(name, pod_spec_path, true)
sandbox.store_local_path(name, @params[:local]) sandbox.store_local_path(name, params[:local])
end end
# @see AbstractExternalSource#description # @see AbstractExternalSource#description
# #
def description def description
"from `#{@params[:local]}`" "from `#{params[:local]}`"
end end
# @see AbstractExternalSource#specification_from_local # @see AbstractExternalSource#specification_from_local
...@@ -316,7 +324,7 @@ module Pod ...@@ -316,7 +324,7 @@ module Pod
def specification_from_external(sandbox) def specification_from_external(sandbox)
copy_external_source_into_sandbox(sandbox) copy_external_source_into_sandbox(sandbox)
spec = Specification.from_file(pod_spec_path) spec = Specification.from_file(pod_spec_path)
spec.source = @params spec.source = params
spec spec
end end
...@@ -329,12 +337,15 @@ module Pod ...@@ -329,12 +337,15 @@ module Pod
# @return [Pathname] the path of the podspec. # @return [Pathname] the path of the podspec.
# #
def pod_spec_path def pod_spec_path
path = Pathname.new(@params[:local]).expand_path declared_path = params[:local].to_s
path += "#{name}.podspec" unless path.to_s.match(/#{name}\.podspec$/) path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec"
unless path.exist? path_without_tilde = path_with_ext.gsub('~', ENV['HOME'])
raise Informative, "No podspec found for `#{name}` in `#{@params[:local]}`" absolute_path = Pathname(podfile_path).dirname + path_without_tilde
unless absolute_path.exist?
raise Informative, "No podspec found for `#{name}` in `#{params[:local]}`"
end end
path absolute_path
end end
end end
end end
......
...@@ -221,7 +221,7 @@ module Pod ...@@ -221,7 +221,7 @@ module Pod
# @return [Set] the set for the dependency. # @return [Set] the set for the dependency.
# #
def set_from_external_source(dependency) def set_from_external_source(dependency)
source = ExternalSources.from_dependency(dependency) source = ExternalSources.from_dependency(dependency, podfile.defined_in_file)
if allow_pre_downloads? if allow_pre_downloads?
if update_external_specs? if update_external_specs?
spec = source.specification_from_external(sandbox) spec = source.specification_from_external(sandbox)
...@@ -236,7 +236,7 @@ module Pod ...@@ -236,7 +236,7 @@ module Pod
end end
end end
set = Specification::Set::External.new(spec) Specification::Set::External.new(spec)
end end
# Ensures that a specification is compatible with the platform of a target. # Ensures that a specification is compatible with the platform of a target.
......
...@@ -9,10 +9,10 @@ module Pod ...@@ -9,10 +9,10 @@ module Pod
podspec = Dependency.new("Reachability", :podspec => nil) podspec = Dependency.new("Reachability", :podspec => nil)
local = Dependency.new("Reachability", :local => nil) local = Dependency.new("Reachability", :local => nil)
ExternalSources.from_dependency(git).class.should == ExternalSources::GitSource ExternalSources.from_dependency(git, nil).class.should == ExternalSources::GitSource
ExternalSources.from_dependency(svn).class.should == ExternalSources::SvnSource ExternalSources.from_dependency(svn, nil).class.should == ExternalSources::SvnSource
ExternalSources.from_dependency(podspec).class.should == ExternalSources::PodspecSource ExternalSources.from_dependency(podspec, nil).class.should == ExternalSources::PodspecSource
ExternalSources.from_dependency(local).class.should == ExternalSources::LocalSource ExternalSources.from_dependency(local, nil).class.should == ExternalSources::LocalSource
end end
end end
...@@ -22,7 +22,7 @@ module Pod ...@@ -22,7 +22,7 @@ module Pod
before do before do
dependency = Dependency.new("Reachability", :git => fixture('integration/Reachability')) dependency = Dependency.new("Reachability", :git => fixture('integration/Reachability'))
@external_source = ExternalSources.from_dependency(dependency) @external_source = ExternalSources.from_dependency(dependency, nil)
end end
#--------------------------------------# #--------------------------------------#
...@@ -100,7 +100,7 @@ module Pod ...@@ -100,7 +100,7 @@ module Pod
before do before do
dependency = Dependency.new("Reachability", :git => fixture('integration/Reachability')) dependency = Dependency.new("Reachability", :git => fixture('integration/Reachability'))
@external_source = ExternalSources.from_dependency(dependency) @external_source = ExternalSources.from_dependency(dependency, nil)
end end
it "creates a copy of the podspec" do it "creates a copy of the podspec" do
...@@ -125,7 +125,7 @@ module Pod ...@@ -125,7 +125,7 @@ module Pod
before do before do
dependency = Dependency.new("SvnSource", :svn => "file://#{fixture('subversion-repo/trunk')}") dependency = Dependency.new("SvnSource", :svn => "file://#{fixture('subversion-repo/trunk')}")
@external_source = ExternalSources.from_dependency(dependency) @external_source = ExternalSources.from_dependency(dependency, nil)
end end
it "creates a copy of the podspec" do it "creates a copy of the podspec" do
...@@ -150,7 +150,7 @@ module Pod ...@@ -150,7 +150,7 @@ module Pod
before do before do
dependency = Dependency.new("MercurialSource", :hg => fixture('mercurial-repo')) dependency = Dependency.new("MercurialSource", :hg => fixture('mercurial-repo'))
@external_source = ExternalSources.from_dependency(dependency) @external_source = ExternalSources.from_dependency(dependency, nil)
end end
it "creates a copy of the podspec" do it "creates a copy of the podspec" do
...@@ -176,7 +176,7 @@ module Pod ...@@ -176,7 +176,7 @@ 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) @external_source = ExternalSources.from_dependency(dependency, nil)
end end
it "creates a copy of the podspec" do it "creates a copy of the podspec" do
...@@ -197,7 +197,8 @@ module Pod ...@@ -197,7 +197,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", :local => fixture('integration/Reachability')) dependency = Dependency.new("Reachability", :local => fixture('integration/Reachability'))
@external_source = ExternalSources.from_dependency(dependency) 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
...@@ -217,6 +218,35 @@ module Pod ...@@ -217,6 +218,35 @@ module Pod
} }
end end
describe "Helpers" do
it "handles absolute paths" do
@external_source.stubs(:params).returns(:local => fixture('integration/Reachability'))
path = @external_source.send(:pod_spec_path)
path.should == fixture('integration/Reachability/Reachability.podspec')
end
it "handles relative paths" do
@external_source.stubs(:params).returns(:local => 'Reachability')
path = @external_source.send(:pod_spec_path)
path.should == fixture('integration/Reachability/Reachability.podspec')
end
it "expands the tilde" do
@external_source.stubs(:params).returns(:local => '~/Reachability')
Pathname.any_instance.stubs(:exist?).returns(true)
path = @external_source.send(:pod_spec_path)
path.should == Pathname(ENV['HOME']) + 'Reachability/Reachability.podspec'
end
it "raises if the podspec cannot be found" do
@external_source.stubs(:params).returns(:local => temporary_directory)
e = lambda { @external_source.send(:pod_spec_path) }.should.raise Informative
e.message.should.match /No podspec found/
end
end
end end
#---------------------------------------------------------------------------# #---------------------------------------------------------------------------#
......
...@@ -232,7 +232,8 @@ module Pod ...@@ -232,7 +232,8 @@ module Pod
describe "#set_from_external_source" do describe "#set_from_external_source" do
before do before do
@resolver = Resolver.new(config.sandbox, nil) podfile = Podfile.new("#{temporary_directory}/Podfile") { }
@resolver = Resolver.new(config.sandbox, podfile)
end end
it "it fetches the specification from either the sandbox or from the remote be default" do it "it fetches the specification from either the sandbox or from the remote be default" do
......
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