unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Janneke Nieuwenhuizen <janneke@gnu.org>
To: 70380@debbugs.gnu.org
Subject: [bug#70380] [PATCH v2 1/3] maint: Generate doc/version[-LANG].texi using `mdate-from-git.scm'.
Date: Mon, 15 Apr 2024 16:27:46 +0200	[thread overview]
Message-ID: <5fab9ccaca83003bfcf79baa00dd23cc4179b3ae.1713190364.git.janneke@gnu.org> (raw)
In-Reply-To: <cover.1713190364.git.janneke@gnu.org>

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.

Change-Id: I17d0a7de9ffea397129c0db1728f86e28a4e245f
---
 bootstrap                    |  8 +++-
 build-aux/mdate-from-git.scm | 86 ++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 1 deletion(-)
 create mode 100755 build-aux/mdate-from-git.scm

diff --git a/bootstrap b/bootstrap
index de024aeaa5..5bf83175e5 100755
--- a/bootstrap
+++ b/bootstrap
@@ -24,4 +24,10 @@ for lang in ${langs}; do
     fi
 done
 
-exec autoreconf -vfi
+autoreconf -vfi
+
+# Replace Automake's build-aux/mdate-sh with build-aux/mdate-from-git, our
+# own, reproducible version.
+chmod +w build-aux/mdate-sh
+rm -f build-aux/mdate-sh
+ln -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 0000000000..abe7e97f32
--- /dev/null
+++ b/build-aux/mdate-from-git.scm
@@ -0,0 +1,86 @@
+#! /bin/sh
+# -*-scheme-*-
+export LANG=C LANGUAGE=C LC_TIME=C
+export TZ=UTC0
+exec guile --no-auto-compile -L $srcdir -C $srcdir -e '(mdate-from-git)' -s "$0" "$@"
+!#
+
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; This program is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;;; Commentary:
+;;;
+;;; Usage: mdate-from-git.scm FILE
+;;;
+;;; This script is compatible with Automake's `mdate-sh' but uses the timestamp
+;;; from Git instead of from the file system.  Also, it can be appended to
+;;; mdate-sh.
+
+;;; As a special exception for Guix, it caters for doc/guix.LANG.texi files that
+;;; are not stored in Git, by using po/doc/guix-manual.LANG.po for the Git
+;;; timestamp.  Test doing something like:
+;;;
+;;; build-aux/mdate-from-git.scm doc/guix.de.texi
+;;;
+;;;; Code:
+
+(define-module (mdate-from-git)
+  #:use-module (ice-9 match)
+  #:use-module (ice-9 popen)
+  #:use-module (ice-9 rdelim)
+  #:use-module (ice-9 regex)
+  #:export (main))
+
+(define (pipe-command command)
+  (let* ((port (apply open-pipe* OPEN_READ command))
+         (output (read-string port)))
+    (close-port port)
+    output))
+
+(define (guix.LANG.texi->guix-manual.LANG.po file-name)
+  "Translated manuals doc/guix.LANG.texi are not tracked in Git and are
+generated from po/doc/guix-manual.LANG.po.  For such an untraced .TEXI file,
+return its .PO counterpart."
+  (let ((m (string-match "doc/guix.([^.]+).texi" file-name)))
+    (if (not m) file-name
+        (let ((lang (match:substring m 1)))
+          (format #f "po/doc/guix-manual.~a.po" lang)))))
+
+\f
+;;;
+;;; Entry point.
+;;;
+(define (main args)
+  (match args
+    ((script file-name)
+     (let* ((command `("git" "ls-files" "--error-unmatch" "--" ,file-name))
+            (tracked? (zero? (with-error-to-port (%make-void-port "w")
+                               (lambda _ (apply system* command)))))
+            (file-name (if tracked? file-name
+                           (guix.LANG.texi->guix-manual.LANG.po file-name)))
+            (command `("git" "log" "--pretty=format:%ct" "-n1" "--" ,file-name))
+            (timestamp (pipe-command command))
+            (source-date-epoch (or (getenv "SOURCE_DATE_EPOCH") "1"))
+            (timestamp (if (string-null? timestamp) source-date-epoch
+                           timestamp))
+            (time (gmtime (string->number timestamp)))
+            (d-m-y (strftime "%-d %B %Y" time)))
+       (display d-m-y)))
+    (_
+     (format (current-error-port) "Usage: mdate-from-git.scm FILE\n")
+     (exit 2))))
-- 
2.41.0





  reply	other threads:[~2024-04-15 14:29 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-14  9:56 [bug#70380] [PATCH 0/3] Reproducible `make dist' tarball: Avoid override stamp-N warnings Janneke Nieuwenhuizen
2024-04-14  9:59 ` [bug#70380] [PATCH 1/3] maint: Generate doc/version[-LANG].texi using `mdate-from-git.scm' Janneke Nieuwenhuizen
2024-04-14  9:59 ` [bug#70380] [PATCH 2/3] Revert "maint: Generate 'doc/version-LANG.texi' reproducibly." Janneke Nieuwenhuizen
2024-04-14  9:59 ` [bug#70380] [PATCH 3/3] Revert "maint: Generate 'doc/version.texi' reproducibly." Janneke Nieuwenhuizen
2024-04-15 14:27 ` [bug#70380] [PATCH v2 0/3] Reproducible `make dist' tarball: Avoid override stamp-N warnings Janneke Nieuwenhuizen
2024-04-15 14:27   ` Janneke Nieuwenhuizen [this message]
2024-04-15 14:27   ` [bug#70380] [PATCH v2 2/3] Revert "maint: Generate 'doc/version-LANG.texi' reproducibly." Janneke Nieuwenhuizen
2024-04-15 14:27   ` [bug#70380] [PATCH v2 3/3] Revert "maint: Generate 'doc/version.texi' reproducibly." Janneke Nieuwenhuizen
2024-04-16  7:33   ` [bug#70380] [PATCH v2 0/3] Reproducible `make dist' tarball: Avoid override stamp-N warnings pelzflorian (Florian Pelz)
2024-04-16  7:38     ` pelzflorian (Florian Pelz)
2024-04-17  8:10       ` Janneke Nieuwenhuizen
2024-04-17  9:53 ` [bug#70380] [PATCH v3 0/4] " Janneke Nieuwenhuizen
2024-04-17  9:53   ` [bug#70380] [PATCH v3 1/4] maint: Cater for running `make dist' from tarball Janneke Nieuwenhuizen
2024-04-17 15:37     ` pelzflorian (Florian Pelz)
2024-04-17 19:02       ` Janneke Nieuwenhuizen
2024-04-17  9:53   ` [bug#70380] [PATCH v3 2/4] maint: Generate doc/version[-LANG].texi using `mdate-from-git.scm' Janneke Nieuwenhuizen
2024-04-17  9:53   ` [bug#70380] [PATCH v3 3/4] Revert "maint: Generate 'doc/version-LANG.texi' reproducibly." Janneke Nieuwenhuizen
2024-04-17  9:53   ` [bug#70380] [PATCH v3 4/4] Revert "maint: Generate 'doc/version.texi' reproducibly." Janneke Nieuwenhuizen
2024-04-17 19:08 ` [bug#70380] [PATCH v4 0/6] Reproducible `make dist' tarball: Avoid override stamp-N warnings Janneke Nieuwenhuizen
2024-04-17 19:08   ` [bug#70380] [PATCH v4 1/6] maint: Resurrect running `make' from a tarball Janneke Nieuwenhuizen
2024-04-17 19:08   ` [bug#70380] [PATCH v4 2/6] maint: Support `make doc-po-update' from tarball Janneke Nieuwenhuizen
2024-04-18 12:01     ` pelzflorian (Florian Pelz)
2024-04-18 18:50       ` Janneke Nieuwenhuizen
2024-04-19 11:34         ` pelzflorian (Florian Pelz)
2024-04-19 14:47           ` bug#70380: " Janneke Nieuwenhuizen
2024-04-17 19:08   ` [bug#70380] [PATCH v4 3/6] maint: Cater for running `make dist' " Janneke Nieuwenhuizen
2024-04-17 19:08   ` [bug#70380] [PATCH v4 4/6] maint: Generate doc/version[-LANG].texi using `mdate-from-git.scm' Janneke Nieuwenhuizen
2024-04-17 19:08   ` [bug#70380] [PATCH v4 5/6] Revert "maint: Generate 'doc/version-LANG.texi' reproducibly." Janneke Nieuwenhuizen
2024-04-17 19:08   ` [bug#70380] [PATCH v4 6/6] Revert "maint: Generate 'doc/version.texi' reproducibly." Janneke Nieuwenhuizen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5fab9ccaca83003bfcf79baa00dd23cc4179b3ae.1713190364.git.janneke@gnu.org \
    --to=janneke@gnu.org \
    --cc=70380@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).