Skip to content

Commit

Permalink
Encapsulate adding a pod's source files to an Xcode target within Loc…
Browse files Browse the repository at this point in the history
…alPod.
  • Loading branch information
lukeredpath committed Feb 25, 2012
1 parent ef25e3f commit 8390e00
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -7,5 +7,5 @@ group :development do
gem "guard-bacon" gem "guard-bacon"
gem "rb-fsevent" gem "rb-fsevent"
gem "growl" gem "growl"
gem "mocha" gem "mocha-on-bacon"
end end
4 changes: 3 additions & 1 deletion Gemfile.lock
Expand Up @@ -11,6 +11,8 @@ GEM
metaclass (0.0.1) metaclass (0.0.1)
mocha (0.10.4) mocha (0.10.4)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mocha-on-bacon (0.2.0)
mocha (>= 0.9.8)
rake (0.9.2.2) rake (0.9.2.2)
rb-fsevent (0.9.0) rb-fsevent (0.9.0)
schmurfy-bacon (1.2.1) schmurfy-bacon (1.2.1)
Expand All @@ -26,6 +28,6 @@ DEPENDENCIES
growl growl
guard guard
guard-bacon guard-bacon
mocha mocha-on-bacon
rake rake
rb-fsevent rb-fsevent
6 changes: 1 addition & 5 deletions lib/cocoapods/installer/target_installer.rb
Expand Up @@ -66,11 +66,7 @@ def install!(pods, sandbox)


pods.each do |pod| pods.each do |pod|
xcconfig.merge!(pod.specification.xcconfig) xcconfig.merge!(pod.specification.xcconfig)

pod.add_to_target(@target)
pod.implementation_files.each do |file|
@target.add_source_file(file, nil, pod.specification.compiler_flags)
end

pod.link_headers pod.link_headers
end end


Expand Down
14 changes: 10 additions & 4 deletions lib/cocoapods/local_pod.rb
Expand Up @@ -50,10 +50,6 @@ def clean_paths
def resources def resources
expanded_paths(specification.resources, :relative_to_sandbox => true) expanded_paths(specification.resources, :relative_to_sandbox => true)
end end

def implementation_files
source_files.select { |f| f.extname != '.h' }
end


def header_files def header_files
source_files.select { |f| f.extname == '.h' } source_files.select { |f| f.extname == '.h' }
Expand All @@ -65,8 +61,18 @@ def link_headers
end end
end end


def add_to_target(target)
implementation_files.each do |file|
target.add_source_file(file, nil, specification.compiler_flags)
end
end

private private


def implementation_files
source_files.select { |f| f.extname != '.h' }
end

def relative_root def relative_root
root.relative_path_from(@sandbox.root) root.relative_path_from(@sandbox.root)
end end
Expand Down
8 changes: 2 additions & 6 deletions lib/cocoapods/specification.rb
Expand Up @@ -121,8 +121,8 @@ def header_dir


attr_writer :compiler_flags attr_writer :compiler_flags
def compiler_flags def compiler_flags
flags = "#{@compiler_flags} " flags = "#{@compiler_flags}"
flags << '-fobjc-arc' if requires_arc flags << ' -fobjc-arc' if requires_arc
flags flags
end end


Expand Down Expand Up @@ -265,10 +265,6 @@ def expanded_source_files
files files
end end


def implementation_files
expanded_source_files.select { |f| f.extname != '.h' }
end

# Returns only the header files of this pod. # Returns only the header files of this pod.
def header_files def header_files
expanded_source_files.select { |f| f.extname == '.h' } expanded_source_files.select { |f| f.extname == '.h' }
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
@@ -1,6 +1,6 @@
require 'rubygems' require 'rubygems'
require 'bacon' require 'bacon'
require 'mocha' require 'mocha-on-bacon'


require 'pathname' require 'pathname'
ROOT = Pathname.new(File.expand_path('../../', __FILE__)) ROOT = Pathname.new(File.expand_path('../../', __FILE__))
Expand Down
17 changes: 13 additions & 4 deletions spec/unit/local_pod_spec.rb
Expand Up @@ -45,10 +45,6 @@
@pod.resources.should == [Pathname.new("BananaLib/Resources/logo-sidebar.png")] @pod.resources.should == [Pathname.new("BananaLib/Resources/logo-sidebar.png")]
end end


it 'returns a list of implementation files' do
@pod.implementation_files.should == [Pathname.new("BananaLib/Classes/Banana.m")]
end

it 'returns a list of header files' do it 'returns a list of header files' do
@pod.header_files.should == [Pathname.new("BananaLib/Classes/Banana.h")] @pod.header_files.should == [Pathname.new("BananaLib/Classes/Banana.h")]
end end
Expand All @@ -70,4 +66,17 @@
File.read(expected_header_path).should == (@sandbox.root + @pod.header_files[0]).read File.read(expected_header_path).should == (@sandbox.root + @pod.header_files[0]).read
end end


it "can add it's source files to an Xcode project target" do
target = mock('target')
target.expects(:add_source_file).with(Pathname.new("BananaLib/Classes/Banana.m"), anything, anything)
@pod.add_to_target(target)
end

it "can add it's source files to a target with any specially configured compiler flags" do
@pod.specification.compiler_flags = '-d some_flag'
target = mock('target')
target.expects(:add_source_file).with(anything, anything, "-d some_flag")
@pod.add_to_target(target)
end

end end
6 changes: 0 additions & 6 deletions spec/unit/specification_spec.rb
Expand Up @@ -160,12 +160,6 @@
@spec.header_files.sort.should == files.sort @spec.header_files.sort.should == files.sort
end end


it "returns the list of implementation files" do
files = @destroot.glob('**/*.{c,m}')
files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.implementation_files.sort.should == files.sort
end

it "returns a hash of mappings from the pod's destroot to its header dirs, which by default is just the pod's header dir" do it "returns a hash of mappings from the pod's destroot to its header dirs, which by default is just the pod's header dir" do
@spec.copy_header_mappings.size.should == 1 @spec.copy_header_mappings.size.should == 1
@spec.copy_header_mappings[Pathname.new('SSZipArchive')].sort.should == %w{ @spec.copy_header_mappings[Pathname.new('SSZipArchive')].sort.should == %w{
Expand Down

0 comments on commit 8390e00

Please sign in to comment.