From patchwork Sat Apr 6 21:17:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janneke Nieuwenhuizen X-Patchwork-Id: 62787 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 AFC5827BBE9; Sat, 6 Apr 2024 22:19:14 +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=unavailable 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 9B1EF27BBE2 for ; Sat, 6 Apr 2024 22:19:12 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtDRL-0000R6-4u; Sat, 06 Apr 2024 17:19:07 -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 1rtDRG-0000Oj-T7 for guix-patches@gnu.org; Sat, 06 Apr 2024 17:19:03 -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 1rtDRF-0004TF-Vf for guix-patches@gnu.org; Sat, 06 Apr 2024 17:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rtDRK-0000a0-EM; Sat, 06 Apr 2024 17:19:06 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70169] [PATCH v2 07/12] maint: Use xgettext.scm wrapper to create .PO files reproducibly. Resent-From: Janneke Nieuwenhuizen Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, julien@lepiller.eu, guix-patches@gnu.org Resent-Date: Sat, 06 Apr 2024 21:19:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70169@debbugs.gnu.org Cc: Florian Pelz , Julien Lepiller X-Debbugs-Original-Xcc: Florian Pelz , Julien Lepiller Received: via spool by 70169-submit@debbugs.gnu.org id=B70169.17124383221992 (code B ref 70169); Sat, 06 Apr 2024 21:19:06 +0000 Received: (at 70169) by debbugs.gnu.org; 6 Apr 2024 21:18:42 +0000 Received: from localhost ([127.0.0.1]:41133 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rtDQu-0000Vq-QT for submit@debbugs.gnu.org; Sat, 06 Apr 2024 17:18:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53958) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rtDQk-0000Sr-9W for 70169@debbugs.gnu.org; Sat, 06 Apr 2024 17:18:32 -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 1rtDQY-0004Hg-JJ; Sat, 06 Apr 2024 17:18:18 -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=5f51ZRcnHNEpCFQtNyXonoM9juLiNt3lIbdge0bzb7s=; b=PbrZdlgqPi3q2xQNVv8K gGRhaNeC4uLd6LGSWH8vLWNEeKXmRO5EkglDJTTjiX3tX0Rkp6ev+ck3LuW4m42GclTtDNoTFsa43 433socCr1XHmTJmnQg60LCc+phhpJwDX9QmwdcCuZ+9BJlbp/R6ULvib4SAzufg40yceymoPXLgP5 ghgm7Hpq/m36JSEVCRTXQgZrwp7sORlGL5cvP2iOjuc8vo4pxbedY//kWMsaZSXKgI+cii2qdRsOM vDAewcZZOk1rz1xpmiEoPc1TFN4dQFJ8iSOamQC4fyCaa5YkdLuDWipAjKrame156rx39ZXWCY65j /iDt+Uq5kjb+Cw==; From: Janneke Nieuwenhuizen Date: Sat, 6 Apr 2024 23:17:59 +0200 Message-ID: <83a27ee0460886ac9802caa34addd8d111acf68a.1712437365.git.janneke@gnu.org> 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 * build-aux/xgettext.scm: New script. * po/guix/Makevars (XGETTEXT): Set it. (XGETTEXT_OPTIONS): Add --xgettext option to `real' xgettext. * po/packages/Makevars (XGETTEXT): Set it. (XGETTEXT_OPTIONS): Add --xgettext option to `real' xgettext. Change-Id: I71b6b843970090f765f46ac346b92a346560e3f0 --- build-aux/xgettext.scm | 87 ++++++++++++++++++++++++++++++++++++++++++ po/guix/Makevars | 7 +++- po/packages/Makevars | 10 ++++- 3 files changed, 101 insertions(+), 3 deletions(-) create mode 100755 build-aux/xgettext.scm diff --git a/build-aux/xgettext.scm b/build-aux/xgettext.scm new file mode 100755 index 0000000000..e8a970f251 --- /dev/null +++ b/build-aux/xgettext.scm @@ -0,0 +1,87 @@ +#! /bin/sh +# -*-scheme-*- +build_aux=$(dirname $0) +srcdir=$build_aux/.. +exec guile --no-auto-compile -L $srcdir -C $srcdir -e main -s "$0" "$@" +!# + +;;; Copyright © 2024 Janneke Nieuwenhuizen +;;; +;;; 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: +;;; +;;; This script provides an xgettext wrapper to (re)set POT-Creation-Date from +;;; a Git timestamp. Test doing something like: +;;; +;;; build-aux/xgettext.scm --files-from=po/guix/POTFILES.in --default-domain=test +;;; +;;;; Code: + +(use-modules (srfi srfi-1) + (srfi srfi-26) + (ice-9 curried-definitions) + (ice-9 match) + (ice-9 popen) + (ice-9 rdelim) + (guix build utils)) + +(define ((option? name) option) + (string-prefix? name option)) + +(define (get-option args name) + (let ((option (find (option? name) args))) + (and option + (substring option (string-length name))))) + +(define (pipe-command command) + (let* ((port (apply open-pipe* OPEN_READ command)) + (output (read-string port))) + (close-port port) + output)) + + +;;; +;;; Entry point. +;;; +(define (main args) + ;; Cater for being run in a container. + (setenv "LC_ALL" "en_US.UTF-8") + (setenv "TZ" "UTC0") + (fluid-set! %default-port-encoding #f) + (let* ((files-from (get-option args "--files-from=")) + (default-domain (get-option args "--default-domain=")) + (directory (or (get-option args "--directory=") ".")) + (xgettext (or (get-option args "--xgettext=") "xgettext")) + (xgettext-args (filter (negate (option? "--xgettext=")) args)) + (command (match xgettext-args + ((xgettext.scm args ...) + `(,xgettext ,@args)))) + (result (apply system* command)) + (status (/ result 256))) + (if (or (not (zero? status)) + (not files-from)) + (exit status) + (let* ((text (with-input-from-file files-from read-string)) + (lines (string-split text #\newline)) + (files (filter (negate (cute string-prefix? "#" <>)) lines)) + (files (map (cute string-append directory "/" <>) files)) + (git-command `("git" "log" "--pretty=format:%ci" "-n1" ,@files)) + (timestamp (pipe-command git-command)) + (po-file (string-append default-domain ".po"))) + (when (string-null? timestamp) + (exit 1)) + (substitute* po-file + (("(\"POT-Creation-Date: )[^\\]*" all header) + (string-append header timestamp))))))) diff --git a/po/guix/Makevars b/po/guix/Makevars index 88a4e8c7bc..4cfd0f431d 100644 --- a/po/guix/Makevars +++ b/po/guix/Makevars @@ -5,6 +5,10 @@ DOMAIN = guix subdir = po/guix top_builddir = ../.. +# We use our xgettext.scm wrapper to produce .PO files reproducibly using a +# timestamp from Git. +XGETTEXT:=$(top_srcdir)/build-aux/xgettext.scm + # These options get passed to xgettext. We want to catch standard # gettext uses, and SRFI-35 error condition messages. In C++ code # we use 'n_' instead of the more usual 'N_' for no-ops. @@ -14,7 +18,8 @@ XGETTEXT_OPTIONS = \ --keyword=message \ --keyword=description \ --keyword=synopsis \ - --keyword=n_ + --keyword=n_ \ + --xgettext=$(XGETTEXT_) COPYRIGHT_HOLDER = the authors of Guix (msgids) diff --git a/po/packages/Makevars b/po/packages/Makevars index 65912786d8..0ba4f1ba7e 100644 --- a/po/packages/Makevars +++ b/po/packages/Makevars @@ -6,12 +6,18 @@ DOMAIN = guix-packages subdir = po/packages top_builddir = ../.. +# We use our xgettext.scm wrapper to produce .PO files reproducibly using a +# timestamp from Git. The `real' xgettext is passed as an option to +# xgettext.scm +XGETTEXT:=$(top_srcdir)/build-aux/xgettext.scm + # These options get passed to xgettext. We want to catch exclusively package # synopses and descriptions. XGETTEXT_OPTIONS = \ --language=Scheme --from-code=UTF-8 \ - --keyword=synopsis --keyword=description \ - --keyword=output-synopsis:2 + --keyword=synopsis --keyword=description \ + --keyword=output-synopsis:2 \ + --xgettext=$(XGETTEXT_) COPYRIGHT_HOLDER = the authors of Guix (msgids)