Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 60 additions & 17 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -569,21 +603,30 @@ 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']}";
$repos[$ac['LANG']] = "{$ac['rootdir']}/{$ac['LANG']}";

$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";
Expand Down