summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rwxr-xr-xbootstrap8
-rwxr-xr-xbuild-aux/mdate-from-git.scm89
3 files changed, 97 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 4f0ddf19331..27d76173e55 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -725,6 +725,7 @@ EXTRA_DIST += \
725 build-aux/convert-xref.scm \ 725 build-aux/convert-xref.scm \
726 build-aux/generate-authors.scm \ 726 build-aux/generate-authors.scm \
727 build-aux/git-version-gen \ 727 build-aux/git-version-gen \
728 build-aux/mdate-from-git.scm \
728 build-aux/test-driver.scm \ 729 build-aux/test-driver.scm \
729 build-aux/update-NEWS.scm \ 730 build-aux/update-NEWS.scm \
730 build-aux/update-guix-package.scm \ 731 build-aux/update-guix-package.scm \
diff --git a/bootstrap b/bootstrap
index de024aeaa5c..5bf83175e59 100755
--- a/bootstrap
+++ b/bootstrap
@@ -24,4 +24,10 @@ for lang in ${langs}; do
24 fi 24 fi
25done 25done
26 26
27exec autoreconf -vfi 27autoreconf -vfi
28
29# Replace Automake's build-aux/mdate-sh with build-aux/mdate-from-git, our
30# own, reproducible version.
31chmod +w build-aux/mdate-sh
32rm -f build-aux/mdate-sh
33ln -s mdate-from-git.scm build-aux/mdate-sh
diff --git a/build-aux/mdate-from-git.scm b/build-aux/mdate-from-git.scm
new file mode 100755
index 00000000000..9c6ebd6dd9b
--- /dev/null
+++ b/build-aux/mdate-from-git.scm
@@ -0,0 +1,89 @@
1#! /bin/sh
2# -*-scheme-*-
3export LANG=C LANGUAGE=C LC_TIME=C
4export TZ=UTC0
5exec 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 <janneke@gnu.org>
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
57generated from po/doc/guix-manual.LANG.po. For such an untraced .TEXI file,
58return 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))))