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
@pod, @url, @options = pod, url, options
end
def clean(clean_paths = [])
return unless clean_paths
clean_paths.each do |path|
path.rmtree
end
def clean
# implement in sub-classes
end
end
end
......@@ -35,8 +35,7 @@ module Pod
end
end
def clean(clean_paths = [])
super
def clean
(pod.root + '.git').rmtree
end
end
......
......@@ -19,8 +19,7 @@ module Pod
hg "clone '#{url}' --rev '#{options[:revision]}' '#{pod.root}'"
end
def clean(clean_paths = [])
super
def clean
(pod.root + '.hg').rmtree
end
end
......
......@@ -19,8 +19,7 @@ module Pod
svn "checkout '#{url}' -r '#{options[:revision]}' '#{pod.root}'"
end
def clean(clean_paths = [])
super
def clean
pod.root.glob('**/.svn').each(&:rmtree)
end
end
......
......@@ -68,8 +68,11 @@ module Pod
pod = Pod.new(sandbox, spec)
downloader = Downloader.for_pod(pod)
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
......
......@@ -22,5 +22,41 @@ module Pod
def implode
root.rmtree if root.exist?
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
......@@ -245,18 +245,6 @@ module Pod
files
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,
# but relative to the project pods root.
#
......
......@@ -44,10 +44,15 @@ end
require 'tmpdir'
def temporary_sandbox
Pod::Sandbox.new(Pathname.new(Dir.mktmpdir))
Pod::Sandbox.new(Pathname.new(Dir.mktmpdir + "/Pods"))
end
def fixture_spec(name)
file = SpecHelper::Fixture.fixture(name)
Pod::Specification.from_file(file)
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
# a LocalPod represents a local copy of the dependency, inside the pod root, built from a spec
before do
@spec = Pod::Specification.from_file(fixture('banana-lib/BananaLib.podspec'))
@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
it 'returns the Pod root directory path' do
......@@ -29,4 +29,30 @@ describe Pod::LocalPod do
@pod.implode
@pod.root.should.not.exist
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
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