diff options
Diffstat (limited to 'Bugzilla/Install/Util.pm')
-rw-r--r-- | Bugzilla/Install/Util.pm | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/Bugzilla/Install/Util.pm b/Bugzilla/Install/Util.pm index d65d2f592..50cbfd2a8 100644 --- a/Bugzilla/Install/Util.pm +++ b/Bugzilla/Install/Util.pm @@ -29,7 +29,9 @@ use strict; use Bugzilla::Constants; use Encode; +use ExtUtils::MM (); use File::Basename; +use File::Spec; use POSIX qw(setlocale LC_CTYPE); use Safe; use Scalar::Util qw(tainted); @@ -54,18 +56,19 @@ our @EXPORT_OK = qw( ); sub bin_loc { - my ($bin) = @_; - return '' if ON_WINDOWS; - # Don't print any errors from "which" - open(my $saveerr, ">&STDERR"); - open(STDERR, '>/dev/null'); - my $loc = `which $bin`; - close(STDERR); - open(STDERR, ">&", $saveerr); - my $exit_code = $? >> 8; # See the perlvar manpage. - return '' if $exit_code > 0; - chomp($loc); - return $loc; + my ($bin, $path) = @_; + my @path = $path ? @$path : File::Spec->path; + + foreach my $dir (@path) { + next if !-d $dir; + my $full_path = File::Spec->catfile($dir, $bin); + # MM is an alias for ExtUtils::MM. maybe_command is nice + # because it checks .com, .bat, .exe (etc.) on Windows. + my $command = MM->maybe_command($full_path); + return $command if $command; + } + + return ''; } sub get_version_and_os { |