]> Lady’s Gitweb - Shushe/commitdiff
Generate dependencies & destinations with metadata
authorLady <redacted>
Sat, 22 Jun 2024 17:02:24 +0000 (13:02 -0400)
committerLady <redacted>
Thu, 11 Jul 2024 01:46:30 +0000 (21:46 -0400)
This commit obviates the need for separate `metadata2dependencies` and
`metadata2destinations` transforms and simply bundles their
functionality into `expandmetadata`.

Making this work right is a bit tricky because we are outputting the
main document to `stdout` but want the other result documents to be
output to `BUILDDIR`. The best solution would be to just read in the
build directory inside of the transform and use it to determine the
output location, but unfortunately `exsl:document` does not support
dynamic computation of the destination directory. The current solution
is instead to `cd` into the build directory in a subshell before
calling `xsltproc`.

GNUmakefile
lib/expandmetadata.xslt
lib/metadata2dependencies.xslt [deleted file]
lib/metadata2destinations.xslt [deleted file]

index 3c494320f0c2834f67bcc2ea4fde13570d42e138..a41fb96cbd042c98a9c4de3db24f25d2b604277f 100644 (file)
@@ -571,12 +571,12 @@ FORCE : ;
 # Phony rules; always consider these out·of·date.
 .PHONY : FORCE all default clean gone info install list listout uninstall $(call built,$(recursivefiles)) ;
 
-ifneq ($(typeupdates)$(wildcard $(BUILDDIR)/dependencies)$(wildcard $(BUILDDIR)/destinations),)
+ifneq ($(typeupdates)$(wildcard $(BUILDDIR)/metadata),)
 # Reload this make·file if the dependency graph or output destinations have changed.
 #
 # The dependency graph and output destinations are used to set the values of variables in this make·file, so it’s important to ensure that they are actually up·to·date prior to executing any later rules.
 #
-# This recipe only exists after types have been updated or when the dependency graph or destinations file already exists.
+# This recipe only exists after types have been updated or when the metadata file exists, to avoid unnecessarily executing it when parsers need updating.
 #
 # ※ There is a chance that generating the dependencies will also update the parsers.
 $(THISDIR)/GNUmakefile :: $(BUILDDIR)/dependencies $(BUILDDIR)/destinations
@@ -647,25 +647,15 @@ $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(BU
        $(silent)$(call ensuredirectory,$(dir $@))
        $(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,<?xml version="1.0"?><object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) >|$(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(call serializexml,$<)) | $(XSLTPROC) --nonet --novalid --nomkdir --nowrite --stringparam BUILDTIME $$($(DATE) -u '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$<))$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) - >|$(call quote,$@))
 
-# Collect the metadata into a single file.
+# Collect the metadata into a single file, and generate the dependencies and destinations files as side·effects.
+#
+# Doing this all in one step reduces the number of calls to `xsltproc´ required, but requires that it be called from the build directory (necessitating a subshell).
 $(BUILDDIR)/metadata : $(call diffprereqs,metadatas,$(call metadata,$(sort $(sourcefiles) $(sourceincludes)))) $(call parsed,$(filter-out $(assetfiles),$(sourcefiles) $(sourceincludes))) $(THISDIR)/lib/expandmetadata.xslt
        $(call inform,$(PRINTF) '%s\n' 'Compiling metadata…' >&2)
-       $(silent){ $(PRINTF) '<?xml version="1.0"?><rdf:RDF xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#" xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"><书社vocab:BuildDirectory nfo:fileUrl="%s"/>' $(call quote,$(call attresc,$(call fileuri,$(BUILDDIR)))); { $(foreach meta,$(call metadata,$(sort $(sourcefiles) $(sourceincludes))),$(CAT) $(call quote,$(meta));) } | $(SED) 's/<?xml version="1.0"?>//g'; $(PRINTF) '%s\n' '</rdf:RDF>'; } | $(XSLTPROC) --nonet --novalid --nomkdir --nowrite $(call quote,$(THISDIR)/lib/expandmetadata.xslt) - | $(XMLLINT) --nonet --nsclean - >|$(call quote,$@)
-
-# Build a list of dependencies for each parsed file.
-$(BUILDDIR)/dependencies : $(BUILDDIR)/metadata $(THISDIR)/lib/metadata2dependencies.xslt
-       $(call inform,$(PRINTF) '%s\n' 'Identifying dependencies…' >&2)
-       $(silent)$(TOUCH) $(call quote,$@)
-       $(silent)$(XSLTPROC) --nonet --novalid --nomkdir --nowrite $(call quote,$(THISDIR)/lib/metadata2dependencies.xslt) $(call quote,$<) >|$(call quote,$@)
-
-# Generate a catalog of destinations for files.
-#
-# This depends on parsing non·asset source files, but not assets or includes.
-# It does not require knowing the dependencies.
-$(BUILDDIR)/destinations : $(BUILDDIR)/metadata $(THISDIR)/lib/metadata2destinations.xslt
-       $(call inform,$(PRINTF) '%s\n' 'Identifying output destinations…' >&2)
-       $(silent)$(TOUCH) $(call quote,$@)
-       $(silent)$(XSLTPROC) --nonet --novalid --nomkdir --nowrite $(call quote,$(THISDIR)/lib/metadata2destinations.xslt) $(call quote,$<) >|$(call quote,$@)
+       $(silent){ $(PRINTF) '<?xml version="1.0"?><rdf:RDF xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#" xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"><书社vocab:BuildDirectory nfo:fileUrl="%s"/>' $(call quote,$(call attresc,$(call fileuri,$(BUILDDIR)))); {$(foreach meta,$(call metadata,$(sort $(sourcefiles) $(sourceincludes))), $(CAT) $(call quote,$(meta));) } | $(SED) 's/<?xml version="1.0"?>//g'; $(PRINTF) '%s\n' '</rdf:RDF>'; } | ( $(CD) $(call quote,$(BUILDDIR)); $(XSLTPROC) --nonet --novalid --nomkdir $(call quote,$(abspath $(THISDIR)/lib/expandmetadata.xslt)) - ) | $(XMLLINT) --nonet --nsclean - >|$(call quote,$(BUILDDIR)/metadata)
+
+# The dependencies and destinations files are side·effects of building the metadata file.
+$(BUILDDIR)/dependencies $(BUILDDIR)/destinations : $(BUILDDIR)/metadata ;
 
 # Generate the main transform.
 $(BUILDDIR)/transform.catalog : $(call diffprereqs,transforms,$(sort $(TRANSFORMS)))
index e35e2c831b1ad21dce157e4039a0ae3b52ffc198..3d46c82873b05e0aff27da0076c3dc5e6d673008 100644 (file)
@@ -151,6 +151,38 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </for-each>
                </copy>
        </template>
+       <template match="/">
+               <variable name="result-fragment">
+                       <apply-templates/>
+               </variable>
+               <variable name="result" select="exsl:node-set($result-fragment)"/>
+               <copy-of select="$result/*"/>
+               <exsl:document href="dependencies" method="text" encoding="UTF-8">
+                       <for-each select="$result/rdf:RDF/*[nie:interpretedAs/nfo:PlainTextDocument]">
+                               <value-of select="@rdf:about"/>
+                               <text>&#xA;</text>
+                               <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
+                                       <text>&#x9;</text>
+                                       <text>-</text>
+                                       <value-of select="."/>
+                                       <text>&#xA;</text>
+                               </for-each>
+                               <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
+                                       <text>&#x9;</text>
+                                       <value-of select="."/>
+                                       <text>&#xA;</text>
+                               </for-each>
+                       </for-each>
+               </exsl:document>
+               <exsl:document href="destinations" method="text" encoding="UTF-8">
+                       <for-each select="$result//书社vocab:SourceFile">
+                               <value-of select="@rdf:about"/>
+                               <text>|</text>
+                               <value-of select="@书社vocab:destination"/>
+                               <text>&#xA;</text>
+                       </for-each>
+               </exsl:document>
+       </template>
        <template match="@*|node()">
                <copy>
                        <apply-templates select="@*|node()"/>
@@ -167,4 +199,5 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </call-template>
                </if>
        </template>
+       <output method="xml" encoding="UTF-8"/>
 </transform>
diff --git a/lib/metadata2dependencies.xslt b/lib/metadata2dependencies.xslt
deleted file mode 100644 (file)
index 5f71053..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0"?>
-<!--
-SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
-SPDX-License-Identifier: MPL-2.0
--->
-<!--
-⁌ ⛩📰 书社 ∷ lib/metadata2dependencies.xslt
-
-© 2023–2024 Lady [@ Ladys Computer].
-
-This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
-If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
--->
-<transform
-       xmlns="http://www.w3.org/1999/XSL/Transform"
-       xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
-       xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
-       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-       xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
-       version="1.0"
->
-       <template match="/">
-               <for-each select="rdf:RDF/*[nie:interpretedAs/nfo:PlainTextDocument]">
-                       <value-of select="@rdf:about"/>
-                       <text>&#xA;</text>
-                       <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
-                               <text>&#x9;</text>
-                               <text>-</text>
-                               <value-of select="."/>
-                               <text>&#xA;</text>
-                       </for-each>
-                       <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
-                               <text>&#x9;</text>
-                               <value-of select="."/>
-                               <text>&#xA;</text>
-                       </for-each>
-               </for-each>
-       </template>
-       <output method="text" encoding="UTF-8"/>
-</transform>
diff --git a/lib/metadata2destinations.xslt b/lib/metadata2destinations.xslt
deleted file mode 100644 (file)
index e82aa0b..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0"?>
-<!--
-SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
-SPDX-License-Identifier: MPL-2.0
--->
-<!--
-⁌ ⛩📰 书社 ∷ lib/metadata2destinations.xslt
-
-© 2024 Lady [@ Ladys Computer].
-
-This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
-If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
--->
-<transform
-       xmlns="http://www.w3.org/1999/XSL/Transform"
-       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-       xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
-       version="1.0"
->
-       <template match="/">
-               <for-each select="//书社vocab:SourceFile">
-                       <value-of select="@rdf:about"/>
-                       <text>|</text>
-                       <value-of select="@书社vocab:destination"/>
-                       <text>&#xA;</text>
-               </for-each>
-       </template>
-       <output method="text" encoding="UTF-8"/>
-</transform>
This page took 0.03016 seconds and 4 git commands to generate.