Skip to content

Commit

Permalink
Remove backports, alert for insensitive file systems, and bundled fil…
Browse files Browse the repository at this point in the history
…e entity for directories (#213)

* Remove backport.
* Detect build breakage on case insensitive file systems
* Do not generate individual entity files for directories
* Setting documentURI cause fails on Windows
  • Loading branch information
alfsb authored Feb 3, 2025
1 parent b12b9bb commit a4884fb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 63 deletions.
7 changes: 2 additions & 5 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,7 @@ function xml_configure()
checking('whether to save an invalid .manual.xml');
checkvalue($ac['FORCE_DOM_SAVE']);


$dom = new DOMDocument();

function dom_load( DOMDocument $dom , string $filename ) : bool
function dom_load( DOMDocument $dom , string $filename , string $baseURI = "" ) : bool
{
$filename = realpath( $filename );
$options = LIBXML_NOENT | LIBXML_COMPACT | LIBXML_BIGLINES | LIBXML_PARSEHUGE;
Expand All @@ -849,6 +846,7 @@ function dom_saveload( DOMDocument $dom , string $filename = "" ) : string
}

echo "Loading and parsing {$ac["INPUT_FILENAME"]}... ";
$dom = new DOMDocument();

if ( dom_load( $dom , "{$ac['srcdir']}/{$ac["INPUT_FILENAME"]}" ) )
{
Expand All @@ -862,7 +860,6 @@ function dom_saveload( DOMDocument $dom , string $filename = "" ) : string
errors_are_bad(1);
}


echo "Running XInclude/XPointer... ";

$total = xinclude_run_byid( $dom );
Expand Down
94 changes: 36 additions & 58 deletions scripts/file-entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
This script creates various "file entities", that is, DTD entities that
point to files and file listings, named and composed of:
- dir.dir.file : pulls in a dir/dir/file.xml file
- dir.dir.file : pulls in a dir/dir/file.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 @@ -33,24 +33,8 @@
- doc-base/temp/file-entites.ent
- doc-base/temp/file-entites.dir.dir.ent
# TODO
1. Leave this running in new idempotent mode for a few months, before
erasing the const BACKPORT, that exists only to replicate the old
style build.
2. Istead of creating ~thousand doc-base/temp/file-entites.*.ent files,
output an solid XML grouped file (per github.com/php/doc-base/pull/183)
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. PPS: May
be possible with LIBXML_PARSEHUGE after all.
*/

const BACKPORT = false; // TODO remove, see above.

// Setup

ini_set( 'display_errors' , 1 );
Expand Down Expand Up @@ -86,15 +70,15 @@

echo "Creating file-entities.ent... ";

$entities = []; // See pushEntity()
$entities = [];
$mixedCase = [];

generate_file_entities( $root , "en" );
generate_list_entities( $root , "en" );

if ( $lang != "" )
generate_file_entities( $root , $lang );

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

if ( ! $chmonly )
Expand All @@ -113,13 +97,7 @@

fputs( $file , "<!-- DON'T TOUCH - AUTOGENERATED BY file-entities.php -->\n\n" );

if ( BACKPORT )
fputs( $file , "\n" );

if ( BACKPORT )
asort( $entities );
else
ksort( $entities );
ksort( $entities );

foreach ( $entities as $ent )
writeEntity( $file , $ent );
Expand All @@ -138,6 +116,7 @@ function __construct( public string $name , public string $text , public string
function pushEntity( string $name , string $text = '' , string $path = '' )
{
global $entities;
global $mixedCase;

$name = str_replace( '_' , '-' , $name );
$path = str_replace( '\\' , '/' , $path );
Expand All @@ -147,8 +126,25 @@ function pushEntity( string $name , string $text = '' , string $path = '' )
if ( ( $text == "" && $path == "" ) || ( $text != "" && $path != "" ) )
{
echo "Something went wrong on file-entities.php.\n";
exit(-1);
exit( 1 );
}

$lname = strtolower( $name );
if ( isset( $mixedCase[ $lname ] ) && $mixedCase[ $lname ] != $name )
{
echo "\n\n";
echo "BROKEN BUILD on case insensitive file systems!\n";
echo "Detected distinct file entities only by case:\n";
echo " - {$mixedCase[ $lname ]}\n";
echo " - $name \n";
echo "This will PERMANENTLY BRICK manual build on Windows machines!\n";
echo "Avoid committing this on repository, and if it's already committed,\n";
echo "revert and send a heads up on mailinst how to fix the issue.\n\n";
echo "See https://github.com/php/doc-en/pull/4330#issuecomment-2557306828";
echo "\n\n";
exit( 1 );
}
$mixedCase[ $lname ] = $name;
}

function generate_file_entities( string $root , string $lang )
Expand All @@ -158,7 +154,7 @@ function generate_file_entities( string $root , string $lang )
if ( $test === false || is_dir( $path ) == false )
{
echo "Language directory not found: $path\n.";
exit(-1);
exit( 1 );
}
$path = $test;

Expand Down Expand Up @@ -210,13 +206,10 @@ function generate_list_entities( string $root , string $lang )
if ( $test === false || is_dir( $path ) == false )
{
echo "Language directory not found: $path\n.";
exit(-1);
exit( 1 );
}
$path = $test;

if ( BACKPORT ) // Spurious file generated outside reference/
pushEntity( "language.predefined.entities.weakreference", path: "$root/$lang/language/predefined/entities.weakreference.xml" );

$dirs = [ "reference" ];
list_entities_recurse( $path , $dirs );
}
Expand All @@ -235,8 +228,6 @@ function list_entities_recurse( string $root , array $dirs )
continue;
if ( $file[0] == "." )
continue;
if ( BACKPORT && str_starts_with( $file , "entities.") )
continue;

$path = "$dir/$file";

Expand Down Expand Up @@ -265,18 +256,15 @@ function list_entities_recurse( string $root , array $dirs )
$text = implode( "\n" , $list );

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

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

file_put_contents( $path , $text );
$path = realpain( $path );
pushEntity( $name , path: $path );
}
// Old style, pre LIBXML_PARSEHUGE, "directory" entity as external file
//
// $path = __DIR__ . "/../temp/file-entities." . implode( '.' , $dirs ) . ".ent";
// file_put_contents( $path , $text );
// $path = realpain( $path );
// pushEntity( $name , path: $path );
//

foreach( $subdirs as $subdir )
{
Expand All @@ -292,20 +280,10 @@ function writeEntity( $file , Entity $ent )
$text = $ent->text;
$path = $ent->path;

if ( BACKPORT )
{
if ( $path == "" )
$line = sprintf("<!ENTITY %-40s ''>\n" , $name ); // was on original, possibly unused
else
$line = sprintf("<!ENTITY %-40s SYSTEM 'file:///%s'>\n" , $name , $path );
}
if ( $path == "" )
$line = "<!ENTITY $name '$text'>\n";
else
{
if ( $path == "" )
$line = "<!ENTITY $name '$text'>\n";
else
$line = "<!ENTITY $name SYSTEM '$path'>\n";
}
$line = "<!ENTITY $name SYSTEM '$path'>\n";

fwrite( $file , $line );
}
Expand Down

0 comments on commit a4884fb

Please sign in to comment.