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
# @todo Find a way to display the live output of the commands.
#
def self.execute_command(executable, command, raise_on_failure)
bin = `which #{executable}`.strip
raise Informative, "Unable to locate the executable `#{executable}`" if bin.empty?
bin = which(executable)
raise Informative, "Unable to locate the executable `#{executable}`" unless bin
require 'shellwords'
......@@ -75,6 +75,20 @@ module Pod
output
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
def self.popen3(bin, command, stdout, stderr)
......
......@@ -381,7 +381,7 @@ module Pod
# @return [void]
#
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
else
UI.message "\nBuilding with xcodebuild.\n".yellow do
......
......@@ -70,7 +70,7 @@ end
#-----------------------------------------------------------------------------#
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'
end
......
......@@ -12,7 +12,8 @@ module Pod
it 'should support spaces in the full path of the command' do
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.stubs(:success?).returns(true)
......
require File.expand_path('../../../spec_helper', __FILE__)
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."
else
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