Skip to content

Commit

Permalink
Merge branch 'ps/build-hotfix' into ma/asciidoctor-build-fixes
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gitster committed Dec 21, 2024
2 parents ff795a5 + 1bc815c commit f5f82c0
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 45 deletions.
17 changes: 6 additions & 11 deletions Documentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ endif
-include ../config.mak.autogen
-include ../config.mak

# Set GIT_VERSION_OVERRIDE such that version_gen knows to substitute
# GIT_VERSION in case it was set by the user.
GIT_VERSION_OVERRIDE := $(GIT_VERSION)

ifndef NO_MAN_BOLD_LITERAL
XMLTO_EXTRA += -m manpage-bold-literal.xsl
endif
Expand Down Expand Up @@ -211,12 +215,10 @@ 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
$(QUIET_GEN)$(call version_gen,"$(shell pwd)/..",$<,$@)
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
$(QUIET_GEN)$(call version_gen,"$(shell pwd)/..",$<,$@)
endif

ASCIIDOC_DEPS += docinfo.html
Expand Down Expand Up @@ -276,13 +278,6 @@ install-pdf: pdf
install-html: html
'$(SHELL_PATH_SQ)' ./install-webdoc.sh $(DESTDIR)$(htmldir)

../GIT-VERSION-FILE: FORCE
$(QUIET_SUBDIR0)../ $(QUIET_SUBDIR1) GIT-VERSION-FILE

ifneq ($(filter-out lint-docs clean,$(MAKECMDGOALS)),)
-include ../GIT-VERSION-FILE
endif

mergetools_txt = mergetools-diff.txt mergetools-merge.txt

#
Expand Down
1 change: 1 addition & 0 deletions Documentation/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ asciidoc_conf = custom_target(
input: meson.current_source_dir() / 'asciidoc.conf.in',
output: 'asciidoc.conf',
depends: [git_version_file],
env: version_gen_environment,
)

asciidoc_common_options = [
Expand Down
58 changes: 35 additions & 23 deletions GIT-VERSION-GEN
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,45 @@ fi
GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.."
export GIT_CEILING_DIRECTORIES

# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
if test -f "$SOURCE_DIR"/version
if test -z "$GIT_VERSION"
then
VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
elif {
test -d "$SOURCE_DIR/.git" ||
test -d "${GIT_DIR:-.git}" ||
test -f "$SOURCE_DIR"/.git;
} &&
VN=$(git -C "$SOURCE_DIR" describe --match "v[0-9]*" HEAD 2>/dev/null) &&
case "$VN" in
*$LF*) (exit 1) ;;
v[0-9]*)
git -C "$SOURCE_DIR" update-index -q --refresh
test -z "$(git -C "$SOURCE_DIR" diff-index --name-only HEAD --)" ||
VN="$VN-dirty" ;;
esac
# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
if test -f "$SOURCE_DIR"/version
then
VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
elif {
test -d "$SOURCE_DIR/.git" ||
test -d "${GIT_DIR:-.git}" ||
test -f "$SOURCE_DIR"/.git;
} &&
VN=$(git -C "$SOURCE_DIR" describe --match "v[0-9]*" HEAD 2>/dev/null) &&
case "$VN" in
*$LF*) (exit 1) ;;
v[0-9]*)
git -C "$SOURCE_DIR" update-index -q --refresh
test -z "$(git -C "$SOURCE_DIR" diff-index --name-only HEAD --)" ||
VN="$VN-dirty" ;;
esac
then
VN=$(echo "$VN" | sed -e 's/-/./g');
else
VN="$DEF_VER"
fi

GIT_VERSION=$(expr "$VN" : v*'\(.*\)')
fi

if test -z "$GIT_BUILT_FROM_COMMIT"
then
VN=$(echo "$VN" | sed -e 's/-/./g');
else
VN="$DEF_VER"
GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
fi

if test -z "$GIT_DATE"
then
GIT_DATE=$(git -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/null)
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 Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,6 @@ include shared.mak
#
# Disable -pedantic compilation.

GIT-VERSION-FILE: FORCE
@OLD=$$(cat $@ 2>/dev/null || :) && \
$(SHELL_PATH) ./GIT-VERSION-GEN "$(shell pwd)" GIT-VERSION-FILE.in $@ && \
NEW=$$(cat $@ 2>/dev/null || :) && \
if test "$$OLD" != "$$NEW"; then echo "$$NEW" >&2; fi
-include GIT-VERSION-FILE

# Set our default configuration.
#
# Among the variables below, these:
Expand Down Expand Up @@ -1465,6 +1458,18 @@ ifdef DEVELOPER
include config.mak.dev
endif

GIT-VERSION-FILE: FORCE
@OLD=$$(cat $@ 2>/dev/null || :) && \
$(call version_gen,"$(shell pwd)",GIT-VERSION-FILE.in,$@) && \
NEW=$$(cat $@ 2>/dev/null || :) && \
if test "$$OLD" != "$$NEW"; then echo "$$NEW" >&2; fi

# We need to set GIT_VERSION_OVERRIDE before including the version file as
# otherwise any user-provided value for GIT_VERSION would have been overridden
# already.
GIT_VERSION_OVERRIDE := $(GIT_VERSION)
-include GIT-VERSION-FILE

# what 'all' will build and 'install' will install in gitexecdir,
# excluding programs for built-in commands
ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
Expand Down Expand Up @@ -2512,8 +2517,7 @@ pager.sp pager.s pager.o: EXTRA_CPPFLAGS = \
-DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'

version-def.h: version-def.h.in GIT-VERSION-GEN GIT-VERSION-FILE GIT-USER-AGENT
$(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
$(QUIET_GEN)$(call version_gen,"$(shell pwd)",$<,$@)

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

Expand Down Expand Up @@ -2554,8 +2558,7 @@ $(SCRIPT_SH_GEN) $(SCRIPT_LIB) : % : %.sh generate-script.sh GIT-BUILD-OPTIONS G
mv $@+ $@

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

git.res: git.rc GIT-PREFIX
$(QUIET_RC)$(RC) -i $< -o $@
Expand Down
13 changes: 13 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ if get_option('sane_tool_path') != ''
script_environment.prepend('PATH', get_option('sane_tool_path'))
endif

# The environment used by GIT-VERSION-GEN. Note that we explicitly override
# environment variables that might be set by the user. This is by design so
# that we always use whatever Meson has configured instead of what is present
# in the environment.
version_gen_environment = script_environment
version_gen_environment.set('GIT_BUILT_FROM_COMMIT', get_option('built_from_commit'))
version_gen_environment.set('GIT_DATE', get_option('build_date'))
version_gen_environment.set('GIT_USER_AGENT', get_option('user_agent'))
version_gen_environment.set('GIT_VERSION', get_option('version'))

compiler = meson.get_compiler('c')

libgit_sources = [
Expand Down Expand Up @@ -1485,6 +1495,7 @@ git_version_file = custom_target(
],
input: meson.current_source_dir() / 'GIT-VERSION-FILE.in',
output: 'GIT-VERSION-FILE',
env: version_gen_environment,
build_always_stale: true,
)

Expand All @@ -1501,6 +1512,7 @@ version_def_h = custom_target(
# Depend on GIT-VERSION-FILE so that we don't always try to rebuild this
# target for the same commit.
depends: [git_version_file],
env: version_gen_environment,
)

# Build a separate library for "version.c" so that we do not have to rebuild
Expand Down Expand Up @@ -1544,6 +1556,7 @@ if host_machine.system() == 'windows'
input: meson.current_source_dir() / 'git.rc.in',
output: 'git.rc',
depends: [git_version_file],
env: version_gen_environment,
)

common_main_sources += import('windows').compile_resources(git_rc,
Expand Down
10 changes: 10 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ option('runtime_prefix', type: 'boolean', value: false,
option('sane_tool_path', type: 'string', value: '',
description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.')

# Build information compiled into Git and other parts like documentation.
option('build_date', type: 'string', value: '',
description: 'Build date reported by our documentation.')
option('built_from_commit', type: 'string', value: '',
description: 'Commit that Git was built from reported by git-version(1).')
option('user_agent', type: 'string', value: '',
description: 'User agent reported to remote servers.')
option('version', type: 'string', value: '',
description: 'Version string reported by git-version(1) and other tools.')

# Features supported by Git.
option('curl', type: 'feature', value: 'enabled',
description: 'Build helpers used to access remotes with the HTTP transport.')
Expand Down
11 changes: 11 additions & 0 deletions shared.mak
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,14 @@ endef
define libpath_template
-L$(1) $(if $(filter-out -L,$(CC_LD_DYNPATH)),$(CC_LD_DYNPATH)$(1))
endef

# Populate build information into a file via GIT-VERSION-GEN. Requires the
# absolute path to the root source directory as well as input and output files
# as arguments, in that order.
define version_gen
GIT_BUILT_FROM_COMMIT="$(GIT_BUILT_FROM_COMMIT)" \
GIT_DATE="$(GIT_DATE)" \
GIT_USER_AGENT="$(GIT_USER_AGENT)" \
GIT_VERSION="$(GIT_VERSION_OVERRIDE)" \
$(SHELL_PATH) "$(1)/GIT-VERSION-GEN" "$(1)" "$(2)" "$(3)"
endef

0 comments on commit f5f82c0

Please sign in to comment.