Commit 581eb06a authored by Gabe Heafitz's avatar Gabe Heafitz Committed by Fabio Pelosin

[Rake] Check required binaries

hg (and git, for that matter) is required to run the install_subspecs spec. As a result, this
commit makes the Rake tasks die quickly if it is not installed.
parent 1bffd254
REQUIRED_COMMANDS = %w[ git hg ]
# Task check_requirements
#-----------------------------------------------------------------------------#
desc 'Verifies that the required third-party commands are available'
task :check_requirements do
has_all_requirements = REQUIRED_COMMANDS.inject(true) do |has_requirements, required_command|
result = has_required_binary?(required_command)
puts red("Missing required command: #{required_command}. You may need to install it.") unless result
has_requirements && result
end
raise unless has_all_requirements
end
# Bootstrap task # Bootstrap task
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
desc "Initializes your working copy to run the specs" desc "Initializes your working copy to run the specs"
task :bootstrap, :use_bundle_dir? do |t, args| task :bootstrap, [:use_bundle_dir?] => [:check_requirements] do |t, args|
title "Environment bootstrap" title "Environment bootstrap"
puts "Updating submodules" puts "Updating submodules"
...@@ -113,7 +127,7 @@ begin ...@@ -113,7 +127,7 @@ begin
#--------------------------------------# #--------------------------------------#
desc "Run the integration spec" desc "Run the integration spec"
task :integration do task :integration => :check_requirements do
unless File.exists?('spec/cocoapods-integration-specs') unless File.exists?('spec/cocoapods-integration-specs')
$stderr.puts red("Integration files not checked out. Run `rake bootstrap`") $stderr.puts red("Integration files not checked out. Run `rake bootstrap`")
exit 1 exit 1
...@@ -128,7 +142,7 @@ begin ...@@ -128,7 +142,7 @@ begin
# The specs helper interfere with the integration 2 specs and thus they need # The specs helper interfere with the integration 2 specs and thus they need
# to be run separately. # to be run separately.
# #
task :all => :unpack_fixture_tarballs do task :all => [:unpack_fixture_tarballs, :check_requirements] do
ENV['GENERATE_COVERAGE'] = 'true' ENV['GENERATE_COVERAGE'] = 'true'
puts "\033[0;32mUsing #{`ruby --version`}\033[0m" puts "\033[0;32mUsing #{`ruby --version`}\033[0m"
...@@ -300,3 +314,9 @@ end ...@@ -300,3 +314,9 @@ end
def red(string) def red(string)
"\033[0;31m#{string}\e[0m" "\033[0;31m#{string}\e[0m"
end end
def has_required_binary?(name)
`which #{name}`
$?.success?
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