Skip to content

Commit

Permalink
Generate git versions from out-of-tree builds
Browse files Browse the repository at this point in the history
We have to ensure that the calculate script knows where the source
directory is, so that it can set up $GIT_DIR correctly when generating
git-based version numbers.
  • Loading branch information
dcreager committed May 9, 2020
1 parent cbd4d12 commit 8330c19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ find_package(CTargets)

execute_process(
COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/build-aux/calculate version .version-stamp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/build-aux/calculate version
${CMAKE_SOURCE_DIR} .version-stamp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE VERSION_RESULT
OUTPUT_VARIABLE VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -44,8 +45,9 @@ endif(BASE_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-dev)?$")

execute_process(
COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/build-aux/calculate commit .commit-stamp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/build-aux/calculate commit
${CMAKE_SOURCE_DIR} .commit-stamp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_SHA1_RESULT
OUTPUT_VARIABLE GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand Down
20 changes: 9 additions & 11 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ dist-hook: dist-check-git-version dist-stamps

dist-check-git-version:
: # Verify that the version that configure.ac recorded matches the
: # current version from git tags.
@if test -n $(top_srcdir)/.version-stamp; then \
git_ver=`$(top_srcdir)/build-aux/calculate version`; \
if test "x$${git_ver}" != "x$(PACKAGE_VERSION)"; then \
echo "ERROR: PACKAGE_VERSION and 'git describe' version do not match:"; \
echo " current 'git describe' version: $${git_ver}"; \
echo " current PACKAGE_VERSION: $(PACKAGE_VERSION)"; \
echo "Update PACKAGE_VERSION by running $(top_srcdir)/autogen.sh."; \
rm -rf "$(top_srcdir)/autom4te.cache"; \
exit 1; \
fi \
: # current calculated version.
@git_ver=`$(top_srcdir)/build-aux/calculate version $(top_srcdir) $(top_srcdir)/.version-stamp`; \
if test "x$${git_ver}" != "x$(PACKAGE_VERSION)"; then \
echo "ERROR: PACKAGE_VERSION and 'git describe' version do not match:"; \
echo " current 'git describe' version: $${git_ver}"; \
echo " current PACKAGE_VERSION: $(PACKAGE_VERSION)"; \
echo "Update PACKAGE_VERSION by running $(top_srcdir)/autogen.sh."; \
rm -rf "$(top_srcdir)/autom4te.cache"; \
exit 1; \
fi

dist-stamps:
Expand Down
9 changes: 7 additions & 2 deletions build-aux/calculate
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@
# ----------------------------------------------------------------------

# Usage:
# calculate version|commit [path to stamp file]
# calculate version|commit [top_srcdir] [path to stamp file]
#
# Calculates the current version number. When run from a distribution tarball,
# we get the version number from the .version-stamp file (that our `make dist`
# target ensures that it creates). When run from a local git repository, we get
# the version number via `git describe`.

set -e

WHAT="$1"
case "$WHAT" in
version) ;;
commit) ;;
*) echo "Unknown option $WHAT" >&2; exit 1;;
esac

top_srcdir="${2-.}"
export GIT_DIR="${top_srcdir}/.git"

# First try the stamp file
STAMP_FILE="$2"
STAMP_FILE="$3"
if [ -f "$STAMP_FILE" ]; then
version=$(cat "$STAMP_FILE")
if [ -z "$version" ]; then
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ------------------------------------------------------------------------------

AC_INIT([libcork],
m4_esyscmd([build-aux/calculate version .version-stamp]),
m4_esyscmd([build-aux/calculate version . .version-stamp]),
[[email protected]])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
Expand All @@ -28,7 +28,7 @@ BASE_VERSION=`AS_ECHO([$VERSION]) | sed -e 's/\+.*//'`
AC_SUBST(VERSION_MAJOR, [`AS_ECHO([$BASE_VERSION]) | $AWK -F. '{print $1}'`])
AC_SUBST(VERSION_MINOR, [`AS_ECHO([$BASE_VERSION]) | $AWK -F. '{print $2}'`])
AC_SUBST(VERSION_PATCH, [`AS_ECHO([$BASE_VERSION]) | $AWK -F. '{print $3}'`])
AC_SUBST(GIT_SHA1, m4_esyscmd([build-aux/calculate commit .commit-stamp]))
AC_SUBST(GIT_SHA1, m4_esyscmd([build-aux/calculate commit . .commit-stamp]))
AC_CONFIG_FILES([include/libcork/config/version.h])
AC_PROG_CC
AC_PROG_CC_C99
Expand Down

0 comments on commit 8330c19

Please sign in to comment.