grafts: Run with a UTF-8 locale.

Fixes <https://issues.guix.gnu.org/55968>.
Reported by Maxime Devos <maximedevos@telenet.be>.

* guix/grafts.scm (%graft-with-utf8-locale?): New parameter.
(graft-derivation/shallow)[glibc-locales, set-utf8-locale]: New
variables.
[build]: Use 'set-utf8-locale'.
* tests/gexp.scm, tests/grafts.scm, tests/packages.scm: Set
'%graft-with-utf8-locale?' to #f.
This commit is contained in:
Ludovic Courtès 2022-11-10 18:20:23 +01:00
parent 8c0c223fab
commit 19206eee69
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
4 changed files with 34 additions and 2 deletions

View file

@ -40,7 +40,9 @@ (define-module (guix grafts)
graft-replacement-output graft-replacement-output
graft-derivation graft-derivation
graft-derivation/shallow) graft-derivation/shallow
%graft-with-utf8-locale?)
#:re-export (%graft? ;for backward compatibility #:re-export (%graft? ;for backward compatibility
without-grafting without-grafting
set-grafting set-grafting
@ -79,6 +81,12 @@ (define (graft-origin-file-name graft)
(($ <graft> (? string? item)) (($ <graft> (? string? item))
item))) item)))
(define %graft-with-utf8-locale?
;; Whether to install a UTF-8 locale for grafting. This parameter exists
;; for the sole purpose of being able to run tests without having to build
;; 'glibc-utf8-locales'.
(make-parameter #t))
(define* (graft-derivation/shallow drv grafts (define* (graft-derivation/shallow drv grafts
#:key #:key
(name (derivation-name drv)) (name (derivation-name drv))
@ -88,6 +96,10 @@ (define* (graft-derivation/shallow drv grafts
"Return a derivation called NAME, which applies GRAFTS to the specified "Return a derivation called NAME, which applies GRAFTS to the specified
OUTPUTS of DRV. This procedure performs \"shallow\" grafting in that GRAFTS OUTPUTS of DRV. This procedure performs \"shallow\" grafting in that GRAFTS
are not recursively applied to dependencies of DRV." are not recursively applied to dependencies of DRV."
(define glibc-locales
(module-ref (resolve-interface '(gnu packages commencement))
'glibc-utf8-locales-final))
(define mapping (define mapping
;; List of store item pairs. ;; List of store item pairs.
(map (lambda (graft) (map (lambda (graft)
@ -98,6 +110,15 @@ (define mapping
(graft-replacement-output graft))))) (graft-replacement-output graft)))))
grafts)) grafts))
(define set-utf8-locale
(and (%graft-with-utf8-locale?)
#~(begin
;; Let Guile interpret file names as UTF-8.
(setenv "GUIX_LOCPATH"
#+(file-append glibc-locales "/lib/locale"))
(setlocale LC_ALL "en_US.utf8"))))
(define build (define build
(with-imported-modules '((guix build graft) (with-imported-modules '((guix build graft)
(guix build utils) (guix build utils)
@ -111,6 +132,7 @@ (define build
(define %outputs (define %outputs
(ungexp (outputs->gexp outputs))) (ungexp (outputs->gexp outputs)))
#+set-utf8-locale
(let* ((old-outputs '(ungexp (let* ((old-outputs '(ungexp
(map (lambda (output) (map (lambda (output)
(gexp ((ungexp output) (gexp ((ungexp output)

View file

@ -21,6 +21,7 @@ (define-module (test-gexp)
#:use-module (guix store) #:use-module (guix store)
#:use-module (guix monads) #:use-module (guix monads)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module ((guix grafts) #:select (%graft-with-utf8-locale?))
#:use-module (guix derivations) #:use-module (guix derivations)
#:use-module (guix packages) #:use-module (guix packages)
#:use-module (guix build-system trivial) #:use-module (guix build-system trivial)
@ -49,6 +50,9 @@ (define %store
;; Globally disable grafts because they can trigger early builds. ;; Globally disable grafts because they can trigger early builds.
(%graft? #f) (%graft? #f)
;; When grafting, do not add dependency on 'glibc-utf8-locales'.
(%graft-with-utf8-locale? #f)
;; For white-box testing. ;; For white-box testing.
(define (gexp-inputs x) (define (gexp-inputs x)
((@@ (guix gexp) gexp-inputs) x)) ((@@ (guix gexp) gexp-inputs) x))

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2014-2019, 2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2021 Mark H Weaver <mhw@netris.org> ;;; Copyright © 2021 Mark H Weaver <mhw@netris.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
@ -35,6 +35,9 @@ (define-module (test-grafts)
(define %store (define %store
(open-connection-for-tests)) (open-connection-for-tests))
;; When grafting, do not add dependency on 'glibc-utf8-locales'.
(%graft-with-utf8-locale? #f)
(define (bootstrap-binary name) (define (bootstrap-binary name)
(let ((bin (search-bootstrap-binary name (%current-system)))) (let ((bin (search-bootstrap-binary name (%current-system))))
(and %store (and %store

View file

@ -75,6 +75,9 @@ (define %store
;; can trigger builds early.) ;; can trigger builds early.)
(%graft? #f) (%graft? #f)
;; When grafting, do not add dependency on 'glibc-utf8-locales'.
(%graft-with-utf8-locale? #f)
(test-begin "packages") (test-begin "packages")