Commit 4a6e1e1c authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #3464 from CocoaPods/mr-cache-prepare-command

[Cache] Run the prepare_command before cleaning
parents 6cc8ec58 b725ef35
......@@ -41,6 +41,12 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Boris Bügling](https://github.com/neonichu)
[#3106](https://github.com/CocoaPods/CocoaPods/issues/3106)
* Run a pod's `prepare_command` (if it has one) before it is cleaned in the
download cache.
[Marius Rackwitz](https://github.com/mrackwitz)
[Samuel Giddins](https://github.com/segiddins)
[#3436](https://github.com/CocoaPods/CocoaPods/issues/3436)
## 0.37.0.beta.1
......
......@@ -188,6 +188,7 @@ module Pod
end
destination.parent.mkpath
FileUtils.cp_r(source, destination)
Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
end
......
......@@ -34,6 +34,7 @@ module Pod
autoload :HooksContext, 'cocoapods/installer/hooks_context'
autoload :Migrator, 'cocoapods/installer/migrator'
autoload :PodSourceInstaller, 'cocoapods/installer/pod_source_installer'
autoload :PodSourcePreparer, 'cocoapods/installer/pod_source_preparer'
autoload :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer'
autoload :TargetInstaller, 'cocoapods/installer/target_installer'
autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator'
......
......@@ -43,7 +43,7 @@ module Pod
#
def install!
download_source unless predownloaded? || local?
run_prepare_command
PodSourcePreparer.new(root_spec, root).prepare! if local?
lock_files!
end
......@@ -109,29 +109,6 @@ module Pod
end
end
extend Executable
executable :bash
# Runs the prepare command bash script of the spec.
#
# @note Unsets the `CDPATH` env variable before running the
# shell script to avoid issues with relative paths
# (issue #1694).
#
# @return [void]
#
def run_prepare_command
return unless root_spec.prepare_command
UI.section(' > Running prepare command', '', 1) do
Dir.chdir(root) do
ENV.delete('CDPATH')
prepare_command = root_spec.prepare_command.strip_heredoc.chomp
full_command = "\nset -e\n" + prepare_command
bash!('-c', full_command)
end
end
end
# Removes all the files not needed for the installation according to the
# specs by platform.
#
......
module Pod
class Installer
# Controller class responsible of executing the prepare command
# of a single Pod.
#
class PodSourcePreparer
# @return [Specification] the root specification of the Pod.
#
attr_reader :spec
# @return [Pathname] the folder where the source of the Pod is located.
#
attr_reader :path
# @param [Specification] spec the root specification of the Pod.
# @param [Pathname] path the folder where the source of the Pod is located.
#
def initialize(spec, path)
raise "Given spec isn't a root spec, but must be." unless spec.root?
@spec = spec
@path = path
end
#-----------------------------------------------------------------------#
public
# @!group Preparation
# Executes the prepare command if there is one.
#
# @return [void]
#
def prepare!
run_prepare_command
end
#-----------------------------------------------------------------------#
private
# @!group Preparation Steps
extend Executable
executable :bash
# Runs the prepare command bash script of the spec.
#
# @note Unsets the `CDPATH` env variable before running the
# shell script to avoid issues with relative paths
# (issue #1694).
#
# @return [void]
#
def run_prepare_command
return unless spec.prepare_command
UI.section(' > Running prepare command', '', 1) do
Dir.chdir(path) do
ENV.delete('CDPATH')
prepare_command = spec.prepare_command.strip_heredoc.chomp
full_command = "\nset -e\n" + prepare_command
bash!('-c', full_command)
end
end
end
#-----------------------------------------------------------------------#
end
end
end
Subproject commit c304744bab51c323cbe9a07d54900b3a372adfdc
Subproject commit e47491f7c98ccb6eaabb110740556bbb60ce6d6a
......@@ -84,8 +84,7 @@ CLIntegracon.configure do |c|
c.ignores %r{/xcuserdata/}
# Needed for some test cases
c.ignores 'Reachability.podspec'
c.ignores 'Moment.podspec'
c.ignores '*.podspec'
c.ignores 'PodTest-hg-source/**'
c.hook_into :bacon
......@@ -245,6 +244,14 @@ describe_cli 'pod' do
#--------------------------------------#
describe 'Pod lint' do
describe 'Lints a Pod from source with a prepare_command' do
# We have to disable verbose mode by adding --no-verbose here,
# otherwise xcodebuild output is included in execution output.
behaves_like cli_spec 'lib_lint_with_prepare_command',
'lib lint',
'--no-verbose'
end
describe 'Lints a Pod' do
behaves_like cli_spec 'spec_lint',
'spec lint --quick'
......
......@@ -67,12 +67,12 @@ 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::PodSourcePreparer.any_instance.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::PodSourcePreparer.any_instance.expects(:bash!).never
@installer.install!
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