Commit 524abbfa authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #3540 from orta/pre_install

Add a pre-install hook
parents 03c60f3c 132a29f2
...@@ -39,6 +39,13 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -39,6 +39,13 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Samuel Giddins](https://github.com/segiddins) [Samuel Giddins](https://github.com/segiddins)
[cocoapods-try#31](https://github.com/CocoaPods/cocoapods-try/issues/31) [cocoapods-try#31](https://github.com/CocoaPods/cocoapods-try/issues/31)
* Supports running pre-install hooks in plugins. This happens before the resolver
does its work, and offers easy access to the sandbox, podfile and lockfile via a
`PreInstallHooksContext` object. This also renames the post-install hooks from `HooksContext`
to `PostInstallHooksContext`.
[Orta Therox](https://github.com/orta)
[cocoapods#3540](https://github.com/CocoaPods/cocoapods/issues/3409)
##### Bug Fixes ##### Bug Fixes
* `pod repo push` will now find and push JSON podspecs. * `pod repo push` will now find and push JSON podspecs.
...@@ -49,7 +56,6 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -49,7 +56,6 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Boris Bügling](https://github.com/neonichu) [Boris Bügling](https://github.com/neonichu)
[#3500](https://github.com/CocoaPods/CocoaPods/issues/3500) [#3500](https://github.com/CocoaPods/CocoaPods/issues/3500)
## 0.37.1 ## 0.37.1
##### Bug Fixes ##### Bug Fixes
......
...@@ -31,7 +31,8 @@ module Pod ...@@ -31,7 +31,8 @@ module Pod
autoload :AggregateTargetInstaller, 'cocoapods/installer/target_installer/aggregate_target_installer' autoload :AggregateTargetInstaller, 'cocoapods/installer/target_installer/aggregate_target_installer'
autoload :Analyzer, 'cocoapods/installer/analyzer' autoload :Analyzer, 'cocoapods/installer/analyzer'
autoload :FileReferencesInstaller, 'cocoapods/installer/file_references_installer' autoload :FileReferencesInstaller, 'cocoapods/installer/file_references_installer'
autoload :HooksContext, 'cocoapods/installer/hooks_context' autoload :PostInstallHooksContext, 'cocoapods/installer/post_install_hooks_context'
autoload :PreInstallHooksContext, 'cocoapods/installer/pre_install_hooks_context'
autoload :Migrator, 'cocoapods/installer/migrator' autoload :Migrator, 'cocoapods/installer/migrator'
autoload :PodSourceInstaller, 'cocoapods/installer/pod_source_installer' autoload :PodSourceInstaller, 'cocoapods/installer/pod_source_installer'
autoload :PodSourcePreparer, 'cocoapods/installer/pod_source_preparer' autoload :PodSourcePreparer, 'cocoapods/installer/pod_source_preparer'
...@@ -106,6 +107,7 @@ module Pod ...@@ -106,6 +107,7 @@ module Pod
sandbox.prepare sandbox.prepare
ensure_plugins_are_installed! ensure_plugins_are_installed!
Migrator.migrate(sandbox) Migrator.migrate(sandbox)
run_plugins_pre_install_hooks
end end
end end
...@@ -128,7 +130,7 @@ module Pod ...@@ -128,7 +130,7 @@ module Pod
UI.section 'Downloading dependencies' do UI.section 'Downloading dependencies' do
create_file_accessors create_file_accessors
install_pod_sources install_pod_sources
run_pre_install_hooks run_podfile_pre_install_hooks
clean_pod_sources clean_pod_sources
lock_pod_sources lock_pod_sources
end end
...@@ -401,6 +403,15 @@ module Pod ...@@ -401,6 +403,15 @@ module Pod
end end
end end
# Runs the registered callbacks for the plugins pre install hooks.
#
# @return [void]
#
def run_plugins_pre_install_hooks
context = PreInstallHooksContext.generate(sandbox, podfile, lockfile)
HooksManager.run(:pre_install, context, podfile.plugins)
end
# Performs any post-installation actions # Performs any post-installation actions
# #
# @return [void] # @return [void]
...@@ -413,7 +424,7 @@ module Pod ...@@ -413,7 +424,7 @@ module Pod
# Runs the registered callbacks for the plugins post install hooks. # Runs the registered callbacks for the plugins post install hooks.
# #
def run_plugins_post_install_hooks def run_plugins_post_install_hooks
context = HooksContext.generate(sandbox, aggregate_targets) context = PostInstallHooksContext.generate(sandbox, aggregate_targets)
HooksManager.run(:post_install, context, podfile.plugins) HooksManager.run(:post_install, context, podfile.plugins)
end end
...@@ -669,7 +680,7 @@ module Pod ...@@ -669,7 +680,7 @@ module Pod
# #
# @return [void] # @return [void]
# #
def run_pre_install_hooks def run_podfile_pre_install_hooks
UI.message '- Running pre install hooks' do UI.message '- Running pre install hooks' do
executed = run_podfile_pre_install_hook executed = run_podfile_pre_install_hook
UI.message '- Podfile' if executed UI.message '- Podfile' if executed
......
...@@ -3,7 +3,7 @@ module Pod ...@@ -3,7 +3,7 @@ module Pod
# Context object designed to be used with the HooksManager which describes # Context object designed to be used with the HooksManager which describes
# the context of the installer. # the context of the installer.
# #
class HooksContext class PostInstallHooksContext
# @return [String] The path to the sandbox root (`Pods` directory). # @return [String] The path to the sandbox root (`Pods` directory).
# #
attr_accessor :sandbox_root attr_accessor :sandbox_root
...@@ -13,7 +13,7 @@ module Pod ...@@ -13,7 +13,7 @@ module Pod
# #
attr_accessor :umbrella_targets attr_accessor :umbrella_targets
# Generate a {HooksContext}. # @return [PostInstallHooksContext] Convenience class generator method
# #
# @param [Sandbox] sandbox # @param [Sandbox] sandbox
# The sandbox # The sandbox
......
module Pod
class Installer
# Context object designed to be used with the HooksManager which describes
# the context of the installer before analysis has been completed.
#
class PreInstallHooksContext
# @return [String] The path to the sandbox root (`Pods` directory).
#
attr_accessor :sandbox_root
# @return [Podfile] The Podfile for the project.
#
attr_accessor :podfile
# @return [Sandbox] The Sandbox for the project.
#
attr_accessor :sandbox
# @return [Lockfile] The Lockfile for the project.
#
attr_accessor :lockfile
# @return [PreInstallHooksContext] Convenience class method to generate the
# static context.
#
def self.generate(sandbox, podfile, lockfile)
result = new
result.podfile = podfile
result.sandbox = sandbox
result.lockfile = lockfile
result
end
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Installer::PreInstallHooksContext do
it 'offers a convenience method to be generated' do
sandbox, podfile, lockfile = stub, stub, stub
result = Installer::PreInstallHooksContext.generate(sandbox, podfile, lockfile)
result.class.should == Installer::PreInstallHooksContext
result.sandbox.should == sandbox
result.podfile.should == podfile
result.lockfile.should == lockfile
end
end
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../spec_helper', __FILE__)
module Pod module Pod
describe Installer::HooksContext do describe Installer::PostInstallHooksContext do
it 'offers a convenience method to be generated' do it 'offers a convenience method to be generated' do
sandbox = stub(:root => '/path') sandbox = stub(:root => '/path')
...@@ -15,8 +15,8 @@ module Pod ...@@ -15,8 +15,8 @@ module Pod
umbrella.stubs(:platform).returns(Platform.new(:ios, '8.0')) umbrella.stubs(:platform).returns(Platform.new(:ios, '8.0'))
umbrella.pod_targets = [pod_target] umbrella.pod_targets = [pod_target]
result = Installer::HooksContext.generate(sandbox, [umbrella]) result = Installer::PostInstallHooksContext.generate(sandbox, [umbrella])
result.class.should == Installer::HooksContext result.class.should == Installer::PostInstallHooksContext
result.sandbox_root.should == '/path' result.sandbox_root.should == '/path'
result.umbrella_targets.count.should == 1 result.umbrella_targets.count.should == 1
umbrella_target = result.umbrella_targets.first umbrella_target = result.umbrella_targets.first
......
...@@ -63,7 +63,7 @@ module Pod ...@@ -63,7 +63,7 @@ module Pod
@installer.unstub(:download_dependencies) @installer.unstub(:download_dependencies)
@installer.stubs(:create_file_accessors) @installer.stubs(:create_file_accessors)
@installer.stubs(:install_pod_sources) @installer.stubs(:install_pod_sources)
def @installer.run_pre_install_hooks def @installer.run_podfile_pre_install_hooks
@hook_called = true @hook_called = true
end end
def @installer.clean_pod_sources def @installer.clean_pod_sources
...@@ -74,7 +74,7 @@ module Pod ...@@ -74,7 +74,7 @@ module Pod
it 'in runs the post-install hooks before serializing the Pods project' do it 'in runs the post-install hooks before serializing the Pods project' do
@installer.stubs(:prepare_pods_project) @installer.stubs(:prepare_pods_project)
@installer.stubs(:run_pre_install_hooks) @installer.stubs(:run_podfile_pre_install_hooks)
@installer.stubs(:install_file_references) @installer.stubs(:install_file_references)
@installer.stubs(:install_libraries) @installer.stubs(:install_libraries)
@installer.stubs(:set_target_dependencies) @installer.stubs(:set_target_dependencies)
...@@ -685,16 +685,23 @@ module Pod ...@@ -685,16 +685,23 @@ module Pod
@installer.stubs(:installed_specs).returns(@specs) @installer.stubs(:installed_specs).returns(@specs)
end end
it 'runs plugins pre install hook' do
context = stub
Installer::PreInstallHooksContext.expects(:generate).returns(context)
HooksManager.expects(:run).with(:pre_install, context, {})
@installer.send(:run_plugins_pre_install_hooks)
end
it 'runs plugins post install hook' do it 'runs plugins post install hook' do
context = stub context = stub
Installer::HooksContext.expects(:generate).returns(context) Installer::PostInstallHooksContext.expects(:generate).returns(context)
HooksManager.expects(:run).with(:post_install, context, {}) HooksManager.expects(:run).with(:post_install, context, {})
@installer.send(:run_plugins_post_install_hooks) @installer.send(:run_plugins_post_install_hooks)
end end
it 'only runs the podfile-specified post-install hooks' do it 'only runs the podfile-specified hooks' do
context = stub context = stub
Installer::HooksContext.expects(:generate).returns(context) Installer::PostInstallHooksContext.expects(:generate).returns(context)
plugins_hash = { 'cocoapods-keys' => { 'keyring' => 'Eidolon' } } plugins_hash = { 'cocoapods-keys' => { 'keyring' => 'Eidolon' } }
@installer.podfile.stubs(:plugins).returns(plugins_hash) @installer.podfile.stubs(:plugins).returns(plugins_hash)
HooksManager.expects(:run).with(:post_install, context, plugins_hash) HooksManager.expects(:run).with(:post_install, context, plugins_hash)
...@@ -722,7 +729,7 @@ module Pod ...@@ -722,7 +729,7 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe 'Hooks' do describe 'Podfile Hooks' do
before do before do
@installer.send(:analyze) @installer.send(:analyze)
@specs = @installer.pod_targets.map(&:specs).flatten @specs = @installer.pod_targets.map(&:specs).flatten
...@@ -736,7 +743,7 @@ module Pod ...@@ -736,7 +743,7 @@ module Pod
@installer.expects(:installer_rep).returns(installer_rep) @installer.expects(:installer_rep).returns(installer_rep)
@installer.podfile.expects(:pre_install!).with(installer_rep) @installer.podfile.expects(:pre_install!).with(installer_rep)
@installer.send(:run_pre_install_hooks) @installer.send(:run_podfile_pre_install_hooks)
end end
it 'run_podfile_post_install_hooks' do it 'run_podfile_post_install_hooks' do
...@@ -756,7 +763,7 @@ module Pod ...@@ -756,7 +763,7 @@ module Pod
@installer.stubs(:pod_targets).returns([pod_target_ios, pod_target_osx]) @installer.stubs(:pod_targets).returns([pod_target_ios, pod_target_osx])
@installer.stubs(:installer_rep).returns(stub) @installer.stubs(:installer_rep).returns(stub)
@installer.podfile.expects(:pre_install!) @installer.podfile.expects(:pre_install!)
@installer.send(:run_pre_install_hooks) @installer.send(:run_podfile_pre_install_hooks)
@installer.send(:run_podfile_post_install_hooks) @installer.send(:run_podfile_post_install_hooks)
end end
......
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