Skip to content

Commit ffa8870

Browse files
authored
Idempotent build: manual.xml.in (#210)
1 parent c6be704 commit ffa8870

File tree

4 files changed

+96
-50
lines changed

4 files changed

+96
-50
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Files generated by the configure script
22
.manual.xml
33
.revcheck.json
4-
manual.xml
54
version.xml
65
sources.xml
76
# File use to generate entities by configure script

chm/manual.chm.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<book xml:id="chmonly">
2+
<title>&CHMEdition;</title>
3+
&chmonly.aboutchm;
4+
&chmonly.usingchm;
5+
&chmonly.search;
6+
&chmonly.integration;
7+
</book>

configure.php

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727

2828
echo "configure.php on PHP " . phpversion() . "\n\n";
2929

30+
// init_argv()
31+
// init_checks()
32+
// init_clean()
33+
// xml_configure()
34+
// xml_parse()
35+
// xml_xinclude()
36+
// xml_validate()
37+
// phd_sources()
38+
// phd_version()
39+
// php_history()
40+
3041
const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR;
3142
const RNG_SCHEMA_FILE = RNG_SCHEMA_DIR . 'docbook.rng';
3243
const RNG_SCHEMA_XINCLUDE_FILE = RNG_SCHEMA_DIR . 'docbookxi.rng';
@@ -81,6 +92,29 @@ function usage() // {{{
8192
HELPCHUNK;
8293
} // }}}
8394

95+
function realpain( string $path , bool $touch = false , bool $mkdir = false ) : string
96+
{
97+
// pain is real
98+
99+
// care for external XML tools (realpath() everywhere)
100+
// care for Windows builds (foward slashes everywhere)
101+
// avoid `cd` and chdir() like the plague
102+
103+
$path = str_replace( "\\" , '/' , $path );
104+
105+
if ( $mkdir && ! file_exists( $path ) )
106+
mkdir( $path , recursive: true );
107+
108+
if ( $touch && ! file_exists( $path ) )
109+
touch( $path );
110+
111+
$res = realpath( $path );
112+
if ( is_string( $res ) )
113+
$path = $res;
114+
115+
return $path;
116+
}
117+
84118
function errbox($msg) {
85119
$len = strlen($msg)+4;
86120
$line = "+" . str_repeat("-", $len) . "+";
@@ -251,7 +285,7 @@ function generate_sources_file() // {{{
251285
echo 'Iterating over files for sources info... ';
252286
$en_dir = "{$ac['rootdir']}/{$ac['EN_DIR']}";
253287
$source_langs = array(
254-
array('base', $ac['srcdir'], array('manual.xml.in', 'funcindex.xml')),
288+
array('base', $ac['srcdir'], array('manual.xml', 'funcindex.xml')),
255289
array('en', $en_dir, find_xml_files($en_dir)),
256290
);
257291
if ($ac['LANG'] !== 'en') {
@@ -630,12 +664,6 @@ function getFileModificationHistory(): array {
630664
}
631665

632666

633-
// We shouldn't be globbing for this. autoconf requires you to tell it which files to use, we should do the same
634-
// Notice how doing it this way results in generating less than half as many files.
635-
$infiles = array(
636-
'manual.xml.in',
637-
);
638-
639667
// Show local repository status to facilitate debug
640668

641669
$repos = array();
@@ -659,19 +687,45 @@ function getFileModificationHistory(): array {
659687
$output = str_replace( "\n\n" , "\n" , $output );
660688
echo "\n" , trim( $output ) . "\n\n";
661689

662-
foreach ($infiles as $in) {
663-
$in = chop("{$ac['basedir']}/{$in}");
664690

665-
$out = substr($in, 0, -3);
666-
echo "Generating {$out}... ";
667-
if (generate_output_file($in, $out, $ac)) {
668-
echo "done\n";
669-
} else {
670-
echo "fail\n";
671-
errors_are_bad(117);
691+
xml_configure();
692+
function xml_configure()
693+
{
694+
global $ac;
695+
$lang = $ac["LANG"];
696+
$conf = [];
697+
698+
$conf[] = "<!ENTITY LANG '$lang'>";
699+
700+
if ( $lang == 'en' )
701+
{
702+
realpain( __DIR__ . "/temp/empty" , touch: true );
703+
$trans1 = realpain( __DIR__ . "/temp/empty" );
704+
$trans2 = realpain( __DIR__ . "/temp/empty" );
705+
$trans3 = realpain( __DIR__ . "/temp/empty" );
706+
}
707+
else
708+
{
709+
$trans1 = realpain( __DIR__ . "/../$lang/language-defs.ent" );
710+
$trans2 = realpain( __DIR__ . "/../$lang/language-snippets.ent" );
711+
$trans3 = realpain( __DIR__ . "/../$lang/extensions.ent" );
672712
}
713+
$conf[] = "<!ENTITY % translation-defs SYSTEM '$trans1'>";
714+
$conf[] = "<!ENTITY % translation-snippets SYSTEM '$trans2'>";
715+
$conf[] = "<!ENTITY % translation-extensions SYSTEM '$trans3'>";
716+
717+
if ( $ac['CHMENABLED'] == 'yes' )
718+
{
719+
$chmpath = realpain( __DIR__ . "/chm/manual.chm.xml" );
720+
$conf[] = "<!ENTITY manual.chmonly SYSTEM '$chmpath'>";
721+
}
722+
else
723+
$conf[] = "<!ENTITY manual.chmonly ''>";
724+
725+
file_put_contents( __DIR__ . "/temp/manual.conf" , implode( "\n" , $conf ) );
673726
}
674727

728+
675729
if ($ac['SEGFAULT_ERROR'] === 'yes') {
676730
libxml_use_internal_errors(true);
677731
}

manual.xml.in renamed to manual.xml

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
1-
<?xml version='1.0' encoding='@ENCODING@' ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE PHPDOC [
3-
<!-- Add translated specific definitions and snippets -->
4-
@TRANSLATION_ONLY_INCL_BEGIN@
5-
<!ENTITY % language-defs SYSTEM "../@LANGDIR@/language-defs.ent">
6-
<!ENTITY % language-snippets SYSTEM "../@LANGDIR@/language-snippets.ent">
7-
<!ENTITY % extensions SYSTEM "../@LANGDIR@/extensions.ent">
8-
9-
%language-defs;
10-
%extensions;
11-
%language-snippets;
12-
@TRANSLATION_ONLY_INCL_END@
13-
14-
<!-- Fallback to English definitions and snippets (in case of missing translation) -->
15-
<!ENTITY % language-defs.default SYSTEM "../@EN_DIR@/language-defs.ent">
16-
<!ENTITY % language-snippets.default SYSTEM "../@EN_DIR@/language-snippets.ent">
17-
<!ENTITY % extensions.default SYSTEM "../@EN_DIR@/extensions.ent">
183

4+
<!-- Parameter entities used to configure manual.xml -->
5+
<!ENTITY % configure SYSTEM "./temp/manual.conf">
6+
%configure;
7+
8+
<!-- Translation layer, if any -->
9+
%translation-defs;
10+
%translation-snippets;
11+
%translation-extensions;
12+
13+
<!-- English manual (also works as fallback layer for incomplete translations) -->
14+
<!ENTITY % language-defs.default SYSTEM "../en/language-defs.ent">
15+
<!ENTITY % language-snippets.default SYSTEM "../en/language-snippets.ent">
16+
<!ENTITY % extensions.default SYSTEM "../en/extensions.ent">
1917
%language-defs.default;
2018
%extensions.default;
2119
%language-snippets.default;
2220

23-
<!-- All global entities for the XML files -->
24-
<!ENTITY % global.entities SYSTEM "./entities/global.ent">
25-
26-
<!-- These are language independent -->
27-
<!ENTITY % frontpage.entities SYSTEM "../@EN_DIR@/contributors.ent">
21+
<!-- Language independent entities, and language dependent file entities -->
22+
<!ENTITY % global.entities SYSTEM "./entities/global.ent">
23+
<!ENTITY % frontpage.entities SYSTEM "../en/contributors.ent">
2824
<!ENTITY % file.entities SYSTEM "./temp/file-entities.ent">
29-
30-
<!-- Include all external DTD parts defined previously -->
3125
%global.entities;
3226
%file.entities;
3327
%frontpage.entities;
3428
]>
3529

36-
<set xmlns="http://docbook.org/ns/docbook" version="5.2" xml:id="index" xml:lang="@LANG@" xmlns:xlink="http://www.w3.org/1999/xlink">
30+
<set xmlns="http://docbook.org/ns/docbook" version="5.2" xml:id="index" xml:lang="&LANG;" xmlns:xlink="http://www.w3.org/1999/xlink">
3731
<title>&PHPManual;</title>
3832
&bookinfo;
3933

@@ -465,15 +459,7 @@
465459
</appendix>
466460
</book>
467461

468-
@CHMONLY_INCL_BEGIN@
469-
<book xml:id="chmonly">
470-
<title>&CHMEdition;</title>
471-
&chmonly.aboutchm;
472-
&chmonly.usingchm;
473-
&chmonly.search;
474-
&chmonly.integration;
475-
</book>
476-
@CHMONLY_INCL_END@
462+
&manual.chmonly;
477463

478464
</set>
479465

0 commit comments

Comments
 (0)