Commit 53946968 authored by Eloy Duran's avatar Eloy Duran

Append the contents of Specification#prefix_header_file to the Pods library's pch. Closes #169.

parent 0ac080a3
......@@ -35,11 +35,18 @@ module Pod
end
# TODO move out to Generator::PrefixHeader
def save_prefix_header_as(pathname)
def save_prefix_header_as(pathname, pods)
pathname.open('w') do |header|
header.puts "#ifdef __OBJC__"
header.puts "#import #{@target_definition.platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}"
header.puts "#endif"
pods.each do |pod|
if prefix_header = pod.prefix_header_file
header.puts
header.puts "// Pods/#{prefix_header.relative_path_from(pod.sandbox.root)}"
header.puts prefix_header.read
end
end
end
end
......@@ -92,7 +99,7 @@ module Pod
puts "* Generating xcconfig file at `#{sandbox.root + @target_definition.xcconfig_name}'" if config.verbose?
xcconfig.save_as(sandbox.root + @target_definition.xcconfig_name)
puts "* Generating prefix header at `#{sandbox.root + @target_definition.prefix_header_name}'" if config.verbose?
save_prefix_header_as(sandbox.root + @target_definition.prefix_header_name)
save_prefix_header_as(sandbox.root + @target_definition.prefix_header_name, pods)
puts "* Generating copy resources script at `#{sandbox.root + @target_definition.copy_resources_script_name}'" if config.verbose?
copy_resources_script_for(pods).save_as(sandbox.root + @target_definition.copy_resources_script_name)
end
......
......@@ -48,6 +48,12 @@ module Pod
def clean
clean_paths.each { |path| FileUtils.rm_rf(path) }
end
def prefix_header_file
if prefix_header = specification.prefix_header_file
@sandbox.root + specification.name + prefix_header
end
end
def source_files
expanded_paths(specification.source_files, :glob => '*.{h,m,mm,c,cpp}', :relative_to_sandbox => true)
......
......@@ -93,6 +93,11 @@ module Pod
@part_of = dependency(*name_and_version_requirements)
end
def prefix_header_file=(file)
@prefix_header_file = Pathname.new(file)
end
attr_reader :prefix_header_file
def clean_paths=(patterns)
@clean_paths = pattern_list(patterns)
end
......
......@@ -3,6 +3,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
TMP_POD_ROOT = ROOT + "tmp" + "podroot" unless defined? TMP_POD_ROOT
describe Pod::Installer::TargetInstaller do
extend SpecHelper::TemporaryDirectory
before do
@podfile = Pod::Podfile.new do
......@@ -17,6 +18,7 @@ describe Pod::Installer::TargetInstaller do
@installer = Pod::Installer::TargetInstaller.new(@podfile, @project, @target_definition)
@sandbox = Pod::Sandbox.new(TMP_POD_ROOT)
FileUtils.cp_r(fixture('banana-lib'), TMP_POD_ROOT + 'BananaLib')
@specification = fixture_spec('banana-lib/BananaLib.podspec')
@pods = [Pod::LocalPod.new(@specification, @sandbox, Pod::Platform.ios)]
end
......@@ -43,23 +45,33 @@ describe Pod::Installer::TargetInstaller do
it 'adds the sandbox header search paths to the xcconfig, with quotes' do
do_install!
@installer.xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include("\"#{@sandbox.header_search_paths.join(" ")}\"")
@installer.xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include("\"#{@sandbox.header_search_paths.join('" "')}\"")
end
it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do
do_install!
@installer.xcconfig.to_hash['OTHER_LDFLAGS'].split(" ").should.not.include("-fobjc-arc")
end
describe "when ARC compatibility flag is set" do
before do
@podfile.stubs(:set_arc_compatibility_flag? => true)
end
it 'adds the -fobjc-arc to OTHER_LDFLAGS if any pods require arc (to support non-ARC projects on iOS 4.0)' do
@specification.stubs(:requires_arc).returns(true)
@installer.install!(@pods, @sandbox)
@installer.xcconfig.to_hash['OTHER_LDFLAGS'].split(" ").should.include("-fobjc-arc")
end
it 'adds the -fobjc-arc to OTHER_LDFLAGS if any pods require arc (to support non-ARC projects on iOS 4.0)' do
@podfile.stubs(:set_arc_compatibility_flag? => true)
@specification.stubs(:requires_arc).returns(true)
@installer.install!(@pods, @sandbox)
@installer.xcconfig.to_hash['OTHER_LDFLAGS'].split(" ").should.include("-fobjc-arc")
end
it "creates a prefix header, including the contents of the specification's prefix header" do
do_install!
prefix_header = @sandbox.root + 'Pods.pch'
@installer.save_prefix_header_as(prefix_header, @pods)
prefix_header.read.should == <<-EOS
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
// Pods/BananaLib/Classes/BananaLib.pch
#import <BananaTree/BananaTree.h>
EOS
end
end
......@@ -222,6 +222,12 @@ describe "A Pod::Specification, in general," do
list = ROOT + @spec.clean_paths.first
list.glob.should == Pod::FileList[(ROOT + '*').to_s].exclude('Rakefile').map { |path| Pathname.new(path) }
end
it "takes a prefix header path which will be appended to the Pods pch file" do
@spec.prefix_header_file.should == nil
@spec.prefix_header_file = 'Classes/Demo.pch'
@spec.prefix_header_file.should == Pathname.new('Classes/Demo.pch')
end
end
describe "A Pod::Specification subspec" do
......
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