# SPDX-License-Identifier: GPL-3.0-or-later
# -*- coding: utf-8 -*-
+import errno
+import json
import os
import re
import subprocess
source_suffix = '.rst'
master_doc = 'index'
-# Get current year (preferably from Git commit)
+# Get current year in the order of preference (fallback to system time)
commit_year = date.today().year
-
-try:
- commit_date_str = subprocess.check_output(['git', 'show', '--no-patch', '--format=%cs'])\
- .decode().strip()
- commit_date = date.fromisoformat(commit_date_str)
- commit_year = commit_date.year
-except BaseException as e:
- print('Could not get current commit, using system time for copyright:', e)
+commit_year_src = 'system time'
+commit_year_got = False
+
+if not commit_year_got:
+ try:
+ commit_date_str = subprocess.check_output(['git', 'show', '--no-patch', '--format=%cs'])\
+ .decode().strip()
+ commit_date = date.fromisoformat(commit_date_str)
+ commit_year = commit_date.year
+ commit_year_src = 'Git'
+ commit_year_got = True
+ except subprocess.CalledProcessError as e:
+ pass # Kind of expected, just silently fall back to '.kr-vcs-info'
+
+if not commit_year_got:
+ try:
+ with open('../.kr-vcs-info', 'rb') as vcs_info_fp:
+ vcs_info = json.load(vcs_info_fp)
+
+ commit_date = date.fromisoformat(vcs_info['commitDate'])
+ commit_year = commit_date.year
+ commit_year_src = '.kr-vcs-info'
+ commit_year_got = True
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ raise e
+
+print('Using copyright year ({year}) from {year_src}'.format(
+ year=commit_year, year_src=commit_year_src))
# General information about the project.
project = u'Knot Resolver'
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Run on 'meson dist' to copy VCS information (e.g. to generate documentation
+# with correct copyright year)
+set -o errexit -o nounset -o xtrace
+
+if [ -z "$MESON_DIST_ROOT" ]; then
+ echo "MESON_DIST_ROOT is not set! Must be run from 'meson dist'!" >&2
+ exit 1
+fi
+if [ -z "$MESON_SOURCE_ROOT" ]; then
+ echo "MESON_SOURCE_ROOT is not set! Must be run from 'meson dist'!" >&2
+ exit 1
+fi
+
+cp "$MESON_SOURCE_ROOT/.kr-vcs-info" "$MESON_DIST_ROOT"
--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Make a `.kr-vcs-info` file for archive purposes
+set -o errexit -o nounset -o xtrace
+
+cd "$(dirname ${0})/.."
+
+vcs_info_name='.kr-vcs-info'
+
+# make sure we don't accidentally add / overwrite forgotten changes in git
+#(git diff-index --quiet HEAD && git diff-index --cached --quiet HEAD) || \
+# (echo 'git index has uncommitted changes!'; exit 1)
+
+rm -f "$vcs_info_name"
+
+commit_date="$(git show --no-patch --format=%cs)"
+commit_hash="$(git show --no-patch --format=%H)"
+tag="$(git describe --tags --exact-match || echo '')"
+
+cat > "$vcs_info_name" <<EOF
+{
+ $(test -n "$tag" && echo "\"tag\": \"$tag\",")
+ "commitDate": "$commit_date",
+ "commitHash": "$commit_hash"
+}
+EOF