Skip to content

Commit 2b8a2a6

Browse files
committed
maint: Generate doc/version[-LANG].texi using `mdate-from-git.scm'.
This replaces Automake's `build-aux/mdate-sh' with our own `build-aux/mdate-from-git.scm' to use reproducible timestamps from Git instead. * build-aux/mdate-from-git.scm: New script. * bootstrap: Use it to replace build-aux/mdate-sh. * Makefile.am (EXTRA_DIST): Add it. Change-Id: I17d0a7de9ffea397129c0db1728f86e28a4e245f
1 parent a47f228 commit 2b8a2a6

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ EXTRA_DIST += \
725725
build-aux/convert-xref.scm \
726726
build-aux/generate-authors.scm \
727727
build-aux/git-version-gen \
728+
build-aux/mdate-from-git.scm \
728729
build-aux/test-driver.scm \
729730
build-aux/update-NEWS.scm \
730731
build-aux/update-guix-package.scm \

bootstrap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ for lang in ${langs}; do
2424
fi
2525
done
2626

27-
exec autoreconf -vfi
27+
autoreconf -vfi
28+
29+
# Replace Automake's build-aux/mdate-sh with build-aux/mdate-from-git, our
30+
# own, reproducible version.
31+
chmod +w build-aux/mdate-sh
32+
rm -f build-aux/mdate-sh
33+
ln -s mdate-from-git.scm build-aux/mdate-sh

build-aux/mdate-from-git.scm

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#! /bin/sh
2+
# -*-scheme-*-
3+
export LANG=C LANGUAGE=C LC_TIME=C
4+
export TZ=UTC0
5+
exec guile --no-auto-compile -L $srcdir -C $srcdir -e '(mdate-from-git)' -s "$0" "$@"
6+
!#
7+
8+
;;; GNU Guix --- Functional package management for GNU
9+
;;; Copyright © 2024 Janneke Nieuwenhuizen <[email protected]>
10+
;;;
11+
;;; This file is part of GNU Guix.
12+
;;;
13+
;;; This program is free software; you can redistribute it and/or modify it
14+
;;; under the terms of the GNU General Public License as published by
15+
;;; the Free Software Foundation; either version 3 of the License, or (at
16+
;;; your option) any later version.
17+
;;;
18+
;;; This program is distributed in the hope that it will be useful, but
19+
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20+
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
;;; GNU General Public License for more details.
22+
;;;
23+
;;; You should have received a copy of the GNU General Public License
24+
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
26+
;;;; Commentary:
27+
;;;
28+
;;; Usage: mdate-from-git.scm FILE
29+
;;;
30+
;;; This script is compatible with Automake's `mdate-sh' but uses the timestamp
31+
;;; from Git instead of from the file system. Also, it can be appended to
32+
;;; mdate-sh.
33+
34+
;;; As a special exception for Guix, it caters for doc/guix.LANG.texi files that
35+
;;; are not stored in Git, by using po/doc/guix-manual.LANG.po for the Git
36+
;;; timestamp. Test doing something like:
37+
;;;
38+
;;; build-aux/mdate-from-git.scm doc/guix.de.texi
39+
;;;
40+
;;;; Code:
41+
42+
(define-module (mdate-from-git)
43+
#:use-module (ice-9 match)
44+
#:use-module (ice-9 popen)
45+
#:use-module (ice-9 rdelim)
46+
#:use-module (ice-9 regex)
47+
#:export (main))
48+
49+
(define (pipe-command command)
50+
(let* ((port (apply open-pipe* OPEN_READ command))
51+
(output (read-string port)))
52+
(close-port port)
53+
output))
54+
55+
(define (guix.LANG.texi->guix-manual.LANG.po file-name)
56+
"Translated manuals doc/guix.LANG.texi are not tracked in Git and are
57+
generated from po/doc/guix-manual.LANG.po. For such an untraced .TEXI file,
58+
return its .PO counterpart."
59+
(let ((m (string-match "doc/guix.([^.]+).texi" file-name)))
60+
(if (not m) file-name
61+
(let ((lang (match:substring m 1)))
62+
(format #f "po/doc/guix-manual.~a.po" lang)))))
63+
64+
65+
;;;
66+
;;; Entry point.
67+
;;;
68+
(define (main args)
69+
(match args
70+
((script file-name)
71+
(let* ((command `("git" "ls-files" "--error-unmatch" "--" ,file-name))
72+
(tracked? (zero? (with-error-to-port (%make-void-port "w")
73+
(lambda _
74+
(with-output-to-port (%make-void-port "w")
75+
(lambda _ (apply system* command)))))))
76+
(file-name (if tracked? file-name
77+
(guix.LANG.texi->guix-manual.LANG.po file-name)))
78+
(command `("git" "log" "--pretty=format:%ct" "-n1" "--" ,file-name))
79+
(timestamp (with-error-to-port (%make-void-port "w")
80+
(lambda _ (pipe-command command))))
81+
(source-date-epoch (or (getenv "SOURCE_DATE_EPOCH") "1"))
82+
(timestamp (if (string-null? timestamp) source-date-epoch
83+
timestamp))
84+
(time (gmtime (string->number timestamp)))
85+
(d-m-y (strftime "%-d %B %Y" time)))
86+
(display d-m-y)))
87+
(_
88+
(format (current-error-port) "Usage: mdate-from-git.scm FILE\n")
89+
(exit 2))))

0 commit comments

Comments
 (0)