<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-gsm-manuals/+/20952">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty_reference_combine.sh: print the final result to stdout<br><br>This is a follow-up change for [1], making this script more<br>flexible.  It's now a task of the caller to store the merge<br>results to a file.  This approach allows to merge several<br>*.xml files and store all the results in a single directory.<br><br>Unfortunately, it's impossible to pass the same file as both<br>input and output to xsltproc, because it would immediately<br>overwrite its input.  To work this around, create two<br>temporary files and remove them at the end of the script.<br><br>[1] Iabe729af22c235cf9c4b252acda99b43ebcae20c<br><br>Change-Id: I6aac73d998c5937894233631e654a160d5623198<br>Related: SYS#4937<br>---<br>M build/Makefile.vty-reference.inc<br>M build/vty_reference_combine.sh<br>2 files changed, 18 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-manuals refs/changes/52/20952/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/build/Makefile.vty-reference.inc b/build/Makefile.vty-reference.inc</span><br><span>index 9e22925..878c841 100644</span><br><span>--- a/build/Makefile.vty-reference.inc</span><br><span>+++ b/build/Makefile.vty-reference.inc</span><br><span>@@ -79,7 +79,7 @@</span><br><span>         $(OSMO_GSM_MANUALS_DIR)/build/vty_reference_combine.sh "$(MERGE_DOC)" \</span><br><span>            $$($(OSMO_GSM_MANUALS_DIR)/build/find_existing_path.sh "vty/*reference.xml" $(builddir) $(srcdir)) \</span><br><span>               $(OSMO_GSM_MANUALS_DIR)/common/vty_additions.xml \</span><br><span style="color: hsl(0, 100%, 40%);">-              $(srcdir)/vty/*additions*.xml</span><br><span style="color: hsl(120, 100%, 40%);">+         $(srcdir)/vty/*additions*.xml > $(GEN_DIR)/combined.xml</span><br><span>   xsltproc $(OSMO_GSM_MANUALS_DIR)/vty_reference.xsl $(GEN_DIR)/combined.xml \</span><br><span>                 > $(GEN_DIR)/docbook_vty.xml</span><br><span> </span><br><span>@@ -98,5 +98,5 @@</span><br><span>      $(OSMO_GSM_MANUALS_DIR)/build/vty_reference_combine.sh "$(MERGE_DOC)" \</span><br><span>            $$($(OSMO_GSM_MANUALS_DIR)/build/find_existing_path.sh "*reference.xml" $$VTYDIR_BUILD $$VTYDIR_SRC) \</span><br><span>             $(OSMO_GSM_MANUALS_DIR)/common/vty_additions.xml \</span><br><span style="color: hsl(0, 100%, 40%);">-              $$VTYDIR_SRC/*additions*.xml && \</span><br><span style="color: hsl(120, 100%, 40%);">+             $$VTYDIR_SRC/*additions*.xml > $$VTYGEN/combined.xml && \</span><br><span>         xsltproc $(OSMO_GSM_MANUALS_DIR)/vty_reference.xsl $$VTYGEN/combined.xml > "$@"</span><br><span>diff --git a/build/vty_reference_combine.sh b/build/vty_reference_combine.sh</span><br><span>index 11e84c0..7b19758 100755</span><br><span>--- a/build/vty_reference_combine.sh</span><br><span>+++ b/build/vty_reference_combine.sh</span><br><span>@@ -1,12 +1,9 @@</span><br><span> #!/bin/sh</span><br><span> # usage: vty_reference_combine.sh path/to/merge_doc.xsl path/to/*reference.xml [paths to additional xmls]</span><br><span style="color: hsl(120, 100%, 40%);">+# the result of combination is printed to stdout</span><br><span> # see Makefile.vty-reference.inc</span><br><span> set -e</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-# Allow overriding the "generated" output dir, so we don't have collisions when building multiple VTY references in one</span><br><span style="color: hsl(0, 100%, 40%);">-# Osmocom project (OS#4292)</span><br><span style="color: hsl(0, 100%, 40%);">-VTYGEN=${VTYGEN:-generated}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> # first argument: merge_doc.xsl</span><br><span> MERGE_DOC="$1"</span><br><span> shift</span><br><span>@@ -16,25 +13,29 @@</span><br><span> test "$(ls -1 $reference | wc -l)" = "1"</span><br><span> shift</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-combined="$VTYGEN/combined.xml"</span><br><span style="color: hsl(0, 100%, 40%);">-combine_src="$VTYGEN/combine_src.xml"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> set -x</span><br><span style="color: hsl(0, 100%, 40%);">-cp $reference "$combined"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# we cannot use the same file as input and output, because</span><br><span style="color: hsl(120, 100%, 40%);">+# xsltproc would override the input immediately :/</span><br><span style="color: hsl(120, 100%, 40%);">+combined=$(mktemp)</span><br><span style="color: hsl(120, 100%, 40%);">+combine_src=$(mktemp)</span><br><span style="color: hsl(120, 100%, 40%);">+cp $reference $combined</span><br><span> </span><br><span> while [ -n "$1" ]; do</span><br><span>   addition="$(realpath "$1")"</span><br><span>      shift</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-       # Fix permissions: xsltproc sets the output permissions the same as the</span><br><span style="color: hsl(0, 100%, 40%);">- # input file, which means during "make distcheck" our output file will</span><br><span style="color: hsl(0, 100%, 40%);">-        # become read-only.</span><br><span style="color: hsl(0, 100%, 40%);">-     if [ -f "$combine_src" ]; then</span><br><span style="color: hsl(0, 100%, 40%);">-                chmod 644 "$combine_src"</span><br><span style="color: hsl(0, 100%, 40%);">-      fi</span><br><span style="color: hsl(120, 100%, 40%);">+    # sync both input and output files</span><br><span style="color: hsl(120, 100%, 40%);">+    cp $combined $combine_src</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   mv "$combined" "$combine_src"</span><br><span>    xsltproc -o "$combined" \</span><br><span>          --stringparam with "$addition" \</span><br><span>           "$MERGE_DOC" "$combine_src"</span><br><span> done</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# print the results to stdout</span><br><span style="color: hsl(120, 100%, 40%);">+cat $combined >&1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# clean up temporary files</span><br><span style="color: hsl(120, 100%, 40%);">+rm -f $combine_src</span><br><span style="color: hsl(120, 100%, 40%);">+rm -f $combined</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-gsm-manuals/+/20952">change 20952</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-gsm-manuals/+/20952"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-gsm-manuals </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I6aac73d998c5937894233631e654a160d5623198 </div>
<div style="display:none"> Gerrit-Change-Number: 20952 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>