Skip to content

Commit

Permalink
Idempotent build: manual.xml.in (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfsb authored Jan 20, 2025
1 parent c6be704 commit ffa8870
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 50 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Files generated by the configure script
.manual.xml
.revcheck.json
manual.xml
version.xml
sources.xml
# File use to generate entities by configure script
Expand Down
7 changes: 7 additions & 0 deletions chm/manual.chm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<book xml:id="chmonly">
<title>&CHMEdition;</title>
&chmonly.aboutchm;
&chmonly.usingchm;
&chmonly.search;
&chmonly.integration;
</book>
86 changes: 70 additions & 16 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@

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

// init_argv()
// init_checks()
// init_clean()
// xml_configure()
// xml_parse()
// xml_xinclude()
// xml_validate()
// phd_sources()
// phd_version()
// php_history()

const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR;
const RNG_SCHEMA_FILE = RNG_SCHEMA_DIR . 'docbook.rng';
const RNG_SCHEMA_XINCLUDE_FILE = RNG_SCHEMA_DIR . 'docbookxi.rng';
Expand Down Expand Up @@ -81,6 +92,29 @@ function usage() // {{{
HELPCHUNK;
} // }}}

function realpain( string $path , bool $touch = false , bool $mkdir = 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 ( $mkdir && ! file_exists( $path ) )
mkdir( $path , recursive: true );

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

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

return $path;
}

function errbox($msg) {
$len = strlen($msg)+4;
$line = "+" . str_repeat("-", $len) . "+";
Expand Down Expand Up @@ -251,7 +285,7 @@ function generate_sources_file() // {{{
echo 'Iterating over files for sources info... ';
$en_dir = "{$ac['rootdir']}/{$ac['EN_DIR']}";
$source_langs = array(
array('base', $ac['srcdir'], array('manual.xml.in', 'funcindex.xml')),
array('base', $ac['srcdir'], array('manual.xml', 'funcindex.xml')),
array('en', $en_dir, find_xml_files($en_dir)),
);
if ($ac['LANG'] !== 'en') {
Expand Down Expand Up @@ -630,12 +664,6 @@ function getFileModificationHistory(): array {
}


// We shouldn't be globbing for this. autoconf requires you to tell it which files to use, we should do the same
// Notice how doing it this way results in generating less than half as many files.
$infiles = array(
'manual.xml.in',
);

// Show local repository status to facilitate debug

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

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

$out = substr($in, 0, -3);
echo "Generating {$out}... ";
if (generate_output_file($in, $out, $ac)) {
echo "done\n";
} else {
echo "fail\n";
errors_are_bad(117);
xml_configure();
function xml_configure()
{
global $ac;
$lang = $ac["LANG"];
$conf = [];

$conf[] = "<!ENTITY LANG '$lang'>";

if ( $lang == 'en' )
{
realpain( __DIR__ . "/temp/empty" , touch: true );
$trans1 = realpain( __DIR__ . "/temp/empty" );
$trans2 = realpain( __DIR__ . "/temp/empty" );
$trans3 = realpain( __DIR__ . "/temp/empty" );
}
else
{
$trans1 = realpain( __DIR__ . "/../$lang/language-defs.ent" );
$trans2 = realpain( __DIR__ . "/../$lang/language-snippets.ent" );
$trans3 = realpain( __DIR__ . "/../$lang/extensions.ent" );
}
$conf[] = "<!ENTITY % translation-defs SYSTEM '$trans1'>";
$conf[] = "<!ENTITY % translation-snippets SYSTEM '$trans2'>";
$conf[] = "<!ENTITY % translation-extensions SYSTEM '$trans3'>";

if ( $ac['CHMENABLED'] == 'yes' )
{
$chmpath = realpain( __DIR__ . "/chm/manual.chm.xml" );
$conf[] = "<!ENTITY manual.chmonly SYSTEM '$chmpath'>";
}
else
$conf[] = "<!ENTITY manual.chmonly ''>";

file_put_contents( __DIR__ . "/temp/manual.conf" , implode( "\n" , $conf ) );
}


if ($ac['SEGFAULT_ERROR'] === 'yes') {
libxml_use_internal_errors(true);
}
Expand Down
52 changes: 19 additions & 33 deletions manual.xml.in → manual.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
<?xml version='1.0' encoding='@ENCODING@' ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE PHPDOC [
<!-- Add translated specific definitions and snippets -->
@TRANSLATION_ONLY_INCL_BEGIN@
<!ENTITY % language-defs SYSTEM "../@LANGDIR@/language-defs.ent">
<!ENTITY % language-snippets SYSTEM "../@LANGDIR@/language-snippets.ent">
<!ENTITY % extensions SYSTEM "../@LANGDIR@/extensions.ent">

%language-defs;
%extensions;
%language-snippets;
@TRANSLATION_ONLY_INCL_END@

<!-- Fallback to English definitions and snippets (in case of missing translation) -->
<!ENTITY % language-defs.default SYSTEM "../@EN_DIR@/language-defs.ent">
<!ENTITY % language-snippets.default SYSTEM "../@EN_DIR@/language-snippets.ent">
<!ENTITY % extensions.default SYSTEM "../@EN_DIR@/extensions.ent">

<!-- Parameter entities used to configure manual.xml -->
<!ENTITY % configure SYSTEM "./temp/manual.conf">
%configure;

<!-- Translation layer, if any -->
%translation-defs;
%translation-snippets;
%translation-extensions;

<!-- English manual (also works as fallback layer for incomplete translations) -->
<!ENTITY % language-defs.default SYSTEM "../en/language-defs.ent">
<!ENTITY % language-snippets.default SYSTEM "../en/language-snippets.ent">
<!ENTITY % extensions.default SYSTEM "../en/extensions.ent">
%language-defs.default;
%extensions.default;
%language-snippets.default;

<!-- All global entities for the XML files -->
<!ENTITY % global.entities SYSTEM "./entities/global.ent">

<!-- These are language independent -->
<!ENTITY % frontpage.entities SYSTEM "../@EN_DIR@/contributors.ent">
<!-- Language independent entities, and language dependent file entities -->
<!ENTITY % global.entities SYSTEM "./entities/global.ent">
<!ENTITY % frontpage.entities SYSTEM "../en/contributors.ent">
<!ENTITY % file.entities SYSTEM "./temp/file-entities.ent">

<!-- Include all external DTD parts defined previously -->
%global.entities;
%file.entities;
%frontpage.entities;
]>

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

Expand Down Expand Up @@ -465,15 +459,7 @@
</appendix>
</book>

@CHMONLY_INCL_BEGIN@
<book xml:id="chmonly">
<title>&CHMEdition;</title>
&chmonly.aboutchm;
&chmonly.usingchm;
&chmonly.search;
&chmonly.integration;
</book>
@CHMONLY_INCL_END@
&manual.chmonly;

</set>

Expand Down

0 comments on commit ffa8870

Please sign in to comment.