Commit 18f6fe20 authored by Eloy Duran's avatar Eloy Duran

Add a post install hook which allows a pod spec to run custom code.

For instance, by appending code to the Pods prefix header.
parent cb5f3890
module Pod module Pod
# TODO the static library needs an extra xcconfig which sets the values from issue #1.
# Or we could edit the project.pbxproj file, but that seems like more work...
class Installer class Installer
include Config::Mixin include Config::Mixin
...@@ -16,6 +14,10 @@ module Pod ...@@ -16,6 +14,10 @@ module Pod
dependent_specification_sets.reject(&:only_part_of_other_pod?) dependent_specification_sets.reject(&:only_part_of_other_pod?)
end end
def build_specifications
build_specification_sets.map(&:specification)
end
def xcconfig def xcconfig
@xcconfig ||= Xcode::Config.new({ @xcconfig ||= Xcode::Config.new({
# In a workspace this is where the static library headers should be found # In a workspace this is where the static library headers should be found
...@@ -33,8 +35,7 @@ module Pod ...@@ -33,8 +35,7 @@ module Pod
def generate_project def generate_project
puts "==> Generating Xcode project and xcconfig" unless config.silent? puts "==> Generating Xcode project and xcconfig" unless config.silent?
user_header_search_paths = [] user_header_search_paths = []
build_specification_sets.each do |set| build_specifications.each do |spec|
spec = set.specification
xcconfig.merge!(spec.xcconfig) xcconfig.merge!(spec.xcconfig)
group = xcodeproj.add_pod_group(spec.name) group = xcodeproj.add_pod_group(spec.name)
...@@ -59,25 +60,22 @@ module Pod ...@@ -59,25 +60,22 @@ module Pod
end end
def bridge_support_generator def bridge_support_generator
BridgeSupportGenerator.new(build_specification_sets.map do |set| BridgeSupportGenerator.new(build_specifications.map do |spec|
set.specification.header_files.map do |header| spec.header_files.map do |header|
config.project_pods_root + header config.project_pods_root + header
end end
end.flatten) end.flatten)
end end
# TODO we need a spec that tests that all dependencies are first downloaded/installed
# before #generate_project is called!
def install! def install!
puts "Installing dependencies of: #{@specification.defined_in_file}" unless config.silent? puts "Installing dependencies of: #{@specification.defined_in_file}" unless config.silent?
build_specification_sets.each do |set| build_specifications.each(&:install!)
set.specification.install!
end
generate_project generate_project
root = config.project_pods_root root = config.project_pods_root
xcodeproj.create_in(root) xcodeproj.create_in(root)
xcconfig.create_in(root) xcconfig.create_in(root)
bridge_support_generator.create_in(root) if @specification.generate_bridge_support bridge_support_generator.create_in(root) if @specification.generate_bridge_support
build_specifications.each(&:post_install)
end end
end end
end end
...@@ -257,8 +257,8 @@ module Pod ...@@ -257,8 +257,8 @@ module Pod
# Override this if you need to perform work before or after activating the # Override this if you need to perform work before or after activating the
# pod. Eg: # pod. Eg:
# #
# Pod::Spec.new do # Pod::Spec.new do |s|
# def install! # def s.install!
# # pre-install # # pre-install
# super # super
# # post-install # # post-install
...@@ -290,8 +290,8 @@ module Pod ...@@ -290,8 +290,8 @@ module Pod
# Override this if you need to perform work before or after downloading the # Override this if you need to perform work before or after downloading the
# pod, or if you need to implement custom dowloading. Eg: # pod, or if you need to implement custom dowloading. Eg:
# #
# Pod::Spec.new do # Pod::Spec.new do |s|
# def download! # def s.download!
# # pre-download # # pre-download
# super # or custom downloading # super # or custom downloading
# # post-download # # post-download
...@@ -303,6 +303,21 @@ module Pod ...@@ -303,6 +303,21 @@ module Pod
downloader.clean(clean_paths) if config.clean downloader.clean(clean_paths) if config.clean
end end
# This is a convenience method which gets called after all pods have been
# downloaded, installed, and the Xcode project and related files have been
# generated. Override this to, for instance, add to the prefix header:
#
# Pod::Spec.new do |s|
# def s.post_install
# prefix_header = config.project_pods_root + 'Pods-Prefix.pch'
# prefix_header.open('a') do |file|
# file.puts(%{#ifdef __OBJC__\n#import "SSToolkitDefines.h"\n#endif})
# end
# end
# end
def post_install
end
end end
Spec = Specification Spec = Specification
......
...@@ -12,6 +12,21 @@ describe "Pod::Installer" do ...@@ -12,6 +12,21 @@ describe "Pod::Installer" do
config.repos_dir = SpecHelper.tmp_repos_path config.repos_dir = SpecHelper.tmp_repos_path
end end
it "generates a BridgeSupport metadata file from all the pod headers" do
spec = Pod::Spec.new do |s|
s.platform = :osx
s.dependency 'ASIHTTPRequest'
end
expected = []
installer = Pod::Installer.new(spec)
installer.build_specifications.each do |spec|
spec.header_files.each do |header|
expected << config.project_pods_root + header
end
end
installer.bridge_support_generator.headers.should == expected
end
it "adds all source files that should be included in the library to the xcode project" do it "adds all source files that should be included in the library to the xcode project" 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