Commit 7d0a5c10 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Executable] Dont use a subprocess for which

parent b26f26ba
...@@ -48,8 +48,8 @@ module Pod ...@@ -48,8 +48,8 @@ module Pod
# @todo Find a way to display the live output of the commands. # @todo Find a way to display the live output of the commands.
# #
def self.execute_command(executable, command, raise_on_failure) def self.execute_command(executable, command, raise_on_failure)
bin = `which #{executable}`.strip bin = which(executable)
raise Informative, "Unable to locate the executable `#{executable}`" if bin.empty? raise Informative, "Unable to locate the executable `#{executable}`" unless bin
require 'shellwords' require 'shellwords'
...@@ -75,6 +75,20 @@ module Pod ...@@ -75,6 +75,20 @@ module Pod
output output
end end
# Returns the absolute path to the binary with the given name on the current
# `PATH`, or `nil` if none is found.
#
def self.which(program)
program = program.to_s
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
bin = File.expand_path(program, path)
if File.file?(bin) && File.executable?(bin)
return bin
end
end
nil
end
private private
def self.popen3(bin, command, stdout, stderr) def self.popen3(bin, command, stdout, stderr)
......
...@@ -381,7 +381,7 @@ module Pod ...@@ -381,7 +381,7 @@ module Pod
# @return [void] # @return [void]
# #
def build_pod def build_pod
if `which xcodebuild`.strip.empty? if Executable.which('xcodebuild').nil?
UI.warn "Skipping compilation with `xcodebuild' because it can't be found.\n".yellow UI.warn "Skipping compilation with `xcodebuild' because it can't be found.\n".yellow
else else
UI.message "\nBuilding with xcodebuild.\n".yellow do UI.message "\nBuilding with xcodebuild.\n".yellow do
......
...@@ -70,7 +70,7 @@ end ...@@ -70,7 +70,7 @@ end
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
ENV['SKIP_SETUP'] = 'true' ENV['SKIP_SETUP'] = 'true'
if ENV['SKIP_XCODEBUILD'].nil? && `which xcodebuild`.strip.empty? if ENV['SKIP_XCODEBUILD'].nil? && Pod::Executable.which('xcodebuild').nil?
ENV['SKIP_XCODEBUILD'] = 'true' ENV['SKIP_XCODEBUILD'] = 'true'
end end
......
...@@ -12,7 +12,8 @@ module Pod ...@@ -12,7 +12,8 @@ module Pod
it 'should support spaces in the full path of the command' do it 'should support spaces in the full path of the command' do
cmd = '/Spa ces/are"/fun/false' cmd = '/Spa ces/are"/fun/false'
Executable.stubs(:`).returns(cmd) File.expects(:file?).with(cmd).returns(true)
File.expects(:executable?).with(cmd).returns(true)
result = mock result = mock
result.stubs(:success?).returns(true) result.stubs(:success?).returns(true)
......
require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../spec_helper', __FILE__)
describe 'Pod::Generator::BridgeSupport' do describe 'Pod::Generator::BridgeSupport' do
if `which gen_bridge_metadata`.strip.empty? if Executable.which('gen_bridge_metadata').nil?
puts ' ! '.red << "Skipping because the `gen_bridge_metadata` executable can't be found." puts ' ! '.red << "Skipping because the `gen_bridge_metadata` executable can't be found."
else else
it 'generates a metadata file with the appropriate search paths' do it 'generates a metadata file with the appropriate search paths' 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