diff options
| author | Janneke Nieuwenhuizen <janneke@gnu.org> | 2024-04-05 23:21:02 +0200 |
|---|---|---|
| committer | Janneke Nieuwenhuizen <janneke@gnu.org> | 2024-04-14 10:29:11 +0200 |
| commit | 6c63c366776643e5831c50a2b7e29bad93273327 (patch) | |
| tree | c6b431a19695abcc4205906fe574a2cba5eb8392 /build-aux | |
| parent | b4d2838d511f8fc94458358938493b5a1646d8f7 (diff) | |
maint: Use xgettext.scm wrapper to create .PO files reproducibly.
* 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
Diffstat (limited to 'build-aux')
| -rwxr-xr-x | build-aux/xgettext.scm | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/build-aux/xgettext.scm b/build-aux/xgettext.scm new file mode 100755 index 00000000000..e8a970f251c --- /dev/null +++ b/build-aux/xgettext.scm | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | #! /bin/sh | ||
| 2 | # -*-scheme-*- | ||
| 3 | build_aux=$(dirname $0) | ||
| 4 | srcdir=$build_aux/.. | ||
| 5 | exec guile --no-auto-compile -L $srcdir -C $srcdir -e main -s "$0" "$@" | ||
| 6 | !# | ||
| 7 | |||
| 8 | ;;; Copyright © 2024 Janneke Nieuwenhuizen <janneke@gnu.org> | ||
| 9 | ;;; | ||
| 10 | ;;; This program is free software; you can redistribute it and/or modify it | ||
| 11 | ;;; under the terms of the GNU General Public License as published by | ||
| 12 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 13 | ;;; your option) any later version. | ||
| 14 | ;;; | ||
| 15 | ;;; This program is distributed in the hope that it will be useful, but | ||
| 16 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;;; GNU General Public License for more details. | ||
| 19 | ;;; | ||
| 20 | ;;; You should have received a copy of the GNU General Public License | ||
| 21 | ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;;; Commentary: | ||
| 24 | ;;; | ||
| 25 | ;;; This script provides an xgettext wrapper to (re)set POT-Creation-Date from | ||
| 26 | ;;; a Git timestamp. Test doing something like: | ||
| 27 | ;;; | ||
| 28 | ;;; build-aux/xgettext.scm --files-from=po/guix/POTFILES.in --default-domain=test | ||
| 29 | ;;; | ||
| 30 | ;;;; Code: | ||
| 31 | |||
| 32 | (use-modules (srfi srfi-1) | ||
| 33 | (srfi srfi-26) | ||
| 34 | (ice-9 curried-definitions) | ||
| 35 | (ice-9 match) | ||
| 36 | (ice-9 popen) | ||
| 37 | (ice-9 rdelim) | ||
| 38 | (guix build utils)) | ||
| 39 | |||
| 40 | (define ((option? name) option) | ||
| 41 | (string-prefix? name option)) | ||
| 42 | |||
| 43 | (define (get-option args name) | ||
| 44 | (let ((option (find (option? name) args))) | ||
| 45 | (and option | ||
| 46 | (substring option (string-length name))))) | ||
| 47 | |||
| 48 | (define (pipe-command command) | ||
| 49 | (let* ((port (apply open-pipe* OPEN_READ command)) | ||
| 50 | (output (read-string port))) | ||
| 51 | (close-port port) | ||
| 52 | output)) | ||
| 53 | |||
| 54 | |||
| 55 | ;;; | ||
| 56 | ;;; Entry point. | ||
| 57 | ;;; | ||
| 58 | (define (main args) | ||
| 59 | ;; Cater for being run in a container. | ||
| 60 | (setenv "LC_ALL" "en_US.UTF-8") | ||
| 61 | (setenv "TZ" "UTC0") | ||
| 62 | (fluid-set! %default-port-encoding #f) | ||
| 63 | (let* ((files-from (get-option args "--files-from=")) | ||
| 64 | (default-domain (get-option args "--default-domain=")) | ||
| 65 | (directory (or (get-option args "--directory=") ".")) | ||
| 66 | (xgettext (or (get-option args "--xgettext=") "xgettext")) | ||
| 67 | (xgettext-args (filter (negate (option? "--xgettext=")) args)) | ||
| 68 | (command (match xgettext-args | ||
| 69 | ((xgettext.scm args ...) | ||
| 70 | `(,xgettext ,@args)))) | ||
| 71 | (result (apply system* command)) | ||
| 72 | (status (/ result 256))) | ||
| 73 | (if (or (not (zero? status)) | ||
| 74 | (not files-from)) | ||
| 75 | (exit status) | ||
| 76 | (let* ((text (with-input-from-file files-from read-string)) | ||
| 77 | (lines (string-split text #\newline)) | ||
| 78 | (files (filter (negate (cute string-prefix? "#" <>)) lines)) | ||
| 79 | (files (map (cute string-append directory "/" <>) files)) | ||
| 80 | (git-command `("git" "log" "--pretty=format:%ci" "-n1" ,@files)) | ||
| 81 | (timestamp (pipe-command git-command)) | ||
| 82 | (po-file (string-append default-domain ".po"))) | ||
| 83 | (when (string-null? timestamp) | ||
| 84 | (exit 1)) | ||
| 85 | (substitute* po-file | ||
| 86 | (("(\"POT-Creation-Date: )[^\\]*" all header) | ||
| 87 | (string-append header timestamp))))))) | ||
