From: Lady Date: Sat, 22 Jun 2024 17:02:24 +0000 (-0400) Subject: Generate dependencies & destinations with metadata X-Git-Tag: 0.11.1~2 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/be24d75be02ad626c13c0b52cdc30e2ef8735c9f?ds=inline Generate dependencies & destinations with metadata 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`. --- diff --git a/GNUmakefile b/GNUmakefile index 3c49432..a41fb96 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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,) >|$(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) '<书社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///g'; $(PRINTF) '%s\n' ''; } | $(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) '<书社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///g'; $(PRINTF) '%s\n' ''; } | ( $(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))) diff --git a/lib/expandmetadata.xslt b/lib/expandmetadata.xslt index e35e2c8..3d46c82 100644 --- a/lib/expandmetadata.xslt +++ b/lib/expandmetadata.xslt @@ -151,6 +151,38 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one + + diff --git a/lib/metadata2dependencies.xslt b/lib/metadata2dependencies.xslt deleted file mode 100644 index 5f71053..0000000 --- a/lib/metadata2dependencies.xslt +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - diff --git a/lib/metadata2destinations.xslt b/lib/metadata2destinations.xslt deleted file mode 100644 index e82aa0b..0000000 --- a/lib/metadata2destinations.xslt +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - -