gnu: docbook-xsl: Refactor package.

* gnu/packages/docbook.scm (docbook-xsl)[source]: Patch in snippet.
[arguments]: Use sxml representation for xmlc file.
Use xmlcatalog to manipulate catalog.xml instead of substitute*.
Use #:install-plan instead of replacing 'install phase.
[native-inputs]: Add docbook-xml-4.4 and libxml2, required for tests.

Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
This commit is contained in:
Bruno Victal 2023-04-26 01:56:55 +01:00 committed by Ludovic Courtès
parent 77404fd0aa
commit d55feb010d
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5

View File

@ -205,9 +205,16 @@ by no means limited to these applications.) This package provides XML DTDs.")
(url "https://github.com/docbook/xslt10-stylesheets") (url "https://github.com/docbook/xslt10-stylesheets")
(commit commit))) (commit commit)))
(file-name (git-file-name name version)) (file-name (git-file-name name version))
;; Multiple .jar files are bundled with the sources.
(modules '((guix build utils))) (modules '((guix build utils)))
(snippet '(for-each delete-file (find-files "." "\\.jar$"))) (snippet
#~(begin
;; Multiple .jar files are bundled with the sources.
(for-each delete-file
(find-files "." "\\.jar$"))
;; Do not build webhelp files, as they require a Saxon from
;; 2005, which is not packaged in Guix.
(substitute* "xsl/Makefile"
((" webhelp") ""))))
(sha256 (sha256
(base32 (base32
"1bl8dwrcy7skrlh80fpsmiw045bv2j0aym231ikcv3hvm2pi98dj")))) "1bl8dwrcy7skrlh80fpsmiw045bv2j0aym231ikcv3hvm2pi98dj"))))
@ -215,67 +222,106 @@ by no means limited to these applications.) This package provides XML DTDs.")
(arguments (arguments
(list (list
#:make-flags #~(list "XSLTENGINE=xsltproc") #:make-flags #~(list "XSLTENGINE=xsltproc")
#:modules '((guix build gnu-build-system)
(guix build utils)
(sxml simple))
#:phases #:phases
#~(modify-phases %standard-phases #~(let ((dest-path (format #f "~a/xml/xsl/~a-~a"
(replace 'configure #$output #$name #$version)))
(lambda _ (modify-phases %standard-phases
;; The build systems insist on a ~/.xmlc, and it is simpler to (replace 'configure
;; create a dummy config file than to patch it into (lambda _
;; submission. ;; The build systems insist on a ~/.xmlc, and it is simpler to
(setenv "HOME" "/tmp") ;; create a dummy config file than to patch it into
(call-with-output-file "/tmp/.xmlc" ;; submission.
(lambda (port) (setenv "HOME" "/tmp")
(format port "\ (call-with-output-file "/tmp/.xmlc"
<?xml version='1.0' encoding='utf-8'?> <!-- -*- nxml -*- --> (lambda (port)
<config> (sxml->xml
<java xml:id=\"bigmem\"> '(*TOP*
<java-option name=\"Xmx512m\"/> (*PI* xml "version='1.0'")
</java> (config
<xsltproc xml:id=\"xsltproc\" exec=\"xsltproc\"></xsltproc> (java (@ (xml:id "bigmem"))
<xmllint xml:id=\"xmllint\" exec=\"xmllint\"></xmllint> (java-options (@ (name "Xmx512m"))))
</config>\n"))) (xsltproc (@ (xml:id "xsltproc")
(substitute* "xsl/Makefile" (exec "xsltproc")))
;; Do not build webhelp files, as they require a Saxon from (xmllint (@ (xml:id "xmllint")
;; 2005, which is not packaged in Guix. (exec "xmllint")))))
((" webhelp") "")))) port)))))
(add-before 'install 'generate-catalog.xml (add-before 'install 'generate-catalog.xml
(lambda* (#:key make-flags #:allow-other-keys) (lambda* (#:key make-flags #:allow-other-keys)
(apply invoke "make" "-C" "xsl" "catalog.xml" make-flags))) (apply invoke "make" "-C" "xsl" "catalog.xml" make-flags)))
(add-before 'install 'patch-catalog-xml
(lambda* (#:key inputs #:allow-other-keys)
(let ((xmlcatalog (search-input-file inputs
"/bin/xmlcatalog"))
(catalog-files (find-files "." "catalog\\.xml$"))
(store-uri (string-append "file://" dest-path "/")))
(for-each
(lambda (catalog)
;; Replace /snapshot/ reference with one based on
;; BASE-VERSION.
(let ((versioned-uri
(format
#f "https://cdn.docbook.org/release/xsl/~a/"
#$base-version)))
(invoke xmlcatalog "--noout"
"--del"
"https://cdn.docbook.org/release/xsl/snapshot/"
catalog)
(for-each
(lambda (type)
(invoke xmlcatalog "--noout"
"--add" type
versioned-uri
store-uri
catalog))
(list "rewriteSystem" "rewriteURI")))
;; Patch /current/ references to point to /gnu/store/….
(for-each
(lambda (type)
(invoke xmlcatalog "--noout"
"--add" type
"https://cdn.docbook.org/release/xsl/current/"
store-uri
catalog))
(list "rewriteSystem" "rewriteURI"))
;; Re-add the no longer present compatibility entries for
;; v.1.79.1 or earlier URIs.
(for-each
(lambda (type)
(invoke xmlcatalog "--noout"
"--add" type
"http://docbook.sourceforge.net/release/xsl/current/"
store-uri
catalog))
(list "rewriteSystem" "rewriteURI")))
catalog-files))))
(replace 'install (replace 'install
(lambda _ (lambda _
(let ((xml (string-append #$output "/xml/xsl/" (let ((select-rx (make-regexp
#$name "-" #$version))
(select-rx (make-regexp
"(\\.xml$|\\.xsl$|\\.dtd$|\\.ent$)"))) "(\\.xml$|\\.xsl$|\\.dtd$|\\.ent$)")))
;; Install catalog. ;; Install catalog.
(chdir "xsl") (chdir "xsl")
(install-file "catalog.xml" xml) (install-file "catalog.xml" dest-path)
(install-file "VERSION.xsl" xml) (install-file "VERSION.xsl" dest-path)
(substitute* (string-append xml "/catalog.xml")
;; Re-add the no longer present compatibility entries.
((".*</catalog>.*" anchor)
(string-append "\
<!-- Also support old URI of v1.79.1 or earlier -->
<rewriteURI uriStartString=\"http://docbook.sourceforge.net\
/release/xsl/current/\" rewritePrefix=\"./\"/>
<rewriteSystem systemIdStartString=\"http://docbook.sourceforge.net\
/release/xsl/current/\" rewritePrefix=\"./\"/>\n" anchor))
(("/snapshot/")
(string-append "/" #$base-version "/"))
(("rewritePrefix=\"./")
(string-append "rewritePrefix=\"file://" xml "/")))
;; Install style sheets. ;; Install style sheets.
(for-each (lambda (dir) (for-each
(for-each (lambda (f) (lambda (dir)
(install-file (for-each (lambda (f)
f (string-append xml "/" (dirname f)))) (install-file
(find-files dir select-rx))) f
'("assembly" "common" "eclipse" "epub" "epub3" "fo" (string-append dest-path "/" (dirname f))))
"highlighting" "html" "htmlhelp" "javahelp" "lib" (find-files dir select-rx)))
"manpages" "params" "profiling" "roundtrip" '("assembly" "common" "eclipse" "epub" "epub3" "fo"
"template" "website" "highlighting" "html" "htmlhelp" "javahelp" "lib"
"xhtml" "xhtml-1_1" "xhtml5")))))))) "manpages" "params" "profiling" "roundtrip"
(native-inputs (list libxml2 "template" "website"
"xhtml" "xhtml-1_1" "xhtml5")))))))))
(native-inputs (list docbook-xml-4.4 ; for tests
libxml2
libxslt libxslt
perl perl
perl-xml-xpath)) perl-xml-xpath))