Commit ca895cda authored by Samuel Giddins's avatar Samuel Giddins

[Executable] Handle when $PATH is not set

parent 1160056e
...@@ -32,6 +32,9 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -32,6 +32,9 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
`Copy Pods Resources` build phase. `Copy Pods Resources` build phase.
[seaders](https://github.com/seaders) [#4940](https://github.com/CocoaPods/CocoaPods/issues/4940) [seaders](https://github.com/seaders) [#4940](https://github.com/CocoaPods/CocoaPods/issues/4940)
* Handle when `$PATH` isn't set.
[Samuel Giddins](https://github.com/segiddins)
## 1.0.0.beta.4 (2016-02-24) ## 1.0.0.beta.4 (2016-02-24)
......
...@@ -46,8 +46,7 @@ module Pod ...@@ -46,8 +46,7 @@ module Pod
# @return [String] the output of the command (STDOUT and STDERR). # @return [String] the output of the command (STDOUT and STDERR).
# #
def self.execute_command(executable, command, raise_on_failure = true) def self.execute_command(executable, command, raise_on_failure = true)
bin = which(executable) bin = which!(executable)
raise Informative, "Unable to locate the executable `#{executable}`" unless bin
command = command.map(&:to_s) command = command.map(&:to_s)
full_command = "#{bin} #{command.join(' ')}" full_command = "#{bin} #{command.join(' ')}"
...@@ -87,7 +86,10 @@ module Pod ...@@ -87,7 +86,10 @@ module Pod
# #
def self.which(program) def self.which(program)
program = program.to_s program = program.to_s
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| paths = ENV.fetch('PATH') { '' }.split(File::PATH_SEPARATOR)
paths.unshift('./')
paths.uniq!
paths.each do |path|
bin = File.expand_path(program, path) bin = File.expand_path(program, path)
if File.file?(bin) && File.executable?(bin) if File.file?(bin) && File.executable?(bin)
return bin return bin
...@@ -96,6 +98,20 @@ module Pod ...@@ -96,6 +98,20 @@ module Pod
nil nil
end end
# Returns the absolute path to the binary with the given name on the current
# `PATH`, or raises if none is found.
#
# @param [String] program
# The name of the program being searched for.
#
# @return [String] The absolute path to the given program.
#
def self.which!(program)
which(program).tap do |bin|
raise Informative, "Unable to locate the executable `#{executable}`" unless bin
end
end
# Runs the given command, capturing the desired output. # Runs the given command, capturing the desired output.
# #
# @param [String] bin # @param [String] bin
...@@ -114,8 +130,7 @@ module Pod ...@@ -114,8 +130,7 @@ module Pod
# running the command. # running the command.
# #
def self.capture_command(executable, command, capture: :merge) def self.capture_command(executable, command, capture: :merge)
bin = which(executable) bin = which!(executable)
raise Informative, "Unable to locate the executable `#{executable}`" unless bin
require 'open3' require 'open3'
command = command.map(&:to_s) command = command.map(&:to_s)
......
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