Derive copyright year from the git commit date

This solves problems like the need to update test suite on every
New Year's Eve.

* Makefile.am (dist-hook): Generate .year.
* copyright-year-gen: New file.
* configure.ac (copyright_year): New m4 variable, defined as the output
of copyright-year-gen script.
(AC_COPYRIGHT): Use it.
(COPYRIGHT_YEAR): New output variable and preprocessor macro.
* strace.c (print_version): Use COPYRIGHT_YEAR.
* strace.spec.in (%prep): Save the value of COPYRIGHT_YEAR autoconf
variable to .year file.
* tests/strace-V.test (config_year): New variable, derived from config.h.
Add sanity checks for $config_year and use it in expected output.

Reported-by: Andreas Schwab <schwab@suse.de>
This commit is contained in:
Eugene Syromyatnikov 2017-04-04 14:30:39 +02:00 committed by Dmitry V. Levin
parent c79792293b
commit cd838da878
6 changed files with 44 additions and 4 deletions

View File

@ -850,6 +850,7 @@ sen.h: $(patsubst %,$(srcdir)/%,$(syscallent_files))
dist-hook:
$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
${AM_V_GEN}echo $(COPYRIGHT_YEAR) > $(distdir)/.year
today = $(shell date +%Y-%m-%d)
version_regexp = $(subst .,\.,$(VERSION))

View File

@ -35,7 +35,8 @@ AC_INIT([strace],
[strace-devel@lists.sourceforge.net],
[strace],
[https://strace.io])
AC_COPYRIGHT([Copyright (C) 1999-2017 The strace developers.])
m4_define([copyright_year], m4_esyscmd([./copyright-year-gen .year]))
AC_COPYRIGHT([Copyright (C) 1999-]copyright_year[ The strace developers.])
AC_CONFIG_SRCDIR([strace.c])
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_HEADERS([config.h])
@ -59,6 +60,9 @@ AC_PROG_RANLIB
AC_USE_SYSTEM_EXTENSIONS
AX_CODE_COVERAGE
AC_DEFINE([COPYRIGHT_YEAR], "[copyright_year]", [Current copyright year.])
AC_SUBST([COPYRIGHT_YEAR], [copyright_year])
AC_MSG_CHECKING([for supported architecture])
arch_m32=
arch_mx32=

27
copyright-year-gen Executable file
View File

@ -0,0 +1,27 @@
#! /bin/sh
: ${YEAR_FILE:=$1}
: ${DEFAULT_YEAR:=$2}
year=
[ -n "${YEAR_FILE}" ] || {
echo >&2 "$0 $(dirname "$0")/.year [DEFAULT_YEAR]"
exit 1
}
[ -f "${YEAR_FILE}" ] && year="$(cat "${YEAR_FILE}")"
[ -n "${year}" ] ||
year="$(git show --format=format:%cd --no-patch --date=format:%Y)"
[ -n "${year}" ] || year="${DEFAULT_YEAR}"
[ -n "${year}" ] || year="$(date "+%Y")"
[ -n "${year}" ] || {
echo >&2 'Undefined year.'
exit 1
}
printf "%s" "${year}"

View File

@ -190,10 +190,10 @@ static void
print_version(void)
{
printf("%s -- version %s\n"
"Copyright (C) %s The strace developers <%s>.\n"
"Copyright (C) 1991-%s The strace developers <%s>.\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
PACKAGE_NAME, PACKAGE_VERSION, "1991-2017", PACKAGE_URL);
PACKAGE_NAME, PACKAGE_VERSION, COPYRIGHT_YEAR, PACKAGE_URL);
}
static void

View File

@ -48,6 +48,7 @@ The `strace' program in the `strace' package is for 32-bit processes.
%prep
%setup -q
echo -n %version-%release > .tarball-version
echo -n @COPYRIGHT_YEAR@ > .year
%build
echo 'BEGIN OF BUILD ENVIRONMENT INFORMATION'

View File

@ -14,9 +14,16 @@ getval()
../../config.h
}
config_year=$(getval COPYRIGHT_YEAR)
[ "$year" -ge "$config_year" ] && [ "$config_year" -ge 2017 ] || {
echo >&2 "The year derived from config.h (${config_year}) does not pass sanity checks."
exit 1
}
cat > "$EXP" << __EOF__
$(getval PACKAGE_NAME) -- version $(getval PACKAGE_VERSION)
Copyright (C) 1991-$year The strace developers <$(getval PACKAGE_URL)>.
Copyright (C) 1991-${config_year} The strace developers <$(getval PACKAGE_URL)>.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
__EOF__