Commit ac1a9551 authored by Samuel Giddins's avatar Samuel Giddins

[Sandbox] Allow storing specs directly

This also allows up to only create the `Local Podspecs` dir once
parent 0f6b1feb
......@@ -172,7 +172,7 @@ module Pod
end
spec.defined_in_file = nil
validate_podspec(spec)
sandbox.store_podspec(name, spec.to_pretty_json, true, true)
sandbox.store_podspec(name, spec, true, true)
end
def validate_podspec(podspec)
......
......@@ -242,7 +242,7 @@ module Pod
# @param [String] name
# the name of the pod
#
# @param [String, Pathname] podspec
# @param [String, Pathname, Specification] podspec
# The contents of the specification (String) or the path to a
# podspec file (Pathname).
#
......@@ -252,22 +252,29 @@ module Pod
def store_podspec(name, podspec, _external_source = false, json = false)
file_name = json ? "#{name}.podspec.json" : "#{name}.podspec"
output_path = specifications_root + file_name
output_path.dirname.mkpath
if podspec.is_a?(String)
case podspec
when String
output_path.open('w') { |f| f.puts(podspec) }
else
when Pathname
unless podspec.exist?
raise Informative, "No podspec found for `#{name}` in #{podspec}"
end
FileUtils.copy(podspec, output_path)
when Specification
output_path.open('w') { |f| f.puts(podspec.to_pretty_json) }
spec = podspec.dup
spec.defined_in_file = output_path
end
Dir.chdir(podspec.is_a?(Pathname) ? File.dirname(podspec) : Dir.pwd) do
spec ||= Dir.chdir(podspec.is_a?(Pathname) ? File.dirname(podspec) : Dir.pwd) do
spec = Specification.from_file(output_path)
unless spec.name == name
raise Informative, "The name of the given podspec `#{spec.name}` doesn't match the expected one `#{name}`"
end
spec
end
end
......
......@@ -9,6 +9,7 @@ module Pod
}
dep = Dependency.new('Reachability', params)
@subject = ExternalSources.from_dependency(dep, nil, true)
config.sandbox.specifications_root.mkpath
end
it 'creates a copy of the podspec' do
......
......@@ -7,6 +7,7 @@ module Pod
dependency = Dependency.new('Reachability', params)
podfile_path = fixture('integration/Podfile')
@subject = ExternalSources.from_dependency(dependency, podfile_path, true)
config.sandbox.specifications_root.mkpath
end
it 'creates a copy of the podspec' do
......
......@@ -11,6 +11,7 @@ module Pod
end
it 'creates a copy of the podspec' do
config.sandbox.specifications_root.mkpath
@subject.fetch(config.sandbox)
path = config.sandbox.specifications_root + 'Reachability.podspec.json'
path.should.exist?
......
......@@ -22,6 +22,7 @@ module Pod
options.integrate_targets = integrate_targets
end
sandbox.specifications_root.mkpath
@analyzer = Analyzer.new(sandbox, podfile, lockfile).tap do |analyzer|
analyzer.installation_options = installation_options
end
......
......@@ -38,6 +38,7 @@ module Pod
it 'cleans any trace of the Pod with the given name' do
pod_root = @sandbox.pod_dir('BananaLib')
pod_root.mkpath
@sandbox.specifications_root.mkpath
@sandbox.store_podspec('BananaLib', fixture('banana-lib/BananaLib.podspec'))
specification_path = @sandbox.specification_path('BananaLib')
@sandbox.clean_pod('BananaLib')
......@@ -93,8 +94,12 @@ module Pod
#-------------------------------------------------------------------------#
describe 'Specification store' do
before do
# This is normally done in #prepare
@sandbox.specifications_root.mkdir
end
it 'loads the stored specification with the given name' do
(@sandbox.specifications_root).mkdir
FileUtils.cp(fixture('banana-lib/BananaLib.podspec'), @sandbox.specifications_root)
@sandbox.specification('BananaLib').name.should == 'BananaLib'
end
......@@ -121,7 +126,6 @@ module Pod
end
it "returns the path to a spec file in the 'Local Podspecs' dir" do
(@sandbox.root + 'Local Podspecs').mkdir
FileUtils.cp(fixture('banana-lib/BananaLib.podspec'), @sandbox.root + 'Local Podspecs')
@sandbox.specification_path('BananaLib').should ==
@sandbox.root + 'Local Podspecs/BananaLib.podspec'
......
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