Commit d4dcab45 authored by Fabio Pelosin's avatar Fabio Pelosin

[Specification::DSL] Add prepare_command

Closes #1274
parent b329ce0b
...@@ -6,18 +6,22 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides ...@@ -6,18 +6,22 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
###### Enhancements ###### Enhancements
* Added support for resource bundles. * Added `resource_bundles` attribute to Specification DSL.
[#743](https://github.com/CocoaPods/CocoaPods/issues/743), [#743](https://github.com/CocoaPods/CocoaPods/issues/743),
[#1186](https://github.com/CocoaPods/CocoaPods/issues/1186) [#1186](https://github.com/CocoaPods/CocoaPods/issues/1186)
* Added support for bundled frameworks. * Added `vendored_frameworks` attribute to Specification DSL.
[#809](https://github.com/CocoaPods/CocoaPods/issues/809), [#809](https://github.com/CocoaPods/CocoaPods/issues/809),
[#1075](https://github.com/CocoaPods/CocoaPods/issues/1075) [#1075](https://github.com/CocoaPods/CocoaPods/issues/1075)
* Added support for bundled libraries. * Added `vendored_libraries` attribute to Specification DSL.
[#809](https://github.com/CocoaPods/CocoaPods/issues/809), [#809](https://github.com/CocoaPods/CocoaPods/issues/809),
[#1075](https://github.com/CocoaPods/CocoaPods/issues/1075) [#1075](https://github.com/CocoaPods/CocoaPods/issues/1075)
* Added `prepare_command` attribute to Specification DSL. The prepare command
will replace the pre_install hook. The post_install hook has been deprecated.
[#1247](https://github.com/CocoaPods/CocoaPods/issues/1247)
* Restructured `.cocoapods` folder to contain repos in a subdirectory. * Restructured `.cocoapods` folder to contain repos in a subdirectory.
[#1150](https://github.com/CocoaPods/CocoaPods/issues/1150) [#1150](https://github.com/CocoaPods/CocoaPods/issues/1150)
[Ian Ynda-Hummel](https://github.com/ianyh) [Ian Ynda-Hummel](https://github.com/ianyh)
......
require 'active_support/core_ext/string/strip'
module Pod module Pod
class Installer class Installer
...@@ -60,6 +62,7 @@ module Pod ...@@ -60,6 +62,7 @@ module Pod
# #
def install! def install!
download_source unless predownloaded? || local? download_source unless predownloaded? || local?
run_prepare_command
end end
# Cleans the installations if appropriate. # Cleans the installations if appropriate.
...@@ -106,6 +109,24 @@ module Pod ...@@ -106,6 +109,24 @@ module Pod
end end
end end
extend Executable
executable :bash
# Runs the prepare command bash script of the spec.
#
# @return [void]
#
def run_prepare_command
return unless root_spec.prepare_command
UI.section(" > Running prepare command", '', 1) do
Dir.chdir(root) do
prepare_command = root_spec.prepare_command.strip_heredoc.chomp
full_command = "\nset -e\n" + prepare_command
bash!(full_command)
end
end
end
# Removes all the files not needed for the installation according to the # Removes all the files not needed for the installation according to the
# specs by platform. # specs by platform.
# #
......
...@@ -65,6 +65,28 @@ module Pod ...@@ -65,6 +65,28 @@ module Pod
#--------------------------------------# #--------------------------------------#
describe "Prepare command" do
it "runs the prepare command if one has been declared in the spec" do
@spec.prepare_command = "echo test"
@installer.expects(:bash!).once
@installer.install!
end
it "doesn't run the prepare command if it hasn't been declared in the spec" do
@installer.expects(:bash!).never
@installer.install!
end
it "raises if the prepare command fails" do
@spec.prepare_command = "missing_command"
should.raise Informative do
@installer.install!
end.message.should.match /command not found/
end
end
#--------------------------------------#
describe "Cleaning" do describe "Cleaning" do
it "cleans the paths non used by the installation" do it "cleans the paths non used by the installation" 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