Commit dca4cb2d authored by Luke Redpath's avatar Luke Redpath

Move pattern expansion for sources, clean paths and resources in to LocalPod.

Have downloaders responsible only for cleaning up their own paths, move clean up of other paths
into LocalPod itself.
parent 4359e82c
...@@ -25,12 +25,8 @@ module Pod ...@@ -25,12 +25,8 @@ module Pod
@pod, @url, @options = pod, url, options @pod, @url, @options = pod, url, options
end end
def clean(clean_paths = []) def clean
return unless clean_paths # implement in sub-classes
clean_paths.each do |path|
path.rmtree
end
end end
end end
end end
...@@ -35,8 +35,7 @@ module Pod ...@@ -35,8 +35,7 @@ module Pod
end end
end end
def clean(clean_paths = []) def clean
super
(pod.root + '.git').rmtree (pod.root + '.git').rmtree
end end
end end
......
...@@ -19,8 +19,7 @@ module Pod ...@@ -19,8 +19,7 @@ module Pod
hg "clone '#{url}' --rev '#{options[:revision]}' '#{pod.root}'" hg "clone '#{url}' --rev '#{options[:revision]}' '#{pod.root}'"
end end
def clean(clean_paths = []) def clean
super
(pod.root + '.hg').rmtree (pod.root + '.hg').rmtree
end end
end end
......
...@@ -19,8 +19,7 @@ module Pod ...@@ -19,8 +19,7 @@ module Pod
svn "checkout '#{url}' -r '#{options[:revision]}' '#{pod.root}'" svn "checkout '#{url}' -r '#{options[:revision]}' '#{pod.root}'"
end end
def clean(clean_paths = []) def clean
super
pod.root.glob('**/.svn').each(&:rmtree) pod.root.glob('**/.svn').each(&:rmtree)
end end
end end
......
...@@ -68,8 +68,11 @@ module Pod ...@@ -68,8 +68,11 @@ module Pod
pod = Pod.new(sandbox, spec) pod = Pod.new(sandbox, spec)
downloader = Downloader.for_pod(pod) downloader = Downloader.for_pod(pod)
downloader.download downloader.download
# TODO move cleaning into the installer as well
downloader.clean(spec.expanded_clean_paths) if config.clean if config.clean
downloader.clean
pod.clean
end
end end
end end
end end
......
...@@ -22,5 +22,41 @@ module Pod ...@@ -22,5 +22,41 @@ module Pod
def implode def implode
root.rmtree if root.exist? root.rmtree if root.exist?
end end
def clean
clean_paths.each { |path| FileUtils.rm_rf(path) }
end
def source_files
expanded_paths(specification.source_files, :glob => '*.{h,m,mm,c,cpp}', :relative_to_sandbox => true)
end
def clean_paths
expanded_paths(specification.clean_paths)
end
def resources
expanded_paths(specification.resources, :relative_to_sandbox => true)
end
private
def expanded_paths(patterns, options={})
patterns.map do |pattern|
pattern = root + pattern
if pattern.directory? && options[:glob]
pattern += options[:glob]
end
pattern.glob.map do |file|
if options[:relative_to_sandbox]
file.relative_path_from(@sandbox.root)
else
file
end
end
end.flatten
end
end end
end end
...@@ -245,18 +245,6 @@ module Pod ...@@ -245,18 +245,6 @@ module Pod
files files
end end
# Returns full paths to clean for this pod.
def expanded_clean_paths
files = []
clean_paths.each do |pattern|
pattern = pod_destroot + pattern
pattern.glob.each do |file|
files << file
end
end
files
end
# Returns all source files of this pod including header files, # Returns all source files of this pod including header files,
# but relative to the project pods root. # but relative to the project pods root.
# #
......
...@@ -44,10 +44,15 @@ end ...@@ -44,10 +44,15 @@ end
require 'tmpdir' require 'tmpdir'
def temporary_sandbox def temporary_sandbox
Pod::Sandbox.new(Pathname.new(Dir.mktmpdir)) Pod::Sandbox.new(Pathname.new(Dir.mktmpdir + "/Pods"))
end end
def fixture_spec(name) def fixture_spec(name)
file = SpecHelper::Fixture.fixture(name) file = SpecHelper::Fixture.fixture(name)
Pod::Specification.from_file(file) Pod::Specification.from_file(file)
end end
def copy_fixture_to_pod(name, pod)
path = SpecHelper::Fixture.fixture(name)
FileUtils.cp_r(path, pod.root)
end
\ No newline at end of file
...@@ -5,9 +5,9 @@ describe Pod::LocalPod do ...@@ -5,9 +5,9 @@ describe Pod::LocalPod do
# a LocalPod represents a local copy of the dependency, inside the pod root, built from a spec # a LocalPod represents a local copy of the dependency, inside the pod root, built from a spec
before do before do
@spec = Pod::Specification.from_file(fixture('banana-lib/BananaLib.podspec'))
@sandbox = temporary_sandbox @sandbox = temporary_sandbox
@pod = Pod::LocalPod.new(@spec, @sandbox) @pod = Pod::LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), @sandbox)
copy_fixture_to_pod('banana-lib', @pod)
end end
it 'returns the Pod root directory path' do it 'returns the Pod root directory path' do
...@@ -29,4 +29,30 @@ describe Pod::LocalPod do ...@@ -29,4 +29,30 @@ describe Pod::LocalPod do
@pod.implode @pod.implode
@pod.root.should.not.exist @pod.root.should.not.exist
end end
it 'returns an expanded list of source files, relative to the sandbox root' do
@pod.source_files.sort.should == [
Pathname.new("BananaLib/Classes/Banana.m"),
Pathname.new("BananaLib/Classes/Banana.h")
].sort
end
it 'returns an expanded list of absolute clean paths' do
@pod.clean_paths.should == [@sandbox.root + "BananaLib/sub-dir"]
end
it 'returns an expanded list of resources, relative to the sandbox root' do
@pod.resources.should == [Pathname.new("BananaLib/Resources/logo-sidebar.png")]
end
it 'can clean up after itself' do
@pod.clean_paths.tap do |paths|
@pod.clean
paths.each do |path|
path.should.not.exist
end
end
end
end end
...@@ -22,5 +22,5 @@ describe Pod::Sandbox do ...@@ -22,5 +22,5 @@ describe Pod::Sandbox do
File.directory?(TMP_POD_ROOT).should.be.false File.directory?(TMP_POD_ROOT).should.be.false
FileUtils.mkdir(TMP_POD_ROOT) # put it back again FileUtils.mkdir(TMP_POD_ROOT) # put it back again
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