Commit 0fc24622 authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #3818 from CocoaPods/seg-which

[Executable] Dont use a subprocess for which
parents 4e74f0da 89a29416
......@@ -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,26 @@ 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.
#
# @param [String] program
# The name of the program being searched for.
#
# @return [String,Nil] The absolute path to the given program, or `nil` if
# it wasn't found in the current `PATH`.
#
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?
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
headers = %w(/some/dir/foo.h /some/dir/bar.h /some/other/dir/baz.h).map { |h| Pathname.new(h) }
generator = Pod::Generator::BridgeSupport.new(headers)
expected = ['-c', "-I '/some/dir' -I '/some/other/dir'", '-o', '/path/to/Pods.bridgesupport', *headers]
generator.expects(:gen_bridge_metadata).with { |*command| command.map(&:to_s) == expected.map(&:to_s) }
generator.save_as(Pathname.new('/path/to/Pods.bridgesupport'))
module Pod
describe 'Pod::Generator::BridgeSupport' do
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
headers = %w(/some/dir/foo.h /some/dir/bar.h /some/other/dir/baz.h).map { |h| Pathname.new(h) }
generator = Generator::BridgeSupport.new(headers)
expected = ['-c', "-I '/some/dir' -I '/some/other/dir'", '-o', '/path/to/Pods.bridgesupport', *headers]
generator.expects(:gen_bridge_metadata).with { |*command| command.map(&:to_s) == expected.map(&:to_s) }
generator.save_as(Pathname.new('/path/to/Pods.bridgesupport'))
end
end
end
end
......@@ -378,7 +378,9 @@ module Pod
validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
validator.stubs(:check_file_patterns)
validator.stubs(:validate_url)
validator.expects(:`).with('which xcodebuild').times(3).returns('/usr/bin/xcodebuild')
git = Executable.which(:git)
Executable.stubs(:which).with('git').returns(git)
Executable.expects(:which).with('xcodebuild').times(3).returns('/usr/bin/xcodebuild')
status = mock
status.stubs(:success?).returns(false)
validator.stubs(:_xcodebuild).returns(['Output', status])
......@@ -393,7 +395,9 @@ module Pod
validator = Validator.new(podspec_path, SourcesManager.master.map(&:url))
validator.stubs(:check_file_patterns)
validator.stubs(:validate_url)
validator.expects(:`).with('which xcodebuild').times(3).returns('/usr/bin/xcodebuild')
git = Executable.which(:git)
Executable.stubs(:which).with('git').returns(git)
Executable.expects(:which).with('xcodebuild').times(3).returns('/usr/bin/xcodebuild')
command = 'xcodebuild clean build -target Pods'
validator.expects(:`).with("#{command} 2>&1").twice.returns('')
validator.expects(:`).with("#{command} CODE_SIGN_IDENTITY=- -sdk iphonesimulator 2>&1").once.returns('')
......
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