tools/git-version-gen: use NEWS as a fallback

* define ".tarball-version" as the default if not specified by $1

* try read the version string from NEWS file as a fallback if the
  git-repository or .tarball-version is not available

Fixes: https://github.com/karelzak/util-linux/issues/1381
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-07-14 15:57:00 +02:00
parent cd313d3095
commit 90a1baf9a7
1 changed files with 18 additions and 8 deletions

View File

@ -3,6 +3,7 @@
scriptversion=2011-02-19.19; # UTC
# Copyright (C) 2007-2011 Free Software Foundation, Inc.
# Copyright (C) 2011-2021 Karel Zak <kzak@redhat.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -22,10 +23,9 @@ scriptversion=2011-02-19.19; # UTC
# - from a git repository in which the "git describe" command below
# produces useful output (thus requiring at least one signed tag)
# - from a non-git-repo directory containing a .tarball-version file, which
# presumes this script is invoked like "./git-version-gen .tarball-version".
# presumes this script is invoked like "./git-version-gen [.tarball-version]".
# In order to use intra-version strings in your project, you will need two
# separate generated version string files:
# In order to use intra-version strings in your project, you will need:
#
# .tarball-version - present only in a distribution tarball, and not in
# a checked-out repository. Created with contents that were learned at
@ -44,6 +44,11 @@ scriptversion=2011-02-19.19; # UTC
# files to pick up a version string change; and leave it stale to
# minimize rebuild time after unrelated changes to configure sources.
#
# NEWS - present everywhere. It's used only as a fallback solution for
# 3rd-party tarballs generated by the unofficial way (e.g. GitHub).
# The version string is read from the first line of the file, the expected
# format is "project-name version: date".
#
# It is probably wise to add these two files to .gitignore, so that you
# don't accidentally commit either generated file.
#
@ -67,13 +72,13 @@ scriptversion=2011-02-19.19; # UTC
# echo $(VERSION) > $(distdir)/.tarball-version
case $# in
1|2) ;;
*) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \
'[TAG-NORMALIZATION-SED-SCRIPT]'
0|1|2) ;;
*) echo 1>&2 "Usage: $0 [[\$srcdir/.tarball-version]" \
'[TAG-NORMALIZATION-SED-SCRIPT]]'
exit 1;;
esac
tarball_version_file=$1
tarball_version_file=${1:-".tarball-version"}
tag_sed_script="${2:-s/x/x/}"
nl='
'
@ -125,7 +130,12 @@ then
esac
v_from_git=1
else
v=UNKNOWN
if test -f NEWS
then
v=`sed '1s/.*[[:blank:]]\(.*\):.*/\1/; q;' NEWS`
else
v=UNKNOWN
fi
fi
v=`echo "$v" |sed 's/^v//'`