From patchwork Sun Apr 14 09:59:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janneke Nieuwenhuizen X-Patchwork-Id: 62968 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1896727BBEA; Sun, 14 Apr 2024 11:01:30 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1B20627BBE2 for ; Sun, 14 Apr 2024 11:01:29 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rvwfc-000825-4H; Sun, 14 Apr 2024 06:01:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rvwfZ-00081l-J4 for guix-patches@gnu.org; Sun, 14 Apr 2024 06:01:06 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rvwfY-0004lu-Gr for guix-patches@gnu.org; Sun, 14 Apr 2024 06:01:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rvwfj-0003JP-9G for guix-patches@gnu.org; Sun, 14 Apr 2024 06:01:15 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70380] [PATCH 1/3] maint: Generate doc/version[-LANG].texi using `mdate-from-git.scm'. Resent-From: Janneke Nieuwenhuizen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 14 Apr 2024 10:01:14 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70380 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70380@debbugs.gnu.org Received: via spool by 70380-submit@debbugs.gnu.org id=B70380.171308883612343 (code B ref 70380); Sun, 14 Apr 2024 10:01:14 +0000 Received: (at 70380) by debbugs.gnu.org; 14 Apr 2024 10:00:36 +0000 Received: from localhost ([127.0.0.1]:34353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rvwew-0003Ad-LI for submit@debbugs.gnu.org; Sun, 14 Apr 2024 06:00:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58214) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rvweh-00037u-Ui for 70380@debbugs.gnu.org; Sun, 14 Apr 2024 06:00:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rvweR-0004K6-G0; Sun, 14 Apr 2024 05:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=xF44QmwF5U/azBZ4mA64AhPN8qVhlTNCuF7TKr0mcB0=; b=Z4x0Fih6KxkpqFoHhrWk UyYLq6a/2rU8Dp4XHUol/U4eLOTFlZ+e6R/QSmRFQ3UygN9J8xbh4JjMk5UISx35H1Lnz4cap7yXN ibwaQq1bUEIYETcsJxNBPw2yzQA/SBveedSKQnZM68zsTkv1rl+mrE+RzTuoay+kNwmTRK7ah2yzq DzD169tU0TNWo/n2agFHsdBnJZ0y0ZBApP/97UxNKkFuySYbX7v4QhfQOp44TDIklpGCEDmYD+ftW +5o7+1Qill1ijeHJUhWb3R2qSWkVDMxzLd6diWy+dVs/mbPjjpwJ4XT8jQsZmIOjzFpdBx5j+n8Eb 9VOMWX9aNUdADg==; From: Janneke Nieuwenhuizen Date: Sun, 14 Apr 2024 11:59:39 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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 | 7 +++ build-aux/mdate-from-git.scm | 88 ++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100755 build-aux/mdate-from-git.scm diff --git a/bootstrap b/bootstrap index de024aeaa5..abd1ed353e 100755 --- a/bootstrap +++ b/bootstrap @@ -25,3 +25,10 @@ for lang in ${langs}; do done exec 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 +cp build-aux/mdate-from-git build-aux/mdate-sh +chmod -wx 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..0abd580460 --- /dev/null +++ b/build-aux/mdate-from-git.scm @@ -0,0 +1,88 @@ +#! /bin/sh +# -*-scheme-*- +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 +;;; +;;; 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 . + +;;;; Commentary: +;;; +;;; Usage: mdate-from-git 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))))) + + +;;; +;;; Entry point. +;;; +(define (main args) + (setenv "LANG" "C") + (setenv "LANGUAGE" "C") + (setenv "LC_TIME" "C") + (setenv "TZ" "UTC0") + (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-y-m (strftime "%-d %B %Y" time))) + (display d-y-m))) + (_ + (format (current-error-port) "Usage: mdate-from-git.scm FILE\n") + (exit 2))))