From 4f3a4f73c4e973ede752bb02c0fe388bfe3edbe4 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 12 Oct 2021 09:44:26 +0200 Subject: [PATCH 1/2] improve CGI executable path detection for command prefix --- run-tests.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/run-tests.php b/run-tests.php index b45e4a4c576ea..eb129eeafaf77 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1057,11 +1057,14 @@ function get_binary(string $php, string $sapi, string $sapi_path): ?string if (IS_WINDOWS && file_exists("$dir/$sapi.exe")) { return realpath("$dir/$sapi.exe"); } + // Sources tree if (file_exists("$dir/../../$sapi_path")) { return realpath("$dir/../../$sapi_path"); } - if (file_exists("$dir/$sapi")) { - return realpath("$dir/$sapi"); + // Installation tree + $inst = str_replace('php', $sapi, basename($php)); + if (file_exists("$dir/$inst")) { + return realpath("$dir/$inst"); } return null; } From 5d45595540da846d276f5ee2be1aba88c05675ab Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 12 Oct 2021 10:19:54 +0200 Subject: [PATCH 2/2] handles more cases --- run-tests.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/run-tests.php b/run-tests.php index eb129eeafaf77..b3f66e7610960 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1062,7 +1062,14 @@ function get_binary(string $php, string $sapi, string $sapi_path): ?string return realpath("$dir/../../$sapi_path"); } // Installation tree - $inst = str_replace('php', $sapi, basename($php)); + $inst = basename($php); + if (preg_match('/.php$/', $inst)) { // Preserve command prefix + $inst = preg_replace('/php$/', $sapi, $inst); + } else if (preg_match('/^php./', $inst)) {// Preserve command suffix + $inst = preg_replace('/^php/', $sapi, $inst); + } else { + $inst = $sapi; + } if (file_exists("$dir/$inst")) { return realpath("$dir/$inst"); }