Skip to content

Windows related changes, ahead/behind only current branch #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,11 @@ function getFileModificationHistory(): array {
{
$path = escapeshellarg( $path );
$branch = trim( `git -C $path rev-parse --abbrev-ref HEAD` );
$branch = $branch == "master" ? "" : " (branch $branch)";
$suffix = $branch == "master" ? "" : " (branch $branch)";
$output .= str_pad( "$name:" , 10 );
$output .= rtrim( `git -C $path rev-parse HEAD` ?? "" ) . "$branch\n";
$output .= rtrim( `git -C $path rev-parse HEAD` ?? "" ) . "$suffix ";
$output .= rtrim( `git -C $path for-each-ref --format="%(push:track)" refs/heads/$branch` ?? "" ) . "\n";
$output .= rtrim( `git -C $path status -s` ?? "" ) . "\n";
$output .= rtrim( `git -C $path for-each-ref --format="%(push:track)" refs/heads` ?? "" ) . "\n";
}
while( str_contains( $output , "\n\n" ) )
$output = str_replace( "\n\n" , "\n" , $output );
Expand Down
1 change: 1 addition & 0 deletions languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function __construct
, public string $path = "" )
{
$this->path = realpath( __DIR__ . '/..' ) . "/{$code}";
$this->path = str_replace( "\\" , '/' , $this->path );
}
}

Expand Down
102 changes: 33 additions & 69 deletions scripts/file-entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

# Description

This script creates various "file entities", that is, antities and files
that define DTD <!ENTITY name SYSTEM 'path'>, named and composed of:
This script creates various "file entities", that is, DTD entities that
points to files and file listings, named and composed of:

- dir.dir.file : pulls in a dir/dir/file.xml file
- dir.dif.entities.dir : pulls in a entity list for dir/dir/dir/*.xml
- dir.dif.entities.dir : pulls in all files of dir/dir/dir/*.xml

In the original file-entities.php.in, the files are created at:

Expand All @@ -44,7 +44,8 @@
so it would be possible to detect accidental overwriting of structural
entities, the "list of entities" moved to/as normal entity text. PS: This
will NOT work, with libxml recusing to load .manuxal.xml.in because of an
"Detected an entity reference loop", that does not exist. Sigh.
"Detected an entity reference loop", that does not exist. Sigh. PPS: May
be possible with LIBXML_PARSEHUGE after all.

*/

Expand All @@ -60,7 +61,7 @@

// Usage

$root = realpath( __DIR__ . "/../.." );
$root = realpain( __DIR__ . "/../.." );
$lang = "";
$chmonly = false;
$debug = false;
Expand Down Expand Up @@ -93,16 +94,15 @@
if ( $lang != "" )
generate_file_entities( $root , $lang );

pushEntity( "global.function-index", path: realpath( __DIR__ . "/.." ) . "/funcindex.xml" );
// TODO BACKPORT: Fixed relative path, move this directly into manual.xml.in
pushEntity( "global.function-index", path: realpain( __DIR__ . "/.." ) . "/funcindex.xml" );

if ( ! $chmonly )
foreach( $entities as $ent )
if ( str_starts_with( $ent->name , "chmonly." ) )
$ent->path = '';

$outfile = __DIR__ . "/../temp/file-entities.ent";
touch( $outfile );
$outfile = realpath( $outfile );
$outfile = realpain( __DIR__ . "/../temp/file-entities.ent" , touch: true );

$file = fopen( $outfile , "w" );
if ( ! $file )
Expand Down Expand Up @@ -149,48 +149,12 @@ function pushEntity( string $name , string $text = '' , string $path = '' )
echo "Something went wrong on file-entities.php.\n";
exit(-1);
}

if ( DIRECTORY_SEPARATOR == '/' )
return;

// While https://github.com/php/doc-en/pull/4288 is not
// replicated on on all languages, let's sleeping dogs lies

$marks = ['!','@','#'];
$parts = explode( '.' , $name );
foreach( $parts as & $part )
if ( strtolower( $part ) == 'pdo' )
$part = array_shift( $marks );

$mixin = implode( '.' , $parts );
$l1 = ['pdo','PDO'];
$l2 = ['pdo','PDO'];
$l3 = ['pdo','PDO'];

if ( str_contains( $mixin , '!' ) )
{
//echo "\n\n$mixin\n";
foreach( $l1 as $s1 )
foreach( $l2 as $s2 )
foreach( $l3 as $s3 )
{
$tmp = $mixin;
$tmp = str_replace( '!' , $s1 , $tmp );
$tmp = str_replace( '@' , $s2 , $tmp );
$tmp = str_replace( '#' , $s3 , $tmp );
//echo "$tmp\n";

$ent = new Entity( $tmp , $text , $path );
$entities[ $tmp ] = $ent;
}
//echo "\n";
}
}

function generate_file_entities( string $root , string $lang )
{
$path = "$root/$lang";
$test = realpath( $path );
$test = realpain( $path );
if ( $test === false || is_dir( $path ) == false )
{
echo "Language directory not found: $path\n.";
Expand Down Expand Up @@ -242,7 +206,7 @@ function file_entities_recurse( string $langroot , array $dirs )
function generate_list_entities( string $root , string $lang )
{
$path = "$root/$lang";
$test = realpath( $path );
$test = realpain( $path );
if ( $test === false || is_dir( $path ) == false )
{
echo "Language directory not found: $path\n.";
Expand Down Expand Up @@ -292,26 +256,6 @@ function list_entities_recurse( string $root , array $dirs )
}
ksort( $list );

// The entity file names collected on
//
// doc-lang/reference/apache/functions
//
// generate an entity named
//
// reference.apache.ENTITIES.functions
//
// that is saved on parent directory, with filename
//
// doc-lang/reference/apache/ENTITIES.functions.xml
//
// new style has the files saved as
//
// doc-base/temp/file-entities.reference.apache.functions.ent
//
// and in a far future, may only outputs: (see doc-base PR 183)
//
// doc-base/temp/file-entities.xml

$copy = $dirs;
$last = array_pop( $copy );
$copy[] = "entities";
Expand All @@ -322,15 +266,15 @@ function list_entities_recurse( string $root , array $dirs )

if ( $text != "" )
{
// pushEntity( $name , text: $text ); // See TODO item 2
// pushEntity( $name , text: $text ); // See TODO item 2 // LIBXML_PARSEHUGE

if ( BACKPORT )
$path = "$dir/../entities.$last.xml";
else
$path = __DIR__ . "/../temp/file-entities." . implode( '.' , $dirs ) . ".ent";

file_put_contents( $path , $text );
$path = realpath( $path );
$path = realpain( $path );
pushEntity( $name , path: $path );
}

Expand Down Expand Up @@ -365,3 +309,23 @@ function writeEntity( $file , Entity $ent )

fwrite( $file , $line );
}

function realpain( string $path , bool $touch = false ) : string
{
// pain is real

// care for external XML tools (realpath everywhere)
// care for Windows builds (foward slashes everywhere)
// avoid `cd` and chdir() like the plague

$path = str_replace( "\\" , '/' , $path );
if ( $touch && ! file_exists( $path ) )
touch( $path );

$res = realpath( $path );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why you first replace backward slashes with forward slashes, and later call realpath() which will reintroduce the backslashes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because realpath( "C:\phpdoc\en" ) will fail on Windows, I know that is because escaping and not directly related with realpath, but it really frustrating to have some literal "file part" sometimes behaving differently.

And to avoid code end looking like this:

const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot test ir now (soon starting some new year holidays), but I vaguely remember that libxml will accept foward slashes on Windows, backward slashes, but not mixed slashes, e.g., C:\phpdoc/en.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yeah, you can usually just use forward slashes on Windows. But I still don't understand why you first replace backward slashes with forward slashes, and later call realpath() which will reintroduce the backslashes. I mean that has nothing to do with literal file paths, nor with mixing forward and backward slashes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have to test again, without this PR, to see exactly what was broken. I think there is something git related, as this function was copied from languages.php, that does a lot of git invocations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remembered now. realpath() does not reintroduces foward slashes in all cases. It's not even guaranteed to return string. This function is called for expected non existent files, where realpath() returns bool, and I was under impression that this may fails on Windows, and at the time (as now) it's difficult for me to access Windows boxes to make tests. Yet. I remembered that forwards slashes always worked.

Also, these is some evidence this was the norm on doc-base scripts. xml-check.php does it, and I remember that previous file-entities.php there is a lot oft this too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$realpath = str_replace('\\', '/', realpath($_SERVER["argv"][1]));

That code calls realpath() and afterwards replaces the backslashes with forward slashes. That can make sense. Even if the file does not exists, you get false and the str_replace() will return an empty string. Even that might make sense.

I still fail to understand, why you first replace forward slashes with backward slashes, and then call realpath() which will always use backward slashes on Windows (unless the file does not exist, in which case the given filepath will be returned with forward slashes). Maybe you want something like this:

{
    if ( $touch && ! file_exists( $path ) )
        touch( $path );

    $res = realpath( $path );
    if ($res !== false)
        $path = $res;

    return str_replace( "\\" , '/' , $path );
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still fail to understand, why you first replace forward slashes with backward slashes

To avoid mixed slashes (C:\phpdoc/en) when realpath() fails. All backwards, all fowards, never mixed.

and then call realpath() which will always use backward slashes on Windows

The "foward slashes everywhere" refers to using foward slashes everywhere in source code. Having all slashes being foward on Windows when used (replaced), is better for compatibility.

That said, I will remove this line.

if ( is_string( $res ) )
$path = $res;

return $path;
}

Loading