Skip to content

Commit f1ae07e

Browse files
committed
build: documents get Git revision
This is like #89 but for documents. Add the Git revision to the document version information when it is generated from a non-tagged revision. For tagged versions, simply use the corresponding version number (without the prefix "v"). Example: - "4.3.0" # for tagged revisions (releases) - "v4.3.0-1-g7c9706c" # for non-tagged revisions
1 parent 1290533 commit f1ae07e

7 files changed

Lines changed: 111 additions & 33 deletions

File tree

doc/devref/devref.tex.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
\input{version.tex}
2+
\def\formversiondesc{\repoversiondesc}
23
\def\formdate{\repodate}
34
%begin{latexonly} % To avoid latex2html/latex2html#37
5+
\providecommand{\formversiondesc}{@VERSION@}
46
\providecommand{\repodate}{\today}
57
%end{latexonly}
68

@@ -44,7 +46,7 @@
4446
\begin{document}
4547

4648
\thispagestyle{empty}
47-
\title{\Huge FORM \\ \Large version @VERSION@ \\ \huge Developer's reference manual}
49+
\title{\Huge FORM \\ \Large version \formversiondesc \\ \huge Developer's reference manual}
4850
\date{\formdate}
4951
\author{J.A.M.Vermaseren et al.}
5052
\maketitle

doc/doxygen/DoxyfileHTML.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PROJECT_NAME = FORM
2323
# This could be handy for archiving the generated documentation or
2424
# if some version control system is used.
2525

26-
PROJECT_NUMBER = @VERSION@
26+
PROJECT_NUMBER = $(PROJECT_NUMBER)
2727

2828
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
2929
# base path where the generated documentation will be put.

doc/doxygen/DoxyfileLATEX.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PROJECT_NAME = FORM
2323
# This could be handy for archiving the generated documentation or
2424
# if some version control system is used.
2525

26-
PROJECT_NUMBER = @VERSION@
26+
PROJECT_NUMBER = $(PROJECT_NUMBER)
2727

2828
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
2929
# base path where the generated documentation will be put.

doc/doxygen/DoxyfilePDFLATEX.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PROJECT_NAME = FORM
2323
# This could be handy for archiving the generated documentation or
2424
# if some version control system is used.
2525

26-
PROJECT_NUMBER = @VERSION@
26+
PROJECT_NUMBER = $(PROJECT_NUMBER)
2727

2828
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
2929
# base path where the generated documentation will be put.

doc/doxygen/Makefile.am

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
######################################## CONFIG_DOXYGEN
22
if CONFIG_DOXYGEN
33

4+
EXTRA_DIST = version.sh
5+
6+
.PHONY: update_version
7+
8+
# Automatic versioning.
9+
10+
version.sh: update_version
11+
$(UPDATE_VERSION)
12+
13+
dist-hook:
14+
$(DISTHOOK_VERSION)
15+
16+
if FIXED_VERSION
17+
18+
UPDATE_VERSION = \
19+
[ -f version.sh ] || $(LN_S) "$(srcdir)/version.sh.in" version.sh
20+
21+
DISTHOOK_VERSION = \
22+
cp "$(srcdir)/version.sh.in" "$(distdir)/version.sh.in"
23+
24+
else
25+
26+
UPDATE_VERSION = \
27+
$(SHELL) "$(top_srcdir)/scripts/git-version-gen.sh" -C "$(srcdir)" -s -o version.sh --date-format '%e %B %Y'
28+
29+
DISTHOOK_VERSION = \
30+
$(SHELL) "$(top_srcdir)/scripts/git-version-gen.sh" -C "$(srcdir)" -s -o "$(distdir)/version.sh.in" --date-format '%e %B %Y'
31+
32+
endif
33+
34+
RUN_DOXYGEN = source ./version.sh && PROJECT_NUMBER=$$repo_version_desc ${DOXYGEN}
35+
36+
# HTML
37+
438
html: html/index.html
539

6-
html/index.html:
40+
html/index.html: version.sh
741
@echo "Running ${DOXYGEN} DoxyfileHTML ..."; \
8-
${DOXYGEN} DoxyfileHTML
42+
${RUN_DOXYGEN} DoxyfileHTML
943

1044
#################### CONFIG_TEX
1145
if CONFIG_TEX
@@ -23,9 +57,9 @@ latex/doxygen.dvi: latex/doxygen.tex
2357
${MAKEINDEX} doxygen.idx; \
2458
${LATEX} doxygen.tex
2559

26-
latex/doxygen.tex:
60+
latex/doxygen.tex: version.sh
2761
@echo "Running ${DOXYGEN} DoxyfileLATEX ..."; \
28-
${DOXYGEN} DoxyfileLATEX; \
62+
${RUN_DOXYGEN} DoxyfileLATEX; \
2963
mv latex/refman.tex latex/doxygen.tex
3064

3165
########## CONFIG_PS
@@ -59,9 +93,9 @@ pdflatex/doxygen.pdf: pdflatex/doxygen.tex
5993
${MAKEINDEX} doxygen.idx; \
6094
${PDFLATEX} doxygen.tex
6195

62-
pdflatex/doxygen.tex:
96+
pdflatex/doxygen.tex: version.sh
6397
@echo "Running ${DOXYGEN} DoxyfilePDFLATEX ..."; \
64-
${DOXYGEN} DoxyfilePDFLATEX; \
98+
${RUN_DOXYGEN} DoxyfilePDFLATEX; \
6599
mv pdflatex/refman.tex pdflatex/doxygen.tex
66100

67101
endif

doc/manual/manual.tex.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
\input{version.tex}
22
\def\formmajorversion{\repomajorversion}
33
\def\formminorversion{\repominorversion}
4+
\def\formversiondesc{\repoversiondesc}
45
\def\formdate{\repodate}
56
%begin{latexonly} % To avoid latex2html/latex2html#37
7+
\providecommand{\formversiondesc}{@VERSION@}
68
\providecommand{\repodate}{\today}
79
%end{latexonly}
810

@@ -71,7 +73,7 @@
7173

7274
\begin{document}
7375
\begin{titlepage}
74-
\title{\Huge FORM \\ \Large version @VERSION@ \\ \huge Reference manual}
76+
\title{\Huge FORM \\ \Large version \formversiondesc \\ \huge Reference manual}
7577
\date{\formdate}
7678
\author{J.A.M.~Vermaseren, T.~Kaneko, J.~Kuipers, B.~Ruijl, M.~Tentyukov, T.~Ueda and J.~Vollinga}
7779
\end{titlepage}

scripts/git-version-gen.sh

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#!/bin/sh
22
set -eu
3-
rootdir=`dirname "$0"`/..
4-
prog=`basename "$0"`
3+
rootdir=$(dirname "$0")/..
4+
prog=$(basename "$0")
5+
6+
# Remarks:
7+
# - This script assumes the version tag matches with "^v[0-9].*$".
8+
# The version string after the prefix "v" must be in the format in
9+
# semantic versioning.
10+
# - The option -C <path> affects only the dirty flag of $revision
11+
# (and the related variable: $version_desc) and $date,
12+
# if the referred Git repository is the same.
513

614
print_usage() {
715
cat <<END
@@ -14,6 +22,7 @@ Options:
1422
-r, --raw raw output (default)
1523
-c, --c C output
1624
-t, --tex TeX output
25+
-s, --shell shell script output
1726
-v, --only-version only-version output
1827
-o <file>, --output <file> output to <file>
1928
--date-format <format> date format (default: '%b %e %Y')
@@ -72,6 +81,9 @@ for a in "$@"; do
7281
-t|--tex)
7382
mode=tex
7483
;;
84+
-s|--shell)
85+
mode=shell
86+
;;
7587
-v|--only-version)
7688
mode=only-version
7789
;;
@@ -92,52 +104,62 @@ if [ -n "$next" ]; then
92104
exit 1
93105
fi
94106

107+
# Same as git -C "$refdir" ... but works with git < 1.8.5.
95108
git_C() {
96109
(cd "$refdir" && git "$@")
97110
}
98111

99112
# Extract the version number from the latest tag, e.g.,
100113
# v1.0.0-xxx-yyy-zzz -> 1.0.0
101-
version_tag=`git_C describe --match 'v[0-9]*' --tags HEAD`
102-
version_tmp=`echo "$version_tag" | sed 's/^v//'`
103-
version_num=`echo "$version_tmp" | sed 's/-.*//'`
114+
version_tag=$(git_C describe --match 'v[0-9]*' --tags HEAD)
115+
version_tmp=$(echo "$version_tag" | sed 's/^v//')
116+
version_num=$(echo "$version_tmp" | sed 's/-.*//')
104117

105118
version=$version_num
119+
version_suffix=
106120

107121
# Support typical pre-release versions (e.g., v1.0.0-alpha-xxx-yyy-zzz) for
108122
# -alpha, -alpha.1, -beta, -beta.1, -rc, -rc.1
109123
case $version_tmp in
110124
*-alpha*|*-beta*|*-rc*)
111-
version_tmp=`echo "$version_tmp" | sed 's/^[^-]*-//' | sed 's/-.*//'`
125+
version_tmp=$(echo "$version_tmp" | sed 's/^[^-]*-//' | sed 's/-.*//')
112126
case $version_tmp in
113127
alpha*|beta*|rc*)
114128
version="$version-$version_tmp"
129+
version_suffix="-$version_tmp"
115130
;;
116131
esac
117132
;;
118133
esac
119134

120135
if [ "$mode" != "only-version" ]; then
121136
# Get the revision identifier by git-describe.
122-
revision=`git_C describe --tags --always --abbrev=7 HEAD`
137+
revision=$(git_C describe --tags --always --abbrev=7 HEAD)
123138
# Check if the working tree is dirty.
124139
git_C update-index -q --refresh
125140
if git_C diff-index --quiet HEAD .; then
126141
# If the working tree is not dirty, use the latest commit date.
127-
isodate=`git_C log -1 --pretty=%ci .`
128-
date=`LANG=C TZ=UTC fmt_isodate "$isodate" "$date_format"`
142+
isodate=$(git_C log -1 --pretty=%ci .)
143+
date=$(LANG=C TZ=UTC fmt_isodate "$isodate" "$date_format")
129144
else
130145
# If the working tree is dirty, suffix "-dirty" to the revision identifier
131146
# and use the current date time.
132147
revision="$revision-dirty"
133-
date=`LANG=C TZ=UTC date +"$date_format"`
148+
date=$(LANG=C TZ=UTC date +"$date_format")
149+
fi
150+
# Version description.
151+
# Examples: "4.3.0", "v4.3.0-1-g7c9706c"
152+
if [ "v$version" = "$revision" ]; then
153+
version_desc=$version
154+
else
155+
version_desc=$revision
134156
fi
135157
# Extract MAJOR.MINOR.PATCH from the version number.
136-
major_version=`expr "$version_num" : '\([0-9]\+\)' || :`
137-
version_num=`expr "$version_num" : '[0-9]\+\.\?\(.*\)' || :`
138-
minor_version=`expr "$version_num" : '\([0-9]\+\)' || :`
139-
version_num=`expr "$version_num" : '[0-9]\+\.\?\(.*\)' || :`
140-
patch_version=`expr "$version_num" : '\([0-9]\+\)' || :`
158+
major_version=$(expr "$version_num" : '\([0-9]\+\)' || :)
159+
version_num=$(expr "$version_num" : '[0-9]\+\.\?\(.*\)' || :)
160+
minor_version=$(expr "$version_num" : '\([0-9]\+\)' || :)
161+
version_num=$(expr "$version_num" : '[0-9]\+\.\?\(.*\)' || :)
162+
patch_version=$(expr "$version_num" : '\([0-9]\+\)' || :)
141163
[ -z "$major_version" ] && major_version=0
142164
[ -z "$minor_version" ] && minor_version=0
143165
[ -z "$patch_version" ] && patch_version=0
@@ -148,31 +170,49 @@ print_versions() {
148170
raw)
149171
cat <<END
150172
$version
173+
$version_desc
151174
$revision
152175
$date
153176
$major_version
154177
$minor_version
155178
$patch_version
179+
$version_suffix
156180
END
157181
;;
158182
c)
159183
cat <<END
160-
#define REPO_VERSION "$version"
161-
#define REPO_REVISION "$revision"
162-
#define REPO_DATE "$date"
163-
#define REPO_MAJOR_VERSION $major_version
164-
#define REPO_MINOR_VERSION $minor_version
165-
#define REPO_PATCH_VERSION $patch_version
184+
#define REPO_VERSION "$version"
185+
#define REPO_VERSION_DESC "$version_desc"
186+
#define REPO_REVISION "$revision"
187+
#define REPO_DATE "$date"
188+
#define REPO_MAJOR_VERSION $major_version
189+
#define REPO_MINOR_VERSION $minor_version
190+
#define REPO_PATCH_VERSION $patch_version
191+
#define REPO_VERSION_SUFFIX "$version_suffix"
166192
END
167193
;;
168194
tex)
169195
cat <<END
170196
\def\repoversion{$version}
197+
\def\repoversiondesc{$version_desc}
171198
\def\reporevision{$revision}
172199
\def\repodate{$date}
173200
\def\repomajorversion{$major_version}
174201
\def\repominorversion{$minor_version}
175202
\def\repopatchversion{$patch_version}
203+
\def\repoversionsuffix{$version_suffix}
204+
END
205+
;;
206+
shell)
207+
cat <<END
208+
repo_version='$version'
209+
repo_version_desc='$version_desc'
210+
repo_revision='$revision'
211+
repo_date='$date'
212+
repo_major_version='$major_version'
213+
repo_minor_version='$minor_version'
214+
repo_patch_version='$patch_version'
215+
repo_version_suffix='$version_suffix'
176216
END
177217
;;
178218
only-version)
@@ -197,7 +237,7 @@ if [ -z "$output_file" ]; then
197237
else
198238
# To the output file. Write only if any changes required.
199239
if [ -f "$output_file" ]; then
200-
out=`print_versions`
240+
out=$(print_versions)
201241
# NOTE: using echo instead of say at the next line may have problems
202242
# for --tex. POSIX says echo should process '\\', but some shells
203243
# don't without -e option. Here we shouldn't process them.

0 commit comments

Comments
 (0)