summaryrefslogtreecommitdiff
path: root/build-aux/xgettext.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-04-19 13:17:08 +0100
committerChristopher Baines <mail@cbaines.net>2024-04-19 13:52:11 +0100
commit5fec94f3a3d4c67b748f11847064ed60d67c5ade (patch)
tree9f2c7a21ad8f2c061a8d46aac817e4c68d307086 /build-aux/xgettext.scm
parent6931ca9baaaee4c7e85cf3cd5d0f7e4eb5cfd88e (diff)
parent949f97f7f98ac74306b9de79c93790337d804e32 (diff)
Merge remote-tracking branch 'savannah/master' into core-updates
Change-Id: I4f15bcb3e575062c4dd3b6c07a48470300413f24 Conflicts: gnu/local.mk gnu/packages/bioinformatics.scm gnu/packages/dictionaries.scm gnu/packages/display-managers.scm gnu/packages/engineering.scm gnu/packages/geo.scm gnu/packages/gl.scm gnu/packages/glib.scm gnu/packages/gnome-xyz.scm gnu/packages/gnome.scm gnu/packages/gtk.scm gnu/packages/image-processing.scm gnu/packages/linux.scm gnu/packages/mail.scm gnu/packages/patches/eudev-rules-directory.patch gnu/packages/plotutils.scm gnu/packages/sdl.scm gnu/packages/syndication.scm
Diffstat (limited to 'build-aux/xgettext.scm')
-rwxr-xr-xbuild-aux/xgettext.scm90
1 files changed, 90 insertions, 0 deletions
diff --git a/build-aux/xgettext.scm b/build-aux/xgettext.scm
new file mode 100755
index 0000000000..44d30b8149
--- /dev/null
+++ b/build-aux/xgettext.scm
@@ -0,0 +1,90 @@
+#! /bin/sh
+# -*-scheme-*-
+build_aux=$(dirname $0)
+srcdir=$build_aux/..
+exec guile --no-auto-compile -L $srcdir -C $srcdir -e main -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:
+;;;
+;;; 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)))))))