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