Skip to content

Commit f074cde

Browse files
committed
Merge branch 'ps/build-hotfix'
A topic to optionally build with meson, which has graduated to 'master' recently, has regressed the normal Makefile build, which is being corrected. * ps/build-hotfix: meson: add options to override build information GIT-VERSION-GEN: fix overriding GIT_BUILT_FROM_COMMIT and GIT_DATE GIT-VERSION-GEN: fix overriding GIT_VERSION Makefile: introduce template for GIT-VERSION-GEN Makefile: drop unneeded indirection for GIT-VERSION-GEN outputs Makefile: stop including "GIT-VERSION-FILE" in docs
2 parents 83c8f76 + 1bc815c commit f074cde

File tree

7 files changed

+90
-45
lines changed

7 files changed

+90
-45
lines changed

Documentation/Makefile

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ endif
181181
-include ../config.mak.autogen
182182
-include ../config.mak
183183

184+
# Set GIT_VERSION_OVERRIDE such that version_gen knows to substitute
185+
# GIT_VERSION in case it was set by the user.
186+
GIT_VERSION_OVERRIDE := $(GIT_VERSION)
187+
184188
ifndef NO_MAN_BOLD_LITERAL
185189
XMLTO_EXTRA += -m manpage-bold-literal.xsl
186190
endif
@@ -211,12 +215,10 @@ XMLTO_EXTRA += --skip-validation
211215
XMLTO_EXTRA += -x manpage.xsl
212216

213217
asciidoctor-extensions.rb: asciidoctor-extensions.rb.in FORCE
214-
$(QUIET_GEN)GIT_USER_AGENT="$(GIT_USER_AGENT)" $(SHELL_PATH) ../GIT-VERSION-GEN "$(shell pwd)/.." $< $@+
215-
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
218+
$(QUIET_GEN)$(call version_gen,"$(shell pwd)/..",$<,$@)
216219
else
217220
asciidoc.conf: asciidoc.conf.in FORCE
218-
$(QUIET_GEN)GIT_USER_AGENT="$(GIT_USER_AGENT)" $(SHELL_PATH) ../GIT-VERSION-GEN "$(shell pwd)/.." $< $@+
219-
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
221+
$(QUIET_GEN)$(call version_gen,"$(shell pwd)/..",$<,$@)
220222
endif
221223

222224
ASCIIDOC_DEPS += docinfo.html
@@ -276,13 +278,6 @@ install-pdf: pdf
276278
install-html: html
277279
'$(SHELL_PATH_SQ)' ./install-webdoc.sh $(DESTDIR)$(htmldir)
278280

279-
../GIT-VERSION-FILE: FORCE
280-
$(QUIET_SUBDIR0)../ $(QUIET_SUBDIR1) GIT-VERSION-FILE
281-
282-
ifneq ($(filter-out lint-docs clean,$(MAKECMDGOALS)),)
283-
-include ../GIT-VERSION-FILE
284-
endif
285-
286281
mergetools_txt = mergetools-diff.txt mergetools-merge.txt
287282

288283
#

Documentation/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ asciidoc_conf = custom_target(
219219
input: meson.current_source_dir() / 'asciidoc.conf.in',
220220
output: 'asciidoc.conf',
221221
depends: [git_version_file],
222+
env: version_gen_environment,
222223
)
223224

224225
asciidoc_common_options = [

GIT-VERSION-GEN

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,45 @@ fi
2727
GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.."
2828
export GIT_CEILING_DIRECTORIES
2929

30-
# First see if there is a version file (included in release tarballs),
31-
# then try git-describe, then default.
32-
if test -f "$SOURCE_DIR"/version
30+
if test -z "$GIT_VERSION"
3331
then
34-
VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
35-
elif {
36-
test -d "$SOURCE_DIR/.git" ||
37-
test -d "${GIT_DIR:-.git}" ||
38-
test -f "$SOURCE_DIR"/.git;
39-
} &&
40-
VN=$(git -C "$SOURCE_DIR" describe --match "v[0-9]*" HEAD 2>/dev/null) &&
41-
case "$VN" in
42-
*$LF*) (exit 1) ;;
43-
v[0-9]*)
44-
git -C "$SOURCE_DIR" update-index -q --refresh
45-
test -z "$(git -C "$SOURCE_DIR" diff-index --name-only HEAD --)" ||
46-
VN="$VN-dirty" ;;
47-
esac
32+
# First see if there is a version file (included in release tarballs),
33+
# then try git-describe, then default.
34+
if test -f "$SOURCE_DIR"/version
35+
then
36+
VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
37+
elif {
38+
test -d "$SOURCE_DIR/.git" ||
39+
test -d "${GIT_DIR:-.git}" ||
40+
test -f "$SOURCE_DIR"/.git;
41+
} &&
42+
VN=$(git -C "$SOURCE_DIR" describe --match "v[0-9]*" HEAD 2>/dev/null) &&
43+
case "$VN" in
44+
*$LF*) (exit 1) ;;
45+
v[0-9]*)
46+
git -C "$SOURCE_DIR" update-index -q --refresh
47+
test -z "$(git -C "$SOURCE_DIR" diff-index --name-only HEAD --)" ||
48+
VN="$VN-dirty" ;;
49+
esac
50+
then
51+
VN=$(echo "$VN" | sed -e 's/-/./g');
52+
else
53+
VN="$DEF_VER"
54+
fi
55+
56+
GIT_VERSION=$(expr "$VN" : v*'\(.*\)')
57+
fi
58+
59+
if test -z "$GIT_BUILT_FROM_COMMIT"
4860
then
49-
VN=$(echo "$VN" | sed -e 's/-/./g');
50-
else
51-
VN="$DEF_VER"
61+
GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
62+
fi
63+
64+
if test -z "$GIT_DATE"
65+
then
66+
GIT_DATE=$(git -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/null)
5267
fi
5368

54-
GIT_VERSION=$(expr "$VN" : v*'\(.*\)')
55-
GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
56-
GIT_DATE=$(git -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/null)
5769
if test -z "$GIT_USER_AGENT"
5870
then
5971
GIT_USER_AGENT="git/$GIT_VERSION"

Makefile

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,6 @@ include shared.mak
591591
#
592592
# Disable -pedantic compilation.
593593

594-
GIT-VERSION-FILE: FORCE
595-
@OLD=$$(cat $@ 2>/dev/null || :) && \
596-
$(SHELL_PATH) ./GIT-VERSION-GEN "$(shell pwd)" GIT-VERSION-FILE.in $@ && \
597-
NEW=$$(cat $@ 2>/dev/null || :) && \
598-
if test "$$OLD" != "$$NEW"; then echo "$$NEW" >&2; fi
599-
-include GIT-VERSION-FILE
600-
601594
# Set our default configuration.
602595
#
603596
# Among the variables below, these:
@@ -1465,6 +1458,18 @@ ifdef DEVELOPER
14651458
include config.mak.dev
14661459
endif
14671460

1461+
GIT-VERSION-FILE: FORCE
1462+
@OLD=$$(cat $@ 2>/dev/null || :) && \
1463+
$(call version_gen,"$(shell pwd)",GIT-VERSION-FILE.in,$@) && \
1464+
NEW=$$(cat $@ 2>/dev/null || :) && \
1465+
if test "$$OLD" != "$$NEW"; then echo "$$NEW" >&2; fi
1466+
1467+
# We need to set GIT_VERSION_OVERRIDE before including the version file as
1468+
# otherwise any user-provided value for GIT_VERSION would have been overridden
1469+
# already.
1470+
GIT_VERSION_OVERRIDE := $(GIT_VERSION)
1471+
-include GIT-VERSION-FILE
1472+
14681473
# what 'all' will build and 'install' will install in gitexecdir,
14691474
# excluding programs for built-in commands
14701475
ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
@@ -2511,8 +2516,7 @@ pager.sp pager.s pager.o: EXTRA_CPPFLAGS = \
25112516
-DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'
25122517

25132518
version-def.h: version-def.h.in GIT-VERSION-GEN GIT-VERSION-FILE GIT-USER-AGENT
2514-
$(QUIET_GEN)GIT_USER_AGENT="$(GIT_USER_AGENT)" $(SHELL_PATH) ./GIT-VERSION-GEN "$(shell pwd)" $< $@+
2515-
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
2519+
$(QUIET_GEN)$(call version_gen,"$(shell pwd)",$<,$@)
25162520

25172521
version.sp version.s version.o: version-def.h
25182522

@@ -2553,8 +2557,7 @@ $(SCRIPT_SH_GEN) $(SCRIPT_LIB) : % : %.sh generate-script.sh GIT-BUILD-OPTIONS G
25532557
mv $@+ $@
25542558

25552559
git.rc: git.rc.in GIT-VERSION-GEN GIT-VERSION-FILE
2556-
$(QUIET_GEN)$(SHELL_PATH) ./GIT-VERSION-GEN "$(shell pwd)" $< $@+
2557-
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
2560+
$(QUIET_GEN)$(call version_gen,"$(shell pwd)",$<,$@)
25582561

25592562
git.res: git.rc GIT-PREFIX
25602563
$(QUIET_RC)$(RC) -i $< -o $@

meson.build

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ if get_option('sane_tool_path') != ''
201201
script_environment.prepend('PATH', get_option('sane_tool_path'))
202202
endif
203203

204+
# The environment used by GIT-VERSION-GEN. Note that we explicitly override
205+
# environment variables that might be set by the user. This is by design so
206+
# that we always use whatever Meson has configured instead of what is present
207+
# in the environment.
208+
version_gen_environment = script_environment
209+
version_gen_environment.set('GIT_BUILT_FROM_COMMIT', get_option('built_from_commit'))
210+
version_gen_environment.set('GIT_DATE', get_option('build_date'))
211+
version_gen_environment.set('GIT_USER_AGENT', get_option('user_agent'))
212+
version_gen_environment.set('GIT_VERSION', get_option('version'))
213+
204214
compiler = meson.get_compiler('c')
205215

206216
libgit_sources = [
@@ -1484,6 +1494,7 @@ git_version_file = custom_target(
14841494
],
14851495
input: meson.current_source_dir() / 'GIT-VERSION-FILE.in',
14861496
output: 'GIT-VERSION-FILE',
1497+
env: version_gen_environment,
14871498
build_always_stale: true,
14881499
)
14891500

@@ -1500,6 +1511,7 @@ version_def_h = custom_target(
15001511
# Depend on GIT-VERSION-FILE so that we don't always try to rebuild this
15011512
# target for the same commit.
15021513
depends: [git_version_file],
1514+
env: version_gen_environment,
15031515
)
15041516

15051517
# Build a separate library for "version.c" so that we do not have to rebuild
@@ -1543,6 +1555,7 @@ if host_machine.system() == 'windows'
15431555
input: meson.current_source_dir() / 'git.rc.in',
15441556
output: 'git.rc',
15451557
depends: [git_version_file],
1558+
env: version_gen_environment,
15461559
)
15471560

15481561
common_main_sources += import('windows').compile_resources(git_rc,

meson_options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ option('runtime_prefix', type: 'boolean', value: false,
1616
option('sane_tool_path', type: 'string', value: '',
1717
description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.')
1818

19+
# Build information compiled into Git and other parts like documentation.
20+
option('build_date', type: 'string', value: '',
21+
description: 'Build date reported by our documentation.')
22+
option('built_from_commit', type: 'string', value: '',
23+
description: 'Commit that Git was built from reported by git-version(1).')
24+
option('user_agent', type: 'string', value: '',
25+
description: 'User agent reported to remote servers.')
26+
option('version', type: 'string', value: '',
27+
description: 'Version string reported by git-version(1) and other tools.')
28+
1929
# Features supported by Git.
2030
option('curl', type: 'feature', value: 'enabled',
2131
description: 'Build helpers used to access remotes with the HTTP transport.')

shared.mak

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,14 @@ endef
116116
define libpath_template
117117
-L$(1) $(if $(filter-out -L,$(CC_LD_DYNPATH)),$(CC_LD_DYNPATH)$(1))
118118
endef
119+
120+
# Populate build information into a file via GIT-VERSION-GEN. Requires the
121+
# absolute path to the root source directory as well as input and output files
122+
# as arguments, in that order.
123+
define version_gen
124+
GIT_BUILT_FROM_COMMIT="$(GIT_BUILT_FROM_COMMIT)" \
125+
GIT_DATE="$(GIT_DATE)" \
126+
GIT_USER_AGENT="$(GIT_USER_AGENT)" \
127+
GIT_VERSION="$(GIT_VERSION_OVERRIDE)" \
128+
$(SHELL_PATH) "$(1)/GIT-VERSION-GEN" "$(1)" "$(2)" "$(3)"
129+
endef

0 commit comments

Comments
 (0)