summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib/mkmf.rb17
-rw-r--r--test/mkmf/test_find_executable.rb31
3 files changed, 44 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 3d2411f68c..6b5664a503 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Mar 11 18:42:43 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/mkmf.rb (find_executable0): should exclude directories.
+
Fri Mar 11 01:40:35 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* process.c (proc_getmaxgroups, proc_setmaxgroups): Process#maxgroups
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index cc9f918958..260875f732 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -1327,11 +1327,20 @@ end
# Internal use only.
#
def find_executable0(bin, path = nil)
+ executable_file = proc do |name|
+ begin
+ stat = File.stat(name)
+ rescue SystemCallError
+ else
+ next name if stat.file? and stat.executable?
+ end
+ end
+
exts = config_string('EXECUTABLE_EXTS') {|s| s.split} || config_string('EXEEXT') {|s| [s]}
if File.expand_path(bin) == bin
- return bin if File.executable?(bin)
+ return bin if executable_file.call(bin)
if exts
- exts.each {|ext| File.executable?(file = bin + ext) and return file}
+ exts.each {|ext| executable_file.call(file = bin + ext) and return file}
end
return nil
end
@@ -1342,9 +1351,9 @@ def find_executable0(bin, path = nil)
end
file = nil
path.each do |dir|
- return file if File.executable?(file = File.join(dir, bin))
+ return file if executable_file.call(file = File.join(dir, bin))
if exts
- exts.each {|ext| File.executable?(ext = file + ext) and return ext}
+ exts.each {|ext| executable_file.call(ext = file + ext) and return ext}
end
end
nil
diff --git a/test/mkmf/test_find_executable.rb b/test/mkmf/test_find_executable.rb
index 5ccec880fd..fe45ef2d1c 100644
--- a/test/mkmf/test_find_executable.rb
+++ b/test/mkmf/test_find_executable.rb
@@ -2,10 +2,18 @@ require_relative 'base'
class TestMkmf
class TestFindExecutable < TestMkmf
+ def setup
+ super
+ @path, ENV["PATH"] = ENV["PATH"], @tmpdir
+ end
+
+ def teardown
+ ENV["PATH"] = @path
+ super
+ end
+
def test_find_executable
bug2669 = '[ruby-core:27912]'
- path, ENV["PATH"] = ENV["PATH"], path
- ENV["PATH"] = @tmpdir
name = "foobar#{$$}#{rand(1000)}"
exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
stdout.filter {|s| s.sub(name, "<executable>")}
@@ -20,8 +28,23 @@ class TestMkmf
end
assert_equal("#{@tmpdir}/#{name}#{ext}", result, bug2669)
end
- ensure
- ENV["PATH"] = path
+ end
+
+ def test_find_executable_dir
+ name = "foobar#{$$}#{rand(1000)}"
+ exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
+ stdout.filter {|s| s.sub(name, "<executable>")}
+ exts[0] ||= ""
+ exts.each do |ext|
+ full = name+ext
+ begin
+ Dir.mkdir(full)
+ result = mkmf {find_executable(name)}
+ ensure
+ Dir.rmdir(full)
+ end
+ assert_nil(result)
+ end
end
end
end