Skip to content

Commit

Permalink
Makefile: generate doc versions via GIT-VERSION-GEN
Browse files Browse the repository at this point in the history
The documentation we generate embeds information for the exact Git
version used as well as the date of the commit. This information is
injected by injecting attributes into the build process via command line
argument.

Refactor the logic so that we write the information into "asciidoc.conf"
and "asciidoctor-extensions.rb" via `GIT-VERSION-GEN` for AsciiDoc and
AsciiDoctor, respectively.

Signed-off-by: Patrick Steinhardt <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pks-t authored and gitster committed Dec 6, 2024
1 parent 9bb10d2 commit a38edab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Documentation/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ tmp-doc-diff/
GIT-ASCIIDOCFLAGS
/.build/
/GIT-EXCLUDED-PROGRAMS
/asciidoc.conf
/asciidoctor-extensions.rb
25 changes: 16 additions & 9 deletions Documentation/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Import tree-wide shared Makefile behavior and libraries
include ../shared.mak

.PHONY: FORCE

# Guard against environment variables
MAN1_TXT =
MAN5_TXT =
Expand Down Expand Up @@ -148,16 +150,12 @@ man5dir = $(mandir)/man5
man7dir = $(mandir)/man7
# DESTDIR =

GIT_DATE := $(shell git show --quiet --pretty='%as')

ASCIIDOC = asciidoc
ASCIIDOC_EXTRA =
ASCIIDOC_HTML = xhtml11
ASCIIDOC_DOCBOOK = docbook
ASCIIDOC_CONF = -f asciidoc.conf
ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) $(ASCIIDOC_CONF) \
-amanmanual='Git Manual' -amansource='Git $(GIT_VERSION)' \
-arevdate='$(GIT_DATE)'
ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) $(ASCIIDOC_CONF)
ASCIIDOC_DEPS = asciidoc.conf GIT-ASCIIDOCFLAGS
TXT_TO_HTML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML)
TXT_TO_XML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_DOCBOOK)
Expand Down Expand Up @@ -210,6 +208,14 @@ ASCIIDOC_DEPS = asciidoctor-extensions.rb GIT-ASCIIDOCFLAGS
DBLATEX_COMMON =
XMLTO_EXTRA += --skip-validation
XMLTO_EXTRA += -x manpage.xsl

asciidoctor-extensions.rb: asciidoctor-extensions.rb.in FORCE
$(QUIET_GEN)GIT_USER_AGENT="$(GIT_USER_AGENT)" $(SHELL_PATH) ../GIT-VERSION-GEN "$(shell pwd)/.." $< $@+
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
else
asciidoc.conf: asciidoc.conf.in FORCE
$(QUIET_GEN)GIT_USER_AGENT="$(GIT_USER_AGENT)" $(SHELL_PATH) ../GIT-VERSION-GEN "$(shell pwd)/.." $< $@+
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
endif

ASCIIDOC_DEPS += docinfo.html
Expand Down Expand Up @@ -341,6 +347,7 @@ clean:
$(RM) SubmittingPatches.txt
$(RM) $(cmds_txt) $(mergetools_txt) *.made
$(RM) GIT-ASCIIDOCFLAGS
$(RM) asciidoc.conf asciidoctor-extensions.rb

docinfo.html: docinfo-html.in
$(QUIET_GEN)$(RM) $@ && cat $< >$@
Expand All @@ -364,7 +371,7 @@ manpage-cmd = $(QUIET_XMLTO)$(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<
%.xml : %.txt $(ASCIIDOC_DEPS)
$(QUIET_ASCIIDOC)$(TXT_TO_XML) -d manpage -o $@ $<

user-manual.xml: user-manual.txt user-manual.conf asciidoctor-extensions.rb GIT-ASCIIDOCFLAGS
user-manual.xml: user-manual.txt user-manual.conf $(ASCIIDOC_DEPS)
$(QUIET_ASCIIDOC)$(TXT_TO_XML) -d book -o $@ $<

technical/api-index.txt: technical/api-index-skel.txt \
Expand All @@ -373,7 +380,7 @@ technical/api-index.txt: technical/api-index-skel.txt \

technical/%.html: ASCIIDOC_EXTRA += -a git-relative-html-prefix=../
$(patsubst %,%.html,$(API_DOCS) technical/api-index $(TECH_DOCS)): %.html : %.txt \
asciidoc.conf GIT-ASCIIDOCFLAGS
$(ASCIIDOC_DEPS)
$(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.txt

SubmittingPatches.txt: SubmittingPatches
Expand Down Expand Up @@ -416,13 +423,13 @@ $(patsubst %.txt,%.texi,$(MAN_TXT)): %.texi : %.xml
howto-index.txt: howto-index.sh $(HOWTO_TXT)
$(QUIET_GEN)'$(SHELL_PATH_SQ)' ./howto-index.sh $(sort $(HOWTO_TXT)) >$@

$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt
$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt $(ASCIIDOC_DEPS)
$(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.txt

WEBDOC_DEST = /pub/software/scm/git/docs

howto/%.html: ASCIIDOC_EXTRA += -a git-relative-html-prefix=../
$(patsubst %.txt,%.html,$(HOWTO_TXT)): %.html : %.txt GIT-ASCIIDOCFLAGS
$(patsubst %.txt,%.html,$(HOWTO_TXT)): %.html : %.txt $(ASCIIDOC_DEPS)
$(QUIET_ASCIIDOC) \
sed -e '1,/^$$/d' $< | \
$(TXT_TO_HTML) - >$@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ tilde=&#126;
apostrophe=&#39;
backtick=&#96;
litdd=&#45;&#45;
manmanual='Git Manual'
mansource='Git @GIT_VERSION@'
revdate='@GIT_DATE@'

ifdef::backend-docbook[]
[linkgit-inlinemacro]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ def process(parent, target, attrs)
class DocumentPostProcessor < Asciidoctor::Extensions::Postprocessor
def process document, output
if document.basebackend? 'docbook'
mansource = document.attributes['mansource']
manversion = document.attributes['manversion']
manmanual = document.attributes['manmanual']
new_tags = "" \
"<refmiscinfo class=\"source\">#{mansource}</refmiscinfo>\n" \
"<refmiscinfo class=\"version\">#{manversion}</refmiscinfo>\n" \
"<refmiscinfo class=\"manual\">#{manmanual}</refmiscinfo>\n"
"<refmiscinfo class=\"source\">@GIT_VERSION@</refmiscinfo>\n" \
"<refmiscinfo class=\"manual\">Git Manual</refmiscinfo>\n"
output = output.sub(/<\/refmeta>/, new_tags + "</refmeta>")
end
output
Expand Down
2 changes: 2 additions & 0 deletions GIT-VERSION-GEN
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fi

GIT_VERSION=$(expr "$VN" : v*'\(.*\)')
GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
GIT_DATE=$(git -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/null)
if test -z "$GIT_USER_AGENT"
then
GIT_USER_AGENT="git/$GIT_VERSION"
Expand All @@ -72,6 +73,7 @@ sed -e "s|@GIT_VERSION@|$GIT_VERSION|" \
-e "s|@GIT_PATCH_LEVEL@|$GIT_PATCH_LEVEL|" \
-e "s|@GIT_BUILT_FROM_COMMIT@|$GIT_BUILT_FROM_COMMIT|" \
-e "s|@GIT_USER_AGENT@|$GIT_USER_AGENT|" \
-e "s|@GIT_DATE@|$GIT_DATE|" \
"$INPUT" >"$OUTPUT"+

if ! test -f "$OUTPUT" || ! cmp "$OUTPUT"+ "$OUTPUT" >/dev/null
Expand Down

0 comments on commit a38edab

Please sign in to comment.