From: Eugene Syromyatnikov Date: Tue, 4 Apr 2017 12:30:39 +0000 (+0200) Subject: Derive copyright year from the git commit date X-Git-Tag: v4.17~62 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd838da878352d63440af2d9fdb9fec74fe6a65a;p=strace 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 --- diff --git a/Makefile.am b/Makefile.am index 7435e273..5b0b8770 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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)) diff --git a/configure.ac b/configure.ac index a52ad880..a91c888d 100644 --- a/configure.ac +++ b/configure.ac @@ -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= diff --git a/copyright-year-gen b/copyright-year-gen new file mode 100755 index 00000000..5a2110e4 --- /dev/null +++ b/copyright-year-gen @@ -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}" diff --git a/strace.c b/strace.c index 2933a780..4ee2d5d3 100644 --- a/strace.c +++ b/strace.c @@ -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 diff --git a/strace.spec.in b/strace.spec.in index bdd83b19..6fc26897 100644 --- a/strace.spec.in +++ b/strace.spec.in @@ -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' diff --git a/tests/strace-V.test b/tests/strace-V.test index 23973fe0..d5c3ac08 100755 --- a/tests/strace-V.test +++ b/tests/strace-V.test @@ -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__