Commit ece1c9fd authored by Eloy Duran's avatar Eloy Duran

The `source_files`, `resources`, and `clean_paths` attributes can take…

The `source_files`, `resources`, and `clean_paths` attributes can take Rake::FileList instances too.
parent dcdc3af2
...@@ -3,7 +3,7 @@ platform :ios ...@@ -3,7 +3,7 @@ platform :ios
dependency 'AFNetworking' dependency 'AFNetworking'
# From a spec repo # From a spec repo
#dependency 'SSToolkit' dependency 'SSToolkit'
# Directly from the Pod’s repo # Directly from the Pod’s repo
#dependency 'SSToolkit', :git => 'https://github.com/samsoffes/sstoolkit.git' #dependency 'SSToolkit', :git => 'https://github.com/samsoffes/sstoolkit.git'
...@@ -16,19 +16,19 @@ dependency 'AFNetworking' ...@@ -16,19 +16,19 @@ dependency 'AFNetworking'
#dependency 'SSToolkit', :podspec => 'https://raw.github.com/gist/1353347/ef1800da9c5f5d267a642b8d3950b41174f2a6d7/SSToolkit-0.1.1.podspec' #dependency 'SSToolkit', :podspec => 'https://raw.github.com/gist/1353347/ef1800da9c5f5d267a642b8d3950b41174f2a6d7/SSToolkit-0.1.1.podspec'
# If no podspec is available anywhere, you can define one right in your Podfile # If no podspec is available anywhere, you can define one right in your Podfile
dependency do |s| #dependency do |s|
s.name = 'SSToolkit' #s.name = 'SSToolkit'
s.version = '0.1.3' #s.version = '0.1.3'
s.platform = :ios #s.platform = :ios
s.source = { :git => 'https://github.com/samsoffes/sstoolkit.git', :commit => '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b' } #s.source = { :git => 'https://github.com/samsoffes/sstoolkit.git', :commit => '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b' }
s.resources = 'Resources' #s.resources = 'Resources/SSToolkit.bundle'
s.source_files = 'SSToolkit/**/*.{h,m}' #s.source_files = 'SSToolkit/**/*.{h,m}'
s.frameworks = 'QuartzCore', 'CoreGraphics' #s.frameworks = 'QuartzCore', 'CoreGraphics'
def s.post_install(target) #def s.post_install(target)
prefix_header = config.project_pods_root + target.prefix_header_filename #prefix_header = config.project_pods_root + target.prefix_header_filename
prefix_header.open('a') do |file| #prefix_header.open('a') do |file|
file.puts(%{#ifdef __OBJC__\n#import "SSToolkitDefines.h"\n#endif}) #file.puts(%{#ifdef __OBJC__\n#import "SSToolkitDefines.h"\n#endif})
end #end
end #end
end #end
...@@ -2,8 +2,8 @@ PODS: ...@@ -2,8 +2,8 @@ PODS:
- AFNetworking (0.7.0): - AFNetworking (0.7.0):
- JSONKit - JSONKit
- JSONKit (1.4) - JSONKit (1.4)
- SSToolkit (0.1.3) - SSToolkit (0.1.2)
DEPENDENCIES: DEPENDENCIES:
- AFNetworking - AFNetworking
- SSToolkit (defined in Podfile) - SSToolkit
Subproject commit e2ab8c76e891241612535acd114eb82d6be5815e Subproject commit ca3fe8f63cdaddbdf6a465e6352c7ca6501ee164
...@@ -54,11 +54,8 @@ module Pod ...@@ -54,11 +54,8 @@ module Pod
def clean(clean_paths = []) def clean(clean_paths = [])
(@pod_root + '.git').rmtree (@pod_root + '.git').rmtree
clean_paths.each do |pattern| clean_paths.each do |path|
pattern = @pod_root + pattern path.rmtree
pattern.glob.each do |path|
path.rmtree
end
end if clean_paths end if clean_paths
end end
end end
......
require 'rake'
module Rake
class FileList
def prepend_patterns(pathname)
@pending_add.map! { |pattern| (pathname + pattern).to_s }
end
# This makes Rake::FileList usable with source_files and clean_paths.
def directory?
false
end
def glob
to_a.map { |path| Pathname.new(path) }
end
end
end
class Pathname
alias_method :_original_sum, :+
def +(other)
if other.is_a?(Rake::FileList)
other.prepend_patterns(self)
other
else
_original_sum(other)
end
end
end
module Pod module Pod
extend Config::Mixin extend Config::Mixin
...@@ -21,7 +52,7 @@ module Pod ...@@ -21,7 +52,7 @@ module Pod
attr_accessor :defined_in_file attr_accessor :defined_in_file
def initialize def initialize
@dependencies = [] @dependencies, @resources, @clean_paths = [], [], []
@xcconfig = Xcodeproj::Config.new @xcconfig = Xcodeproj::Config.new
yield self if block_given? yield self if block_given?
end end
...@@ -67,21 +98,34 @@ module Pod ...@@ -67,21 +98,34 @@ module Pod
@part_of = dependency(*name_and_version_requirements) @part_of = dependency(*name_and_version_requirements)
end end
def source_files=(*patterns) def source_files=(patterns)
@source_files = patterns.flatten if !patterns.is_a?(Rake::FileList) && patterns.is_a?(Array)
@source_files = patterns
else
@source_files = [patterns]
end
end end
attr_reader :source_files attr_reader :source_files
def resources=(*patterns) def resources=(patterns)
@resources = patterns.flatten if !patterns.is_a?(Rake::FileList) && patterns.is_a?(Array)
@resources = patterns
else
@resources = [patterns]
end
end end
attr_reader :resources attr_reader :resources
alias_method :resource=, :resources= alias_method :resource=, :resources=
def clean_paths=(*patterns) def clean_paths=(patterns)
@clean_paths = patterns.flatten.map { |p| Pathname.new(p) } if !patterns.is_a?(Rake::FileList) && patterns.is_a?(Array)
@clean_paths = patterns
else
@clean_paths = [patterns]
end
end end
attr_reader :clean_paths attr_reader :clean_paths
alias_method :clean_path=, :clean_paths=
def xcconfig=(hash) def xcconfig=(hash)
@xcconfig.merge!(hash) @xcconfig.merge!(hash)
...@@ -182,9 +226,8 @@ module Pod ...@@ -182,9 +226,8 @@ module Pod
# project pods root. # project pods root.
def expanded_resources def expanded_resources
files = [] files = []
[*resources].each do |pattern| resources.each do |pattern|
pattern = pod_destroot + pattern pattern = pod_destroot + pattern
pattern = pattern + '*' if pattern.directory?
pattern.glob.each do |file| pattern.glob.each do |file|
files << file.relative_path_from(config.project_pods_root) files << file.relative_path_from(config.project_pods_root)
end end
...@@ -192,11 +235,27 @@ module Pod ...@@ -192,11 +235,27 @@ 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.
#
# If the pattern is the path to a directory, the pattern will
# automatically glob for c, c++, Objective-C, and Objective-C++
# files.
def expanded_source_files def expanded_source_files
files = [] files = []
[*source_files].each do |pattern| source_files.each do |pattern|
pattern = pod_destroot + pattern pattern = pod_destroot + pattern
pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory? pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
pattern.glob.each do |file| pattern.glob.each do |file|
...@@ -320,7 +379,7 @@ module Pod ...@@ -320,7 +379,7 @@ module Pod
def download! def download!
downloader = Downloader.for_source(pod_destroot, source) downloader = Downloader.for_source(pod_destroot, source)
downloader.download downloader.download
downloader.clean(clean_paths) if config.clean downloader.clean(expanded_clean_paths) if config.clean
end end
# This is a convenience method which gets called after all pods have been # This is a convenience method which gets called after all pods have been
......
...@@ -140,7 +140,6 @@ else ...@@ -140,7 +140,6 @@ else
end.should == %w{ supported supported } end.should == %w{ supported supported }
end end
if false
# TODO add a simple source file which uses the compiled lib to check that it really really works # TODO add a simple source file which uses the compiled lib to check that it really really works
it "should activate required pods and create a working static library xcode project" do it "should activate required pods and create a working static library xcode project" do
spec = Pod::Podfile.new do spec = Pod::Podfile.new do
...@@ -328,4 +327,3 @@ if false ...@@ -328,4 +327,3 @@ if false
end end
end end
end
...@@ -266,4 +266,16 @@ describe "A Pod::Specification, in general," do ...@@ -266,4 +266,16 @@ describe "A Pod::Specification, in general," do
@spec.license = 'MIT' @spec.license = 'MIT'
@spec.license.should == 'MIT' @spec.license.should == 'MIT'
end end
it "takes a list of paths to clean" do
@spec.clean_paths = 'Demo', 'Doc'
@spec.clean_paths.should == %w{ Demo Doc }
end
it "takes any object for clean_paths as long as it responds to #glob (we provide this for Rake::FileList)" do
require 'rake'
@spec.clean_paths = FileList['*'].exclude('Rakefile')
list = ROOT + @spec.clean_paths.first
list.glob.should == FileList[(ROOT + '*').to_s].exclude('Rakefile').map { |path| Pathname.new(path) }
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