20
20
This script creates various "file entities", that is, DTD entities that
21
21
point to files and file listings, named and composed of:
22
22
23
- - dir.dir.file : pulls in a dir/dir/file.xml file
23
+ - dir.dir.file : pulls in a dir/dir/file.xml
24
24
- dir.dif.entities.dir : pulls in all files of dir/dir/dir/*.xml
25
25
26
26
In the original file-entities.php.in, the files are created at:
33
33
- doc-base/temp/file-entites.ent
34
34
- doc-base/temp/file-entites.dir.dir.ent
35
35
36
- # TODO
37
-
38
- 1. Leave this running in new idempotent mode for a few months, before
39
- erasing the const BACKPORT, that exists only to replicate the old
40
- style build.
41
-
42
- 2. Istead of creating ~thousand doc-base/temp/file-entites.*.ent files,
43
- output an solid XML grouped file (per github.com/php/doc-base/pull/183)
44
- so it would be possible to detect accidental overwriting of structural
45
- entities, the "list of entities" moved to/as normal entity text. PS: This
46
- will NOT work, with libxml recusing to load .manuxal.xml.in because of an
47
- "Detected an entity reference loop", that does not exist. Sigh. PPS: May
48
- be possible with LIBXML_PARSEHUGE after all.
49
-
50
36
*/
51
37
52
- const BACKPORT = false ; // TODO remove, see above.
53
-
54
38
// Setup
55
39
56
40
ini_set ( 'display_errors ' , 1 );
86
70
87
71
echo "Creating file-entities.ent... " ;
88
72
89
- $ entities = []; // See pushEntity()
73
+ $ entities = [];
74
+ $ mixedCase = [];
90
75
91
76
generate_file_entities ( $ root , "en " );
92
77
generate_list_entities ( $ root , "en " );
93
78
94
79
if ( $ lang != "" )
95
80
generate_file_entities ( $ root , $ lang );
96
81
97
- // TODO BACKPORT: Fixed relative path, move this directly into manual.xml.in
98
82
pushEntity ( "global.function-index " , path: realpain ( __DIR__ . "/.. " ) . "/funcindex.xml " );
99
83
100
84
if ( ! $ chmonly )
113
97
114
98
fputs ( $ file , "<!-- DON'T TOUCH - AUTOGENERATED BY file-entities.php --> \n\n" );
115
99
116
- if ( BACKPORT )
117
- fputs ( $ file , "\n" );
118
-
119
- if ( BACKPORT )
120
- asort ( $ entities );
121
- else
122
- ksort ( $ entities );
100
+ ksort ( $ entities );
123
101
124
102
foreach ( $ entities as $ ent )
125
103
writeEntity ( $ file , $ ent );
@@ -138,6 +116,7 @@ function __construct( public string $name , public string $text , public string
138
116
function pushEntity ( string $ name , string $ text = '' , string $ path = '' )
139
117
{
140
118
global $ entities ;
119
+ global $ mixedCase ;
141
120
142
121
$ name = str_replace ( '_ ' , '- ' , $ name );
143
122
$ path = str_replace ( '\\' , '/ ' , $ path );
@@ -147,8 +126,25 @@ function pushEntity( string $name , string $text = '' , string $path = '' )
147
126
if ( ( $ text == "" && $ path == "" ) || ( $ text != "" && $ path != "" ) )
148
127
{
149
128
echo "Something went wrong on file-entities.php. \n" ;
150
- exit (- 1 );
129
+ exit ( 1 );
151
130
}
131
+
132
+ $ lname = strtolower ( $ name );
133
+ if ( isset ( $ mixedCase [ $ lname ] ) && $ mixedCase [ $ lname ] != $ name )
134
+ {
135
+ echo "\n\n" ;
136
+ echo "BROKEN BUILD on case insensitive file systems! \n" ;
137
+ echo "Detected distinct file entities only by case: \n" ;
138
+ echo " - {$ mixedCase [ $ lname ]}\n" ;
139
+ echo " - $ name \n" ;
140
+ echo "This will PERMANENTLY BRICK manual build on Windows machines! \n" ;
141
+ echo "Avoid committing this on repository, and if it's already committed, \n" ;
142
+ echo "revert and send a heads up on mailinst how to fix the issue. \n\n" ;
143
+ echo "See https://github.com/php/doc-en/pull/4330#issuecomment-2557306828 " ;
144
+ echo "\n\n" ;
145
+ exit ( 1 );
146
+ }
147
+ $ mixedCase [ $ lname ] = $ name ;
152
148
}
153
149
154
150
function generate_file_entities ( string $ root , string $ lang )
@@ -158,7 +154,7 @@ function generate_file_entities( string $root , string $lang )
158
154
if ( $ test === false || is_dir ( $ path ) == false )
159
155
{
160
156
echo "Language directory not found: $ path \n. " ;
161
- exit (- 1 );
157
+ exit ( 1 );
162
158
}
163
159
$ path = $ test ;
164
160
@@ -210,13 +206,10 @@ function generate_list_entities( string $root , string $lang )
210
206
if ( $ test === false || is_dir ( $ path ) == false )
211
207
{
212
208
echo "Language directory not found: $ path \n. " ;
213
- exit (- 1 );
209
+ exit ( 1 );
214
210
}
215
211
$ path = $ test ;
216
212
217
- if ( BACKPORT ) // Spurious file generated outside reference/
218
- pushEntity ( "language.predefined.entities.weakreference " , path: "$ root/ $ lang/language/predefined/entities.weakreference.xml " );
219
-
220
213
$ dirs = [ "reference " ];
221
214
list_entities_recurse ( $ path , $ dirs );
222
215
}
@@ -235,8 +228,6 @@ function list_entities_recurse( string $root , array $dirs )
235
228
continue ;
236
229
if ( $ file [0 ] == ". " )
237
230
continue ;
238
- if ( BACKPORT && str_starts_with ( $ file , "entities. " ) )
239
- continue ;
240
231
241
232
$ path = "$ dir/ $ file " ;
242
233
@@ -265,18 +256,15 @@ function list_entities_recurse( string $root , array $dirs )
265
256
$ text = implode ( "\n" , $ list );
266
257
267
258
if ( $ text != "" )
268
- {
269
- // pushEntity( $name , text: $text ); // See TODO item 2 // LIBXML_PARSEHUGE
259
+ pushEntity ( $ name , text: $ text );
270
260
271
- if ( BACKPORT )
272
- $ path = "$ dir/../entities. $ last.xml " ;
273
- else
274
- $ path = __DIR__ . "/../temp/file-entities. " . implode ( '. ' , $ dirs ) . ".ent " ;
275
-
276
- file_put_contents ( $ path , $ text );
277
- $ path = realpain ( $ path );
278
- pushEntity ( $ name , path: $ path );
279
- }
261
+ // Old style, pre LIBXML_PARSEHUGE, "directory" entity as external file
262
+ //
263
+ // $path = __DIR__ . "/../temp/file-entities." . implode( '.' , $dirs ) . ".ent";
264
+ // file_put_contents( $path , $text );
265
+ // $path = realpain( $path );
266
+ // pushEntity( $name , path: $path );
267
+ //
280
268
281
269
foreach ( $ subdirs as $ subdir )
282
270
{
@@ -292,20 +280,10 @@ function writeEntity( $file , Entity $ent )
292
280
$ text = $ ent ->text ;
293
281
$ path = $ ent ->path ;
294
282
295
- if ( BACKPORT )
296
- {
297
- if ( $ path == "" )
298
- $ line = sprintf ("<!ENTITY %-40s ''> \n" , $ name ); // was on original, possibly unused
299
- else
300
- $ line = sprintf ("<!ENTITY %-40s SYSTEM 'file:///%s'> \n" , $ name , $ path );
301
- }
283
+ if ( $ path == "" )
284
+ $ line = "<!ENTITY $ name ' $ text'> \n" ;
302
285
else
303
- {
304
- if ( $ path == "" )
305
- $ line = "<!ENTITY $ name ' $ text'> \n" ;
306
- else
307
- $ line = "<!ENTITY $ name SYSTEM ' $ path'> \n" ;
308
- }
286
+ $ line = "<!ENTITY $ name SYSTEM ' $ path'> \n" ;
309
287
310
288
fwrite ( $ file , $ line );
311
289
}
0 commit comments