From af330b2ee153ccade053eecf2747ca08bd5b1750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Fri, 14 Mar 2025 10:17:39 -0300 Subject: [PATCH 1/7] Remove xinclude_debug_report(), as it become redundant --- configure.php | 60 +++++++++------------------------------------------ 1 file changed, 10 insertions(+), 50 deletions(-) diff --git a/configure.php b/configure.php index e5a42462f..3fa445091 100755 --- a/configure.php +++ b/configure.php @@ -950,20 +950,23 @@ function xinclude_run_xpointer( DOMDocument $dom ) : int function xinclude_residual_fixup( DOMDocument $dom ) { - xinclude_debug_report( $dom ); - // XInclude failures are soft errors on translations, so remove // residual XInclude tags on translations to keep them building. + $debugFile = "temp/xinclude-debug.xml"; + $debugPath = __DIR__ . "/{$debugFile}"; $nodes = xinclude_residual_list( $dom ); + if ( count( $nodes ) > 0 ) + dom_saveload( $dom , $debugPath ); // preserve state + $count = 0; $explain = false; foreach( $nodes as $node ) { if ( $count === 0 ) - echo "\nFailed XInclude:\n"; + echo "\nFailed XInclude, inspect {$debugFile} for context:\n"; echo " {$node->getAttribute("xpointer")}\n"; $count++; @@ -1057,50 +1060,6 @@ function xinclude_residual_list( DOMDocument $dom ) : DOMNodeList return $nodes; } -function xinclude_debug_report( DOMDocument $dom ) -{ - $debugFile = __DIR__ . "/temp/xinclude-debug.xml"; - - dom_saveload( $dom , $debugFile ); // preserve state - - libxml_clear_errors(); - $dom->xinclude(); - $errors = libxml_get_errors(); - libxml_clear_errors(); - - dom_saveload( $dom ); // normal output - - $count = 0; - $prefix = realpath( __DIR__ ); - - $prevLine = -1; - $prevClmn = -1; - - foreach( $errors as $error ) - { - $msg = $error->message; - $file = $error->file; - $line = $error->line; - $clmn = $error->column; - - $prevLine = $line; - $prevClmn = $clmn; - - $msg = rtrim( $msg ); - if ( str_starts_with( $file , $prefix ) ) - $file = substr( $file , strlen( $prefix ) + 1 ); - - if ( $count === 0 ) - echo "\n"; - - echo "[{$file} {$line}:{$clmn}] $msg\n"; - $count++; - } - - if ( $count === 0 ) - echo "\n"; -} - echo "Validating {$ac["INPUT_FILENAME"]}... "; if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{ @@ -1141,11 +1100,12 @@ function xinclude_debug_report( DOMDocument $dom ) exit(0); } // }}} -$mxml = $ac["OUTPUT_FILENAME"]; +// Saves and reload, so libxml's RelaxNG validation to work correctly -/* TODO: For some reason libxml does not validate the RelaxNG schema unless reloading the document in full */ -dom_saveload( $dom ); // idempotent path +$mxml = $ac["OUTPUT_FILENAME"]; $dom->save($mxml); // non idempotent, historical path +dom_saveload( $dom ); // idempotent path + if ($dom->relaxNGValidate(RNG_SCHEMA_FILE)) { echo "done.\n"; printf("\nAll good. Saved %s\n", basename($ac["OUTPUT_FILENAME"])); From 4be734d1b3fabc6ef616df0e1f46617729c872ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Fri, 14 Mar 2025 12:03:38 -0300 Subject: [PATCH 2/7] Move final messages to the end --- configure.php | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/configure.php b/configure.php index 3fa445091..f8f182b1b 100755 --- a/configure.php +++ b/configure.php @@ -1108,30 +1108,6 @@ function xinclude_residual_list( DOMDocument $dom ) : DOMNodeList if ($dom->relaxNGValidate(RNG_SCHEMA_FILE)) { echo "done.\n"; - printf("\nAll good. Saved %s\n", basename($ac["OUTPUT_FILENAME"])); - echo "All you have to do now is run 'phd -d {$mxml}'\n"; - echo "If the script hangs here, you can abort with ^C.\n"; - echo << Date: Fri, 14 Mar 2025 12:29:24 -0300 Subject: [PATCH 3/7] Move PhD history code to after XML validation --- configure.php | 81 +++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/configure.php b/configure.php index f8f182b1b..2fcf149a2 100755 --- a/configure.php +++ b/configure.php @@ -327,36 +327,6 @@ function generate_sources_file() // {{{ } } // }}} -function getFileModificationHistory(): array { - global $ac; - - $lang_mod_file = (($ac['LANG'] !== 'en') ? ("{$ac['rootdir']}/{$ac['EN_DIR']}") : ("{$ac['rootdir']}/{$ac['LANGDIR']}")) . "/fileModHistory.php"; - $doc_base_mod_file = __DIR__ . "/fileModHistory.php"; - - $history_file = null; - if (file_exists($lang_mod_file)) { - $history_file = include $lang_mod_file; - if (is_array($history_file)) { - echo 'Copying modification history file... '; - $isFileCopied = copy($lang_mod_file, $doc_base_mod_file); - echo $isFileCopied ? "done.\n" : "failed.\n"; - } else { - echo "Corrupted modification history file found: $lang_mod_file \n"; - } - } else { - echo "Modification history file $lang_mod_file not found.\n"; - } - - if (!is_array($history_file)) { - $history_file = []; - echo "Creating empty modification history file..."; - file_put_contents($doc_base_mod_file, " Date: Fri, 14 Mar 2025 12:38:58 -0300 Subject: [PATCH 4/7] Move PhD sources code to after XML validation --- configure.php | 106 +++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 54 deletions(-) diff --git a/configure.php b/configure.php index 2fcf149a2..a5a38fcee 100755 --- a/configure.php +++ b/configure.php @@ -278,55 +278,6 @@ function find_xml_files($path) // {{{ } } // }}} -function generate_sources_file() // {{{ -{ - global $ac; - $source_map = array(); - echo 'Iterating over files for sources info... '; - $en_dir = "{$ac['rootdir']}/{$ac['EN_DIR']}"; - $source_langs = array( - array('base', $ac['srcdir'], array('manual.xml', 'funcindex.xml')), - array('en', $en_dir, find_xml_files($en_dir)), - ); - if ($ac['LANG'] !== 'en') { - $lang_dir = "{$ac['rootdir']}/{$ac['LANGDIR']}"; - $source_langs[] = array($ac['LANG'], $lang_dir, find_xml_files($lang_dir)); - } - foreach ($source_langs as list($source_lang, $source_dir, $source_files)) { - foreach ($source_files as $source_path) { - $source = file_get_contents("{$source_dir}/{$source_path}"); - if (preg_match_all('/ xml:id=(["\'])([^"]+)\1/', $source, $matches)) { - foreach ($matches[2] as $xml_id) { - $source_map[$xml_id] = array( - 'lang' => $source_lang, - 'path' => $source_path, - ); - } - } - } - } - asort($source_map); - echo "OK\n"; - echo 'Generating sources XML... '; - $dom = new DOMDocument; - $dom->formatOutput = true; - $sources_elem = $dom->appendChild($dom->createElement("sources")); - foreach ($source_map as $id => $source) { - $el = $dom->createElement('item'); - $el->setAttribute('id', $id); - $el->setAttribute('lang', $source["lang"]); - $el->setAttribute('path', $source["path"]); - $sources_elem->appendChild($el); - } - echo "OK\n"; - echo "Saving sources.xml file... "; - if ($dom->save($ac['srcdir'] . '/sources.xml')) { - echo "OK\n"; - } else { - echo "FAIL!\n"; - } -} // }}} - if ( true ) # Initial clean up { $dir = escapeshellarg( __DIR__ ); @@ -748,10 +699,6 @@ function xml_configure() } } -if ($ac['SOURCES_FILE'] === 'yes') { - generate_sources_file(); -} - globbetyglob("{$ac['basedir']}/scripts", 'make_scripts_executable'); @@ -1105,7 +1052,7 @@ function xinclude_residual_list( DOMDocument $dom ) : DOMNodeList phd_acronym(); php_history(); -//phd_sources(); +phd_sources(); //phd_version(); function phd_acronym() @@ -1146,6 +1093,57 @@ function php_history() echo " done.\n"; } +function phd_sources() +{ + global $ac; + if ($ac['SOURCES_FILE'] !== 'yes') + return; + + echo 'PhD sources:'; + + echo ' reading,'; + $source_map = array(); + $en_dir = "{$ac['rootdir']}/{$ac['EN_DIR']}"; + $source_langs = array( + array('base', $ac['srcdir'], array('manual.xml', 'funcindex.xml')), + array('en', $en_dir, find_xml_files($en_dir)), + ); + if ($ac['LANG'] !== 'en') { + $lang_dir = "{$ac['rootdir']}/{$ac['LANGDIR']}"; + $source_langs[] = array($ac['LANG'], $lang_dir, find_xml_files($lang_dir)); + } + foreach ($source_langs as list($source_lang, $source_dir, $source_files)) { + foreach ($source_files as $source_path) { + $source = file_get_contents("{$source_dir}/{$source_path}"); + if (preg_match_all('/ xml:id=(["\'])([^"]+)\1/', $source, $matches)) { + foreach ($matches[2] as $xml_id) { + $source_map[$xml_id] = array( + 'lang' => $source_lang, + 'path' => $source_path, + ); + } + } + } + } + asort($source_map); + echo ' generating,'; + $dom = new DOMDocument; + $dom->formatOutput = true; + $sources_elem = $dom->appendChild($dom->createElement("sources")); + foreach ($source_map as $id => $source) { + $el = $dom->createElement('item'); + $el->setAttribute('id', $id); + $el->setAttribute('lang', $source["lang"]); + $el->setAttribute('path', $source["path"]); + $sources_elem->appendChild($el); + } + echo " saving,"; + if ($dom->save($ac['srcdir'] . '/sources.xml')) { + echo " done.\n"; + } else { + echo " fail!\n"; + } +} printf("\nAll good. Saved %s\n", basename($ac["OUTPUT_FILENAME"])); echo "All you have to do now is run 'phd -d {$mxml}'\n"; From 52da51761ae87620ed123b8d318b894ff381e2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Fri, 14 Mar 2025 12:46:51 -0300 Subject: [PATCH 5/7] Move PhD version code to after XML validation --- configure.php | 106 ++++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/configure.php b/configure.php index a5a38fcee..83e30f7b2 100755 --- a/configure.php +++ b/configure.php @@ -647,58 +647,10 @@ function xml_configure() file_put_contents( __DIR__ . "/temp/manual.conf" , implode( "\n" , $conf ) ); } - if ($ac['SEGFAULT_ERROR'] === 'yes') { libxml_use_internal_errors(true); } -if ($ac['VERSION_FILES'] === 'yes') { - $dom = new DOMDocument; - $dom->preserveWhiteSpace = false; - $dom->formatOutput = true; - - $tmp = new DOMDocument; - $tmp->preserveWhiteSpace = false; - - $versions = $dom->appendChild($dom->createElement("versions")); - - - echo "Iterating over extension specific version files... "; - if ($ac["GENERATE"] != "no") { - $globdir = dirname($ac["GENERATE"]) . "/{../../}versions.xml"; - } - else { - if (file_exists($ac['rootdir'] . '/en/trunk')) { - $globdir = $ac['rootdir'] . '/en/trunk'; - } else { - $globdir = $ac['rootdir'] . '/en'; - } - $globdir .= "/*/*/versions.xml"; - } - if (!defined('GLOB_BRACE')) { - define('GLOB_BRACE', 0); - } - foreach(glob($globdir, GLOB_BRACE) as $file) { - if($tmp->load($file)) { - foreach($tmp->getElementsByTagName("function") as $function) { - $function = $dom->importNode($function, true); - $versions->appendChild($function); - } - } else { - print_xml_errors(); - errors_are_bad(1); - } - } - echo "OK\n"; - echo "Saving it... "; - - if ($dom->save($ac['srcdir'] . '/version.xml')) { - echo "OK\n"; - } else { - echo "FAIL!\n"; - } -} - globbetyglob("{$ac['basedir']}/scripts", 'make_scripts_executable'); @@ -1053,7 +1005,7 @@ function xinclude_residual_list( DOMDocument $dom ) : DOMNodeList phd_acronym(); php_history(); phd_sources(); -//phd_version(); +phd_version(); function phd_acronym() { @@ -1126,7 +1078,7 @@ function phd_sources() } } asort($source_map); - echo ' generating,'; + echo ' transforming,'; $dom = new DOMDocument; $dom->formatOutput = true; $sources_elem = $dom->appendChild($dom->createElement("sources")); @@ -1145,6 +1097,60 @@ function phd_sources() } } +function phd_version() +{ + global $ac; + if ($ac['VERSION_FILES'] !== 'yes') + return; + + echo 'PhD version:'; + + $dom = new DOMDocument; + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + + $tmp = new DOMDocument; + $tmp->preserveWhiteSpace = false; + + $versions = $dom->appendChild($dom->createElement("versions")); + + echo ' reading,'; + if ($ac["GENERATE"] != "no") { + $globdir = dirname($ac["GENERATE"]) . "/{../../}versions.xml"; + } + else { + if (file_exists($ac['rootdir'] . '/en/trunk')) { + $globdir = $ac['rootdir'] . '/en/trunk'; + } else { + $globdir = $ac['rootdir'] . '/en'; + } + $globdir .= "/*/*/versions.xml"; + } + echo ' transforming,'; + if (!defined('GLOB_BRACE')) { + define('GLOB_BRACE', 0); + } + foreach(glob($globdir, GLOB_BRACE) as $file) { + if($tmp->load($file)) { + foreach($tmp->getElementsByTagName("function") as $function) { + $function = $dom->importNode($function, true); + $versions->appendChild($function); + } + } else { + print_xml_errors(); + errors_are_bad(1); + } + } + echo ' saving,'; + + if ($dom->save($ac['srcdir'] . '/version.xml')) { + echo " done.\n"; + } else { + echo " fail!\n"; + } +} + + printf("\nAll good. Saved %s\n", basename($ac["OUTPUT_FILENAME"])); echo "All you have to do now is run 'phd -d {$mxml}'\n"; echo "If the script hangs here, you can abort with ^C.\n"; From 500cc2334dad4af32e494ae970a90ce7958d4fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Fri, 14 Mar 2025 12:55:04 -0300 Subject: [PATCH 6/7] Always show libxml version --- configure.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/configure.php b/configure.php index 83e30f7b2..fc3fecd93 100755 --- a/configure.php +++ b/configure.php @@ -25,7 +25,7 @@ error_reporting( E_ALL ); ob_implicit_flush(); -echo "configure.php on PHP " . phpversion() . "\n\n"; +echo "configure.php on PHP " . phpversion() . ", libxml " . LIBXML_DOTTED_VERSION . "\n\n"; // init_argv() // init_checks() @@ -575,9 +575,6 @@ function find_xml_files($path) // {{{ checking('whether to enable detailed XML error messages'); checkvalue($ac['DETAILED_ERRORMSG']); -checking('libxml version'); -checkvalue(LIBXML_DOTTED_VERSION); - checking('whether to enable detailed error reporting (may segfault)'); checkvalue($ac['SEGFAULT_ERROR']); From 6b3c1552a0437b12e1671ecb9e082cde0d26a16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Sat, 15 Mar 2025 11:37:50 -0300 Subject: [PATCH 7/7] Fix 'Wrong Document Error' on XML fixup --- configure.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.php b/configure.php index fc3fecd93..f74c1708b 100755 --- a/configure.php +++ b/configure.php @@ -819,7 +819,11 @@ function xinclude_residual_fixup( DOMDocument $dom ) $nodes = xinclude_residual_list( $dom ); if ( count( $nodes ) > 0 ) - dom_saveload( $dom , $debugPath ); // preserve state + { + unset( $nodes ); + dom_saveload( $dom , $debugPath ); + $nodes = $nodes = xinclude_residual_list( $dom ); + } $count = 0; $explain = false;