From c361a959c98695906659cda6a44846fc06cf3741 Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Tue, 18 Oct 2022 03:13:13 -0500 Subject: [PATCH] Fix Configure Submodule Checkout on Windows If doing a default build on Windows with `configure` in the Visual Studio Developer Command Prompt and no git installed on the PATH, the configure script's `which` function will erroneously report there is a git command available and try, but fatally fail, to use git to get the commit hash needed for RapidJSON. which is erroneous because it is using `-x`, which seems to return true for directories on Windows. There is a `Git` directory in the PATH that Visual Studio adds that it's picking up. As a side note this actually has a working git command in it, but since it's not on the PATH I'm not sure if we should try to take advantage of it. --- configure | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 4d02defee4f..4d425a815d4 100755 --- a/configure +++ b/configure @@ -398,15 +398,24 @@ my %specific = 'refpost' => '}', 'comment' => '#') ); +sub might_be_executable { + my $path = shift; + return -x $path && -f $path; # On Windows -x can return true for directories +} + sub which { my $file = shift; for my $p (File::Spec->path()) { next if $p eq '.'; - if (-x "$p/$file") { - return "$p/$file"; - } - elsif ($exeext ne '' && -x "$p/$file$exeext") { - return "$p/$file$exeext"; + my $path = "$p/$file"; + if (might_be_executable($path)) { + return $path; + } + elsif ($exeext ne '') { + $path .= $exeext; + if (might_be_executable($path)) { + return $path; + } } } return undef; @@ -470,7 +479,7 @@ sub git_submodule_prop { or die("git_submodule_prop open failed: $!\nStopped"); my $prop_value = <$fd>; close($fd); - chomp($prop_value); + chomp($prop_value) if (defined($prop_value)); if (!$prop_value) { die("Couldn't get $full_prop_name from .gitmodules\nStopped"); }