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