vty_reference_combine.sh: print the final result to stdout
This is a follow-up change for [1], making this script more flexible. It's now a task of the caller to store the merge results to a file. This approach allows to merge several *.xml files and store all the results in a single directory. Unfortunately, it's impossible to pass the same file as both input and output to xsltproc, because it would immediately overwrite its input. To work this around, create two temporary files and remove them at the end of the script. [1] Iabe729af22c235cf9c4b252acda99b43ebcae20c Change-Id: I6aac73d998c5937894233631e654a160d5623198 Related: SYS#4937
This commit is contained in:
parent
2e5dd3cd3f
commit
2e039c9c12
|
@ -79,7 +79,7 @@ $(GEN_DIR)/docbook_vty.xml: \
|
|||
$(OSMO_GSM_MANUALS_DIR)/build/vty_reference_combine.sh "$(MERGE_DOC)" \
|
||||
$$($(OSMO_GSM_MANUALS_DIR)/build/find_existing_path.sh "vty/*reference.xml" $(builddir) $(srcdir)) \
|
||||
$(OSMO_GSM_MANUALS_DIR)/common/vty_additions.xml \
|
||||
$(srcdir)/vty/*additions*.xml
|
||||
$(srcdir)/vty/*additions*.xml > $(GEN_DIR)/combined.xml
|
||||
xsltproc $(OSMO_GSM_MANUALS_DIR)/vty_reference.xsl $(GEN_DIR)/combined.xml \
|
||||
> $(GEN_DIR)/docbook_vty.xml
|
||||
|
||||
|
@ -98,5 +98,5 @@ $(GEN_DIR)/docbook_%-vty-reference.xml: \
|
|||
$(OSMO_GSM_MANUALS_DIR)/build/vty_reference_combine.sh "$(MERGE_DOC)" \
|
||||
$$($(OSMO_GSM_MANUALS_DIR)/build/find_existing_path.sh "*reference.xml" $$VTYDIR_BUILD $$VTYDIR_SRC) \
|
||||
$(OSMO_GSM_MANUALS_DIR)/common/vty_additions.xml \
|
||||
$$VTYDIR_SRC/*additions*.xml && \
|
||||
$$VTYDIR_SRC/*additions*.xml > $$VTYGEN/combined.xml && \
|
||||
xsltproc $(OSMO_GSM_MANUALS_DIR)/vty_reference.xsl $$VTYGEN/combined.xml > "$@"
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
#!/bin/sh
|
||||
# usage: vty_reference_combine.sh path/to/merge_doc.xsl path/to/*reference.xml [paths to additional xmls]
|
||||
# the result of combination is printed to stdout
|
||||
# see Makefile.vty-reference.inc
|
||||
set -e
|
||||
|
||||
# Allow overriding the "generated" output dir, so we don't have collisions when building multiple VTY references in one
|
||||
# Osmocom project (OS#4292)
|
||||
VTYGEN=${VTYGEN:-generated}
|
||||
|
||||
# first argument: merge_doc.xsl
|
||||
MERGE_DOC="$1"
|
||||
shift
|
||||
|
@ -16,25 +13,29 @@ reference="$1"
|
|||
test "$(ls -1 $reference | wc -l)" = "1"
|
||||
shift
|
||||
|
||||
combined="$VTYGEN/combined.xml"
|
||||
combine_src="$VTYGEN/combine_src.xml"
|
||||
|
||||
set -x
|
||||
cp $reference "$combined"
|
||||
|
||||
# we cannot use the same file as input and output, because
|
||||
# xsltproc would override the input immediately :/
|
||||
combined=$(mktemp)
|
||||
combine_src=$(mktemp)
|
||||
cp $reference $combined
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
addition="$(realpath "$1")"
|
||||
shift
|
||||
|
||||
# Fix permissions: xsltproc sets the output permissions the same as the
|
||||
# input file, which means during "make distcheck" our output file will
|
||||
# become read-only.
|
||||
if [ -f "$combine_src" ]; then
|
||||
chmod 644 "$combine_src"
|
||||
fi
|
||||
# sync both input and output files
|
||||
cp $combined $combine_src
|
||||
|
||||
mv "$combined" "$combine_src"
|
||||
xsltproc -o "$combined" \
|
||||
--stringparam with "$addition" \
|
||||
"$MERGE_DOC" "$combine_src"
|
||||
done
|
||||
|
||||
# print the results to stdout
|
||||
cat $combined >&1
|
||||
|
||||
# clean up temporary files
|
||||
rm -f $combine_src
|
||||
rm -f $combined
|
||||
|
|
Loading…
Reference in New Issue