Commit 2cd77b5a authored by Marius Rackwitz's avatar Marius Rackwitz Committed by Samuel E. Giddins

[Installer] Extract run_prepare_command in own controller class

parent a572eb55
...@@ -188,6 +188,7 @@ module Pod ...@@ -188,6 +188,7 @@ module Pod
end end
destination.parent.mkpath destination.parent.mkpath
FileUtils.cp_r(source, destination) FileUtils.cp_r(source, destination)
Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean! Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
end end
......
...@@ -34,6 +34,7 @@ module Pod ...@@ -34,6 +34,7 @@ module Pod
autoload :HooksContext, 'cocoapods/installer/hooks_context' autoload :HooksContext, 'cocoapods/installer/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 :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer' autoload :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer'
autoload :TargetInstaller, 'cocoapods/installer/target_installer' autoload :TargetInstaller, 'cocoapods/installer/target_installer'
autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator' autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator'
......
...@@ -43,7 +43,7 @@ module Pod ...@@ -43,7 +43,7 @@ module Pod
# #
def install! def install!
download_source unless predownloaded? || local? download_source unless predownloaded? || local?
run_prepare_command PodSourcePreparer.new(root_spec, root).prepare! if local?
lock_files! lock_files!
end end
...@@ -109,29 +109,6 @@ module Pod ...@@ -109,29 +109,6 @@ module Pod
end end
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 # Removes all the files not needed for the installation according to the
# specs by platform. # 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
...@@ -67,12 +67,12 @@ module Pod ...@@ -67,12 +67,12 @@ module Pod
describe 'Prepare command' do describe 'Prepare command' do
it 'runs the prepare command if one has been declared in the spec' do it 'runs the prepare command if one has been declared in the spec' do
@spec.prepare_command = 'echo test' @spec.prepare_command = 'echo test'
@installer.expects(:bash!).once Installer::PodSourcePreparer.any_instance.expects(:bash!).once
@installer.install! @installer.install!
end end
it "doesn't run the prepare command if it hasn't been declared in the spec" do 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! @installer.install!
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