From 9f41b981666045041192645242916791798b5982 Mon Sep 17 00:00:00 2001 From: hakre Date: Tue, 1 Dec 2026 18:17:55 +0100 Subject: [PATCH] configure: replace git_clean() with scoped temp_clean() git_clean() unconditionally invoked Git, which fails in build environments that do not provide Git by default and the script stopped with the following diagnostic (shortened): configure.php on PHP 8.5.13, libxml 2.9.14 ... sh: 1: git: not found doc-base/temp clean up FAILED. The safety of 'git clean -fdx temp' comes from its scoping (only untracked files under temp/), not from Git itself. Replace it with a scoped filesystem cleanup using Recursive- IteratorIterator (CHILD_FIRST, SKIP_DOTS, no symlink following), preserving the committed temp/.gitkeep marker. On failure, emit a warning and continue instead of aborting the build, as suggested in review. git_status() had the same root cause without the crash: without Git it produced 6x "sh: git: not found" plus an empty listing, and with Git installed but Docker ADD-stripped .git directories (reproducible builds) it produced "fatal: not a git repository" plus the same empty listing. Fixed with an early `git --version` check (exec with 2>&1, keeping the shell error off the terminal) and a per-repo .git check. Cast shell_exec() results to string to silence trim(null) deprecations on PHP 8.5. --with-git is removed, following the preference expressed in review for a soft warning over a new configure option. --- configure.php | 77 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/configure.php b/configure.php index c18775d54e..63a6d54708 100755 --- a/configure.php +++ b/configure.php @@ -547,20 +547,54 @@ function is_single_language() : bool $ac["ONLYDIR"] = dirname(realpath($ac["GENERATE"])); } -git_clean(); // Idempotent clean up +checking("for temp/ being idempotent cleaned up"); +checkvalue(temp_clean() ? 'yes' : 'no'); + git_status(); // Show local repository status -function git_clean() +function temp_clean() : bool { - $dir = escapeshellarg( __DIR__ ); - $cmd = "git -C $dir clean temp -fdx --quiet"; - $ret = 0; - passthru( $cmd , $ret ); - if ( $ret != 0 ) + $temp = __DIR__ . '/temp'; + if ( !is_dir($temp) || is_link($temp) ) { + return false; + } + + $failed = []; + try { - echo "doc-base/temp clean up FAILED.\n"; - exit( 1 ); + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + $temp, + FilesystemIterator::SKIP_DOTS, + ), + RecursiveIteratorIterator::CHILD_FIRST, + ); + + foreach ($it as $path => $file) + { + if ( $it->getDepth() === 0 && $file->getFilename() === '.gitkeep' ) + continue; + $ok = ( $file->isLink() || $file->isFile() ) + ? @unlink($path) : @rmdir($path) ; + if ( !$ok ) + $failed[] = $path; + } + } + catch (Throwable $e) + { + $failed[] = "{$temp} ({$e->getMessage()})"; + } + + global $ac; + if ( $failed && $ac['quiet'] != 'yes' ) + { + echo "doc-base/temp clean up incomplete:\n"; + foreach ( $failed as $p ) + echo " could not remove: $p\n"; + echo "Build is not idempotent. Clean up temp/ manually and re-run.\n"; } + + return $failed === []; } function git_status() @@ -569,6 +603,10 @@ function git_status() if ( $ac['quiet'] == 'yes' ) return; + exec('git --version 2>&1' , $out , $ret); + if ( $ret !== 0 || empty($out) ) + return; + $repos = array(); $repos['doc-base'] = $ac['basedir']; $repos[$ac['LANG_BASE_DIR']] = "{$ac['rootdir']}/{$ac['LANG_BASE_DIR']}"; @@ -576,14 +614,19 @@ function git_status() $output = ""; foreach ( $repos as $name => $path ) - { - $path = escapeshellarg( $path ); - $branch = trim( shell_exec( "git -C $path rev-parse --abbrev-ref HEAD" )); - $branch = $branch == "master" ? "" : " (branch $branch)"; - $output .= str_pad( "$name:" , 10 ); - $output .= rtrim( shell_exec( "git -C $path rev-parse HEAD" ) ?? "" ) . $branch . "\n"; - $output .= rtrim( shell_exec( "git -C $path status -s") ?? "" ) . "\n"; - } + if ( file_exists( $path . '/.git' ) ) + { + $path = escapeshellarg( $path ); + $branch = trim( (string) shell_exec( "git -C $path rev-parse --abbrev-ref HEAD" )); + $branch = $branch == "master" ? "" : " (branch $branch)"; + $output .= str_pad( "$name:" , 10 ); + $output .= rtrim( (string) shell_exec( "git -C $path rev-parse HEAD" ) ) . $branch . "\n"; + $output .= rtrim( (string) shell_exec( "git -C $path status -s") ) . "\n"; + } + + if ( $output === "" ) + return; + while( str_contains( $output , "\n\n" ) ) $output = str_replace( "\n\n" , "\n" , $output ); echo "\n" , trim( $output ) . "\n\n";