[PATCH v3 09/11] make-setup-generated: optionally add GIT metadata

Alex Bennée
2025-10-10T16:29:10Z

This isn't a full conversion to git based metadata but it allows for
local builds to add git commit and tree status to the final built
product. The normal formal build process is unaffected and uses
manually updated VERSION, REVISION and REVISION-DATE metadata.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v3
- re-flow logic so we either do "unofficial draft" or the formal
OASIS doc type, not both
- use git describe --tags for more descriptive git point
- expose git version to VERSION
---
make-setup-generated.sh | 96 +++++++++++++++++++++++++----------------
makeall.sh | 4 +-
makehtml.sh | 2 +-
makepdf.sh | 2 +-
4 files changed, 63 insertions(+), 41 deletions(-)

diff --git a/make-setup-generated.sh b/make-setup-generated.sh
index 2c5c7f8..256f700 100755
--- a/make-setup-generated.sh
+++ b/make-setup-generated.sh
@@ -1,45 +1,67 @@
#! /bin/sh
+#
+# Generate version and metadata preamble for the document
+#

DATESTR=${DATESTR:-`cat REVISION-DATE 2>/dev/null`}
-if [ x"$DATESTR" = x ]; then
- ISODATE=`git show --format=format:'%cd' --date=iso | head -n 1`
- DATESTR=`date -d "$DATE" +'%d %B %Y'`
-fi

-case "$1" in
- *-wd*)
- STAGE=wd
- STAGENAME="Working Draft"
- WORKINGDRAFT=`basename "$1" | sed 's/.*-wd//'`
- ;;
- *-os*)
- STAGE=os
- STAGENAME="OASIS Standard"
- WORKINGDRAFT=""
- ;;
- *-csd*)
- STAGE=csd
- WORKINGDRAFT=`basename "$1" | sed 's/.*-csd//'`
- STAGENAME="Committee Specification Draft $WORKINGDRAFT"
- ;;
- *-csprd*)
- STAGE=csprd
- WORKINGDRAFT=`basename "$1" | sed 's/.*-csprd//'`
- STAGENAME="Committee Specification Draft $WORKINGDRAFT"
- STAGEEXTRATITLE=" / \newline Public Review Draft $WORKINGDRAFT"
- STAGEEXTRA=" / Public Review Draft $WORKINGDRAFT"
- ;;
- *-cs*)
- STAGE=cs
- WORKINGDRAFT=`basename "$1" | sed 's/.*-cs//'`
- STAGENAME="Committee Specification $WORKINGDRAFT"
- ;;
- *)
- echo Unknown doc type >&2
- exit 1
-esac
+# If a second argument is passed we extract what we can from git
+# metadata (closest lightweight tag) and local tree status. This
+# allows us to build an unofficial draft and tag it appropriately.
+#
+# The formal build process skips this.
+if ! test -z "$2"; then
+ TAG=$(git describe --dirty --tags)
+ # base date on now
+ DATESTR=$(date +'%d %B %Y')
+ COMMIT=$(git describe --tags HEAD)
+
+ # Finally check if we have un-committed changes in the tree
+ if ! git diff-index --quiet HEAD -- ; then
+ COMMIT="$COMMIT with local changes"
+ fi

-VERSION=`echo "$1"| sed -e 's/virtio-v//' -e 's/-.*//'`
+ STAGE=draft
+ STAGENAME="Unofficial Draft"
+ WORKINGDRAFT=
+ VERSION="git @ $COMMIT"
+else
+ # These are all stages mandated by the OASIS process
+ case "$1" in
+ *-wd*)
+ STAGE=wd
+ STAGENAME="Working Draft"
+ WORKINGDRAFT=`basename "$1" | sed 's/.*-wd//'`
+ ;;
+ *-os*)
+ STAGE=os
+ STAGENAME="OASIS Standard"
+ WORKINGDRAFT=""
+ ;;
+ *-csd*)
+ STAGE=csd
+ WORKINGDRAFT=`basename "$1" | sed 's/.*-csd//'`
+ STAGENAME="Committee Specification Draft $WORKINGDRAFT"
+ ;;
+ *-csprd*)
+ STAGE=csprd
+ WORKINGDRAFT=`basename "$1" | sed 's/.*-csprd//'`
+ STAGENAME="Committee Specification Draft $WORKINGDRAFT"
+ STAGEEXTRATITLE=" / \newline Public Review Draft $WORKINGDRAFT"
+ STAGEEXTRA=" / Public Review Draft $WORKINGDRAFT"
+ ;;
+ *-cs*)
+ STAGE=cs
+ WORKINGDRAFT=`basename "$1" | sed 's/.*-cs//'`
+ STAGENAME="Committee Specification $WORKINGDRAFT"
+ ;;
+ *)
+ echo Unknown doc type >&2
+ exit 1
+ esac
+
+ VERSION=`echo "$1"| sed -e 's/virtio-v//' -e 's/-.*//'`
+fi

#Prepend OASIS unless already there
case "$STAGENAME" in
diff --git a/makeall.sh b/makeall.sh
index 37e6c34..5f5d5dc 100755
--- a/makeall.sh
+++ b/makeall.sh
@@ -3,8 +3,8 @@
export SPECDOC=${SPECDOC:-`cat REVISION`}
export DATESTR=${DATESTR:-`cat REVISION-DATE`}
./makezip.sh
-./makehtml.sh
-./makepdf.sh
+./makehtml.sh $1
+./makepdf.sh $1
zip $SPECDOC.zip $SPECDOC.pdf
echo Generated file $SPECDOC.zip
echo To change output file name, set SPECDOC environment variable
diff --git a/makehtml.sh b/makehtml.sh
index 45b7080..cf1a8d7 100755
--- a/makehtml.sh
+++ b/makehtml.sh
@@ -1,7 +1,7 @@
#!/bin/sh

SPECDOC=${SPECDOC:-`cat REVISION`}
-./make-setup-generated.sh "$SPECDOC"
+./make-setup-generated.sh "$SPECDOC" $1

cp virtio-html.tex $SPECDOC.tex

diff --git a/makepdf.sh b/makepdf.sh
index 9cae903..bdfb8e5 100755
--- a/makepdf.sh
+++ b/makepdf.sh
@@ -1,7 +1,7 @@
#!/bin/sh

SPECDOC=${SPECDOC:-`cat REVISION`}
-./make-setup-generated.sh "$SPECDOC"
+./make-setup-generated.sh "$SPECDOC" $1

rm $SPECDOC.aux $SPECDOC.pdf $SPECDOC.out
xelatex --jobname $SPECDOC virtio.tex
--
2.47.3