]> granicus.if.org Git - strace/commitdiff
Derive copyright year from the git commit date
authorEugene Syromyatnikov <evgsyr@gmail.com>
Tue, 4 Apr 2017 12:30:39 +0000 (14:30 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 19 Apr 2017 08:29:46 +0000 (08:29 +0000)
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>
Makefile.am
configure.ac
copyright-year-gen [new file with mode: 0755]
strace.c
strace.spec.in
tests/strace-V.test

index 7435e27342fb2118df860fa1697cfa8cd7c1cd27..5b0b87709c85dd8c731586402d266506dec1ad3c 100644 (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))
index a52ad8808802e72d4035629a90c0bf66f13a2089..a91c888daf591ae88776edfbbef9271047b90f84 100644 (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=
diff --git a/copyright-year-gen b/copyright-year-gen
new file mode 100755 (executable)
index 0000000..5a2110e
--- /dev/null
@@ -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}"
index 2933a78009f2a8174d687dd42f1f042ab9e89731..4ee2d5d3ff40b449683133256a922b6c0b98dee6 100644 (file)
--- 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
index bdd83b190394bc11f3d330124bdc8e2af5dbfd4f..6fc268977df486a79c5ec2470b66e16dbc994b70 100644 (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'
index 23973fe0ff8e4c021736876d1fb8f681fe08ecd0..d5c3ac087b80400b4ae18cc4d9553387cdb94f51 100755 (executable)
@@ -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__