Commit d1c6f442 authored by Eloy Duran's avatar Eloy Duran

Allow a user to define a post install hook in the Podfile, which allows her to…

Allow a user to define a post install hook in the Podfile, which allows her to customize the generated Xcode project. Closes #56.

Add MacRubySample to the rake build_examples task, now that it can
specify that it needs garbage collection support.
parent cf662d16
...@@ -81,7 +81,7 @@ task :build_examples do ...@@ -81,7 +81,7 @@ task :build_examples do
require 'pathname' require 'pathname'
examples = Pathname.new(File.expand_path('../examples', __FILE__)) examples = Pathname.new(File.expand_path('../examples', __FILE__))
examples.entries.each do |example| examples.entries.each do |example|
next if %w{ . .. ConfigureTest MacRubySample }.include?(example.basename.to_s) next if %w{ . .. }.include?(example.basename.to_s)
example = examples + example example = examples + example
next unless example.directory? next unless example.directory?
puts "Building example: #{example}" puts "Building example: #{example}"
...@@ -91,6 +91,7 @@ task :build_examples do ...@@ -91,6 +91,7 @@ task :build_examples do
sh "../../bin/pod install --verbose" sh "../../bin/pod install --verbose"
command = "xcodebuild -workspace '#{example.basename}.xcworkspace' -scheme '#{example.basename}'" command = "xcodebuild -workspace '#{example.basename}.xcworkspace' -scheme '#{example.basename}'"
if (example + 'Podfile').read.include?('platform :ios') if (example + 'Podfile').read.include?('platform :ios')
# Specifically build against the simulator SDK so we don't have to deal with code signing.
command << " -sdk /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk" command << " -sdk /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk"
end end
sh command sh command
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Workspace version="1.0"><FileRef location="group:ConfigureTest.xcodeproj"></FileRef><FileRef location="group:Pods/Pods.xcodeproj"></FileRef></Workspace>
\ No newline at end of file
//
// AppDelegate.h
// ConfigureTest
//
// Created by Eloy Duran on 25-10-11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@end
//
// AppDelegate.m
// ConfigureTest
//
// Created by Eloy Duran on 25-10-11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
- (void)dealloc
{
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>org.cocoapods.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2011 __MyCompanyName__. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
//
// Prefix header for all source files of the 'ConfigureTest' target in the 'ConfigureTest' project
//
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw9840\paperh8400
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f0\b\fs24 \cf0 Engineering:
\b0 \
Some people\
\
\b Human Interface Design:
\b0 \
Some other people\
\
\b Testing:
\b0 \
Hopefully not nobody\
\
\b Documentation:
\b0 \
Whoever\
\
\b With special thanks to:
\b0 \
Mom\
}
//
// main.m
// ConfigureTest
//
// Created by Eloy Duran on 25-10-11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **)argv);
}
platform :osx
dependency 'JSONKit'
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "${SRCROOT}/Pods/PodsResources.sh"; shellScript = "${SRCROOT}/Pods/Pods-resources.sh";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
/* End PBXShellScriptBuildPhase section */ /* End PBXShellScriptBuildPhase section */
......
...@@ -9,6 +9,15 @@ target :debug do ...@@ -9,6 +9,15 @@ target :debug do
dependency 'CocoaLumberjack' dependency 'CocoaLumberjack'
end end
target :test, :exclusive => true do #target :test, :exclusive => true do
dependency 'Kiwi' # dependency 'Kiwi'
#end
# Enable garbage collection support, which MacRuby requires.
post_install do |installer|
installer.project.targets.each do |target|
target.buildConfigurations.each do |config|
config.buildSettings['GCC_ENABLE_OBJC_GC'] = 'supported'
end
end
end end
PODS: PODS:
- ASIHTTPRequest (1.8.1) - ASIHTTPRequest (1.8.1)
- CocoaLumberjack (1.2.1) - CocoaLumberjack (1.2.1)
- Kiwi (1.0.0)
- SBJson (3.0.4) - SBJson (3.0.4)
DEPENDENCIES: DEPENDENCIES:
- ASIHTTPRequest - ASIHTTPRequest
- CocoaLumberjack - CocoaLumberjack
- Kiwi
- SBJson - SBJson
...@@ -196,23 +196,26 @@ EOS ...@@ -196,23 +196,26 @@ EOS
def install! def install!
puts "Installing dependencies of: #{@podfile.defined_in_file}" unless config.silent? puts "Installing dependencies of: #{@podfile.defined_in_file}" unless config.silent?
build_specifications.each(&:install!) build_specifications.each(&:install!)
root = config.project_pods_root root = config.project_pods_root
puts "==> Generating Xcode project and xcconfig" unless config.silent?
puts "==> Generating support files" unless config.silent?
target_installers.each do |target_installer| target_installers.each do |target_installer|
target_installer.install! target_installer.install!
target_installer.create_files_in(root) target_installer.create_files_in(root)
end end
projpath = File.join(root, 'Pods.xcodeproj')
puts " * Writing Xcode project file to `#{projpath}'" if config.verbose?
project.save_as(projpath)
generate_lock_file! generate_lock_file!
# Post install hooks run last! puts "==> Running post install hooks" unless config.silent?
# Post install hooks run _before_ saving of project, so that they can alter it before saving.
target_installers.each do |target_installer| target_installers.each do |target_installer|
target_installer.build_specifications.each { |spec| spec.post_install(target_installer) } target_installer.build_specifications.each { |spec| spec.post_install(target_installer) }
end end
@podfile.post_install!(self)
puts "==> Generating Xcode project" unless config.silent?
projpath = File.join(root, 'Pods.xcodeproj')
puts " * Writing Xcode project file to `#{projpath}'" if config.verbose?
project.save_as(projpath)
end end
def generate_lock_file! def generate_lock_file!
......
...@@ -135,16 +135,10 @@ module Pod ...@@ -135,16 +135,10 @@ module Pod
# #
# For more info on the definition of a Pod::Specification see: # For more info on the definition of a Pod::Specification see:
# https://github.com/CocoaPods/CocoaPods/wiki/A-pod-specification # https://github.com/CocoaPods/CocoaPods/wiki/A-pod-specification
#
#
def dependency(*name_and_version_requirements, &block) def dependency(*name_and_version_requirements, &block)
@target_definition.target_dependencies << Dependency.new(*name_and_version_requirements, &block) @target_definition.target_dependencies << Dependency.new(*name_and_version_requirements, &block)
end end
def dependencies
@target_definitions.values.map(&:target_dependencies).flatten
end
# Specifies that a BridgeSupport metadata should be generated from the # Specifies that a BridgeSupport metadata should be generated from the
# headers of all installed Pods. # headers of all installed Pods.
# #
...@@ -154,8 +148,6 @@ module Pod ...@@ -154,8 +148,6 @@ module Pod
@generate_bridge_support = true @generate_bridge_support = true
end end
attr_reader :target_definitions
# Defines a new static library target and scopes dependencies defined from # Defines a new static library target and scopes dependencies defined from
# the given block. The target will by default include the dependencies # the given block. The target will by default include the dependencies
# defined outside of the block, unless the `:exclusive => true` option is # defined outside of the block, unless the `:exclusive => true` option is
...@@ -190,23 +182,48 @@ module Pod ...@@ -190,23 +182,48 @@ module Pod
@target_definition = parent @target_definition = parent
end end
# This is to be compatible with a Specification for use in the Installer and # This hook allows you to make any last changes to the generated Xcode project
# Resolver. # before it is written to disk, or any other tasks you might want to perform.
#
# For instance, say you'd want to customize the `OTHER_LDFLAGS` of all targets:
#
# post_install do |installer|
# installer.project.targets.each do |target|
# target.buildConfigurations.each do |config|
# config.buildSettings['GCC_ENABLE_OBJC_GC'] = 'supported'
# end
# end
# end
def post_install(&block)
@post_install_callback = block
end
# Not attributes
def podfile? def podfile?
true true
end end
attr_accessor :defined_in_file attr_accessor :defined_in_file
attr_reader :target_definitions
def generate_bridge_support? def dependencies
@generate_bridge_support @target_definitions.values.map(&:target_dependencies).flatten
end end
def dependency_by_name(name) def dependency_by_name(name)
dependencies.find { |d| d.name == name } dependencies.find { |d| d.name == name }
end end
def generate_bridge_support?
@generate_bridge_support
end
def post_install!(installer)
@post_install_callback.call(installer) if @post_install_callback
end
def validate! def validate!
lines = [] lines = []
lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless [:osx, :ios].include?(@platform) lines << "* the `platform` attribute should be either `:osx` or `:ios`" unless [:osx, :ios].include?(@platform)
......
...@@ -121,6 +121,26 @@ else ...@@ -121,6 +121,26 @@ else
FileUtils.cp_r(fixture('integration/.'), config.project_pods_root) FileUtils.cp_r(fixture('integration/.'), config.project_pods_root)
end end
it "runs the optional post_install callback defined in the Podfile _before_ the project is saved to disk" do
podfile = Pod::Podfile.new do
config.rootspec = self
self.platform platform
post_install do |installer|
target = installer.project.targets.first
target.buildConfigurations.each do |config|
config.buildSettings['GCC_ENABLE_OBJC_GC'] = 'supported'
end
end
end
SpecHelper::Installer.new(podfile).install!
project = Xcodeproj::Project.new(config.project_pods_root + 'Pods.xcodeproj')
project.targets.first.buildConfigurations.map do |config|
config.buildSettings['GCC_ENABLE_OBJC_GC']
end.should == %w{ supported supported }
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
...@@ -308,3 +328,4 @@ else ...@@ -308,3 +328,4 @@ else
end end
end end
end
...@@ -49,6 +49,16 @@ describe "Pod::Podfile" do ...@@ -49,6 +49,16 @@ describe "Pod::Podfile" do
Pod::Podfile.new { generate_bridge_support! }.should.generate_bridge_support Pod::Podfile.new { generate_bridge_support! }.should.generate_bridge_support
end end
it "stores a block that will be called with the Installer instance once installation is finished (but the project is not written to disk yet)" do
yielded = nil
Pod::Podfile.new do
post_install do |installer|
yielded = installer
end
end.post_install!(:an_installer)
yielded.should == :an_installer
end
describe "concerning targets (dependency groups)" do describe "concerning targets (dependency groups)" do
before do before do
@podfile = Pod::Podfile.new do @podfile = Pod::Podfile.new 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