From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#22629: [PATCH 3/4] self: Compute and use locale data. Date: Thu, 31 May 2018 16:43:36 +0200 Message-ID: <20180531144337.16298-4-ludo@gnu.org> References: <87fu45ve2z.fsf@gnu.org> <20180531144337.16298-1-ludo@gnu.org> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOOp8-0000ec-J2 for bug-guix@gnu.org; Thu, 31 May 2018 10:45:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOOp5-0004gF-Kr for bug-guix@gnu.org; Thu, 31 May 2018 10:45:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:48225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOOp5-0004ft-HS for bug-guix@gnu.org; Thu, 31 May 2018 10:45:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fOOp5-0006C8-A7 for bug-guix@gnu.org; Thu, 31 May 2018 10:45:03 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20180531144337.16298-1-ludo@gnu.org> List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: 22629@debbugs.gnu.org * guix/self.scm (locale-data): New procedure. (guix-command): Add SOURCE parameter. Call 'locale-data' when SOURCE is true and use it in staged 'bindtextdomain' calls. (whole-package): Add #:command and honor it. (compiled-guix): Pass #:command to 'whole-package'. --- guix/self.scm | 101 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/guix/self.scm b/guix/self.scm index f0641c342..92e69ffd5 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -190,7 +190,47 @@ list of file-name/file-like objects suitable as inputs to 'imported-files'." (file-name->module-name (string-drop file prefix))) (scheme-files (string-append directory "/" sub-directory))))) -(define* (guix-command modules #:key (dependencies '()) +(define* (locale-data source domain + #:optional (sub-directory domain)) + "Return the locale data from 'po/SUB-DIRECTORY' in SOURCE, corresponding to +DOMAIN, a gettext domain." + (define gettext + (module-ref (resolve-interface '(gnu packages gettext)) + 'gettext-minimal)) + + (define build + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (srfi srfi-26) + (ice-9 match) (ice-9 ftw)) + + (define po-directory + (string-append #$source "/po/" #$sub-directory)) + + (define (compile language) + (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/" + #$domain ".mo"))) + (mkdir-p (dirname gmo)) + (invoke #+(file-append gettext "/bin/msgfmt") + "-c" "--statistics" "--verbose" + "-o" gmo + (string-append po-directory "/" language ".po")))) + + (define (linguas) + ;; Return the list of languages. Note: don't read 'LINGUAS' + ;; because it contains things like 'en@boldquot' that do not have + ;; a corresponding .po file. + (map (cut basename <> ".po") + (scandir po-directory + (cut string-suffix? ".po" <>)))) + + (for-each compile (linguas))))) + + (computed-file (string-append "guix-locale-" domain) + build)) + +(define* (guix-command modules #:key source (dependencies '()) (guile-version (effective-version))) "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its load path." @@ -218,35 +258,43 @@ load path." (let ((guix-main (module-ref (resolve-interface '(guix ui)) 'guix-main))) - ;; TODO: Compute locale data. - ;; (bindtextdomain "guix" "@localedir@") - ;; (bindtextdomain "guix-packages" "@localedir@") + #$(if source + #~(begin + (bindtextdomain "guix" + #$(locale-data source "guix")) + (bindtextdomain "guix-packages" + #$(locale-data source + "guix-packages" + "packages"))) + #t) ;; XXX: It would be more convenient to change it to: ;; (exit (apply guix-main (command-line))) (apply guix-main (command-line)))))) (define* (whole-package name modules dependencies - #:key (guile-version (effective-version))) + #:key + (guile-version (effective-version)) + (command (guix-command modules + #:dependencies dependencies + #:guile-version guile-version))) "Return the whole Guix package NAME that uses MODULES, a derivation of all -the modules, and DEPENDENCIES, a list of packages depended on." - (let ((command (guix-command modules - #:dependencies dependencies - #:guile-version guile-version))) - ;; TODO: Move compiled modules to 'lib/guile' instead of 'share/guile'. - (computed-file name - (with-imported-modules '((guix build utils)) - #~(begin - (use-modules (guix build utils)) - (mkdir-p (string-append #$output "/bin")) - (symlink #$command - (string-append #$output "/bin/guix")) +the modules, and DEPENDENCIES, a list of packages depended on. COMMAND is the +'guix' program to use." + ;; TODO: Move compiled modules to 'lib/guile' instead of 'share/guile'. + (computed-file name + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (mkdir-p (string-append #$output "/bin")) + (symlink #$command + (string-append #$output "/bin/guix")) - (let ((modules (string-append #$output - "/share/guile/site/" - (effective-version)))) - (mkdir-p (dirname modules)) - (symlink #$modules modules))))))) + (let ((modules (string-append #$output + "/share/guile/site/" + (effective-version)))) + (mkdir-p (dirname modules)) + (symlink #$modules modules)))))) (define* (compiled-guix source #:key (version %guix-version) (pull-version 1) @@ -423,8 +471,13 @@ the modules, and DEPENDENCIES, a list of packages depended on." ;; Version 1 is when we return the full package. (cond ((= 1 pull-version) ;; The whole package, with a standard file hierarchy. - (whole-package name built-modules dependencies - #:guile-version guile-version)) + (let ((command (guix-command built-modules + #:source source + #:dependencies dependencies + #:guile-version guile-version))) + (whole-package name built-modules dependencies + #:command command + #:guile-version guile-version))) ((= 0 pull-version) ;; Legacy 'guix pull': just return the compiled modules. built-modules) -- 2.17.0