Permalink
Browse files

+ partial installer spec

  • Loading branch information...
1 parent 1139295 commit 3744f6911ce92d16a4b2bea725cd4e9a81a23646 @alloy alloy committed Sep 16, 2011
Showing with 92 additions and 25 deletions.
  1. +11 −0 .kick
  2. +6 −0 lib/cocoa_pods.rb
  3. +26 −19 lib/cocoa_pods/installer.rb
  4. +7 −3 lib/cocoa_pods/specification.rb
  5. +42 −3 spec/unit/installer_spec.rb
View
@@ -1,3 +1,14 @@
recipe :ruby
Ruby.runner_bin = 'macbacon'
+
+process do |files|
+ specs = files.take_and_map do |file|
+ case file
+ when %r{lib/cocoa_pods/(.+?)\.rb$}
+ s = Dir.glob("spec/**/#{$1}_spec.rb")
+ s unless s.empty?
+ end
+ end
+ Ruby.run_tests(specs)
+end
View
@@ -21,3 +21,9 @@ module Xcode
autoload :Pathname, 'pathname'
autoload :Executioner, 'executioner'
end
+
+class Pathname
+ def glob(pattern = '')
+ Dir.glob((self + pattern).to_s).map { |f| Pathname.new(f) }
+ end
+end
@@ -4,12 +4,31 @@ module Pod
class Installer
include Config::Mixin
- def initialize(top_level_specification)
- @top_level_specification = top_level_specification
+ def initialize(specification)
+ @specification = specification
end
def dependent_specification_sets
- @dependent_specifications_sets ||= Resolver.new(@top_level_specification).resolve
+ @dependent_specification_sets ||= Resolver.new(@specification).resolve
+ end
+
+ def build_specification_sets
+ dependent_specification_sets.reject(&:only_part_of_other_pod?)
+ end
+
+ def source_files
+ source_files = []
+ build_specification_sets.each do |set|
+ spec = set.specification
+ spec.read(:source_files).each do |pattern|
+ pattern = spec.pod_destroot + pattern
+ pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
+ pattern.glob.each do |file|
+ source_files << file.relative_path_from(config.project_pods_root)
+ end
+ end
+ end
+ source_files
end
def xcconfig
@@ -27,7 +46,7 @@ def xproj
def install!
unless config.silent?
- puts "Installing dependencies defined in: #{@top_level_specification.defined_in_file}"
+ puts "Installing dependencies defined in: #{@specification.defined_in_file}"
end
install_dependent_specifications!
generate_project
@@ -45,21 +64,9 @@ def install_dependent_specifications!
def generate_project
puts "==> Creating Pods project files" unless config.silent?
- dependent_specification_sets.each do |set|
- # In case the set is only part of other pods we don't need to build
- # the pod itself.
- next if set.only_part_of_other_pod?
- spec = set.specification
- spec.read(:source_files).each do |pattern|
- pattern = spec.pod_destroot + pattern
- pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
- Dir.glob(pattern.to_s).each do |file|
- file = Pathname.new(file)
- file = file.relative_path_from(config.project_pods_root)
- xproj.add_source_file(file)
- end
- end
- xcconfig << spec.read(:xcconfig)
+ source_files.each { |file| xproj.add_source_file(file) }
+ build_specification_sets.each do |set|
+ xcconfig << set.specification.read(:xcconfig)
end
end
@@ -104,13 +104,17 @@ def dependency_by_name(name)
@dependencies.find { |d| d.name == name }
end
- # Returns the specification for the pod that this pod's source is a part of.
- def part_of_specification
+ def part_of_specification_set
if @part_of
- Set.by_specification_name(@part_of.name).specification
+ Set.by_specification_name(@part_of.name)
end
end
+ # Returns the specification for the pod that this pod's source is a part of.
+ def part_of_specification
+ (set = part_of_specification_set) && set.specification
+ end
+
def pod_destroot
return if from_podfile?
if part_of_other_pod?
@@ -2,14 +2,53 @@
describe "Pod::Installer" do
before do
+ config.project_pods_root = fixture('integration')
fixture('spec-repos/master') # ensure the archive is unpacked
config.repos_dir = fixture('spec-repos')
- @spec = Pod::Spec.new do
- dependency 'JSONKit'
- end
end
after do
+ config.project_pods_root = nil
config.repos_dir = SpecHelper.tmp_repos_path
end
+
+ it "adds all source files that should be included in the library to the xcode project" do
+ [
+ [
+ 'ASIHTTPRequest',
+ ['Classes'],
+ "{Classes,External/Reachability}/*.{h,m}"
+ ],
+ [
+ 'Reachability',
+ ["External/Reachability/*.h", "External/Reachability/*.m"],
+ "External/Reachability/*.{h,m}"
+ ],
+ [
+ 'ASIWebPageRequest',
+ ['**/ASIWebPageRequest.*'],
+ "{Classes,Classes/ASIWebPageRequest,External/Reachability}/*.{h,m}"
+ ],
+ ].each do |name, patterns, expected_pattern|
+ Pod::Source.reset!
+ Pod::Spec::Set.reset!
+ installer = Pod::Installer.new(Pod::Spec.new { dependency(name); source_files(*patterns) })
+ expected = (stubbed_destroot(installer) + expected_pattern).glob.map do |file|
+ file.relative_path_from(config.project_pods_root)
+ end
+ installer.source_files.size.should == expected.size
+ installer.source_files.sort.should == expected.sort
+ #installer.xproj.source_files.sort.should == expected.sort
+ end
+ end
+
+ def stubbed_destroot(installer)
+ set = installer.dependent_specification_sets.find { |s| s.name == 'ASIHTTPRequest' }
+ spec = set.specification
+ set.extend(Module.new { define_method(:specification) { spec }})
+ def spec.pod_destroot
+ config.project_pods_root + 'ASIHTTPRequest' # without name and version
+ end
+ spec.pod_destroot
+ end
end

0 comments on commit 3744f69

Please sign in to comment.