unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Miguel <rosen644835@gmail.com>
To: 35394@debbugs.gnu.org
Subject: [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters.
Date: Tue, 23 Apr 2019 15:26:20 +0200	[thread overview]
Message-ID: <20190423152620.2b4fa56b@gmail.com> (raw)
In-Reply-To: <20190423151702.05258473@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 626 bytes --]

system: Add locale to boot-parameters.

* gnu/system.scm (<boot-parameters>): New locale field.
(boot-parameters-locale): New accessor.
(read-boot-parameters): Read locale field.
(operating-system-boot-parameters): Add locale to boot-parameters form.
(opeating-system-boot-parameters-file): Add locale to file-like object.
* tests/boot-parameters.scm: New test file.
* Makefile.am (SCM_TESTS): Add tests/boot-parameters.scm.
---
 Makefile.am               |   1 +
 gnu/system.scm            |  19 +++-
 tests/boot-parameters.scm | 232 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+), 4 deletions(-)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-system-Add-locale-to-boot-parameters.patch --]
[-- Type: text/x-patch, Size: 13930 bytes --]

From ca81983f4fcab05472088b181406f21c80441c57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Mon, 22 Apr 2019 14:44:11 +0200
Subject: [PATCH 1/3] system: Add locale to boot-parameters.

* gnu/system.scm (<boot-parameters>): New locale field.
(boot-parameters-locale): New accessor.
(read-boot-parameters): Read locale field.
(operating-system-boot-parameters): Add locale to boot-parameters form.
(opeating-system-boot-parameters-file): Add locale to file-like object.
* tests/boot-parameters.scm: New test file.
* Makefile.am (SCM_TESTS): Add tests/boot-parameters.scm.
---
 Makefile.am               |   1 +
 gnu/system.scm            |  19 +++-
 tests/boot-parameters.scm | 232 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 99d6ed64b6..6e174588db 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -347,6 +347,7 @@ SCM_TESTS =					\
   tests/base16.scm				\
   tests/base32.scm				\
   tests/base64.scm				\
+  tests/boot-parameters.scm			\
   tests/channels.scm				\
   tests/cpan.scm				\
   tests/cpio.scm				\
diff --git a/gnu/system.scm b/gnu/system.scm
index 24243eb707..385d93150c 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Meiyo Peng <meiyo.peng@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -118,6 +119,7 @@
             boot-parameters-kernel
             boot-parameters-kernel-arguments
             boot-parameters-initrd
+            boot-parameters-locale
             read-boot-parameters
             read-boot-parameters-file
             boot-parameters->menu-entry
@@ -251,7 +253,8 @@ directly by the user."
   (store-mount-point boot-parameters-store-mount-point)
   (kernel           boot-parameters-kernel)
   (kernel-arguments boot-parameters-kernel-arguments)
-  (initrd           boot-parameters-initrd))
+  (initrd           boot-parameters-initrd)
+  (locale           boot-parameters-locale))
 
 (define (ensure-not-/dev device)
   "If DEVICE starts with a slash, return #f.  This is meant to filter out
@@ -329,7 +332,12 @@ file system labels."
          (('store ('device _) ('mount-point mount-point) _ ...)
           mount-point)
          (_                                       ;the old format
-          "/")))))
+          "/")))
+
+      (locale
+       (match (assq 'locale rest)
+         ((_ locale) locale)
+         (#f         #f)))))
     (x                                            ;unsupported format
      (warning (G_ "unrecognized boot parameters at '~a'~%")
               (port-filename port))
@@ -973,6 +981,7 @@ parameters of OS.  When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments
 such as '--root' and '--load' to <boot-parameters>."
   (let* ((initrd          (operating-system-initrd-file os))
          (store           (operating-system-store-file-system os))
+         (locale          (operating-system-locale os))
          (bootloader      (bootloader-configuration-bootloader
                            (operating-system-bootloader os)))
          (bootloader-name (bootloader-name bootloader))
@@ -988,7 +997,8 @@ such as '--root' and '--load' to <boot-parameters>."
      (initrd initrd)
      (bootloader-name bootloader-name)
      (store-device (ensure-not-/dev (file-system-device store)))
-     (store-mount-point (file-system-mount-point store)))))
+     (store-mount-point (file-system-mount-point store))
+     (locale locale))))
 
 (define (device->sexp device)
   "Serialize DEVICE as an sexp (really, as an object with a read syntax.)"
@@ -1031,7 +1041,8 @@ being stored into the \"parameters\" file)."
                     (store
                      (device
                       #$(device->sexp (boot-parameters-store-device params)))
-                     (mount-point #$(boot-parameters-store-mount-point params))))
+                     (mount-point #$(boot-parameters-store-mount-point params)))
+                    (locale #$(boot-parameters-locale params)))
                  #:set-load-path? #f)))
 
 (define-gexp-compiler (operating-system-compiler (os <operating-system>)
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
new file mode 100644
index 0000000000..9ec1e6ddd3
--- /dev/null
+++ b/tests/boot-parameters.scm
@@ -0,0 +1,232 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix 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.
+;;;
+;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;;
+;;; Test boot parameters value storage and compatibility.
+;;;
+;;; Code:
+
+(define-module (test-boot-parameters)
+  #:use-module (gnu bootloader)
+  #:use-module (gnu bootloader grub)
+  #:use-module (gnu system)
+  #:use-module (gnu system file-systems)
+  #:use-module (gnu system uuid)
+  #:use-module (guix gexp)
+  #:use-module (guix store)
+  #:use-module (guix tests)
+  #:use-module (srfi srfi-64)
+  #:use-module (rnrs bytevectors))
+
+;; For whitebox testing
+(define operating-system-boot-parameters
+  (@@ (gnu system) operating-system-boot-parameters))
+
+(define %default-label "GNU with Linux-libre 99.1.2")
+(define %default-kernel-path
+  (string-append (%store-prefix)
+                 "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-linux-libre-99.1.2"))
+(define %default-kernel
+  (string-append %default-kernel-path "/" (system-linux-image-file-name)))
+(define %default-kernel-arguments '())
+(define %default-initrd-path
+  (string-append (%store-prefix) "/wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww-initrd"))
+(define %default-initrd (string-append %default-initrd-path "/initrd.cpio.gz"))
+(define %default-root-device (uuid "abcdef12-3456-7890-abcd-ef1234567890"))
+(define %default-store-device (uuid "01234567-89ab-cdef-0123-456789abcdef"))
+(define %default-store-mount-point (%store-prefix))
+(define %default-locale "es_ES.utf8")
+(define %root-path "/")
+
+(define %grub-boot-parameters
+  (boot-parameters
+   (bootloader-name 'grub)
+   (label %default-label)
+   (root-device %default-root-device)
+   (kernel %default-kernel)
+   (kernel-arguments %default-kernel-arguments)
+   (initrd %default-initrd)
+   (store-device %default-store-device)
+   (store-mount-point %default-store-mount-point)
+   (locale %default-locale)))
+
+(define %default-operating-system
+  (operating-system
+    (host-name "host")
+    (timezone "Europe/Berlin")
+    (locale %default-locale)
+
+    (bootloader (bootloader-configuration
+                 (bootloader grub-bootloader)
+                 (target "/dev/sda")))
+    (file-systems (cons* (file-system
+                           (device %default-root-device)
+                           (mount-point %root-path)
+                           (type "ext4"))
+		         (file-system
+                           (device %default-store-device)
+                           (mount-point %default-store-mount-point)
+                           (type "btrfs"))
+                         %base-file-systems))))
+
+(define (quote-uuid uuid)
+  (list 'uuid (uuid-type uuid) (uuid-bytevector uuid)))
+
+(define* (test-read-boot-parameters
+          #:key
+          (version 0)
+          (bootloader-name 'grub)
+          (label %default-label)
+          (root-device (quote-uuid %default-root-device))
+          (kernel %default-kernel)
+          (kernel-arguments %default-kernel-arguments)
+          (initrd %default-initrd)
+          (with-store #t)
+          (store-device
+           (quote-uuid %default-store-device))
+          (store-mount-point %default-store-mount-point)
+          (locale %default-locale))
+  (define (generate-boot-parameters)
+    (define (sexp-or-nothing fmt val)
+      (cond ((eq? 'false val) (format #f fmt #f))
+            (val              (format #f fmt val))
+            (else             "")))
+    (format #f "(boot-parameters ~a~a~a~a~a~a~a~a~a)"
+            (sexp-or-nothing "(version ~S) " version)
+            (sexp-or-nothing "(label ~S) " label)
+            (sexp-or-nothing "(root-device ~S) " root-device)
+            (sexp-or-nothing "(kernel ~S) " kernel)
+            (sexp-or-nothing "(kernel-arguments ~S) " kernel-arguments)
+            (sexp-or-nothing "(initrd ~S) " initrd)
+            (if with-store
+                (format #f "(store ~a~a)"
+                        (sexp-or-nothing "(device ~S) " store-device)
+                        (sexp-or-nothing "(mount-point ~S)" store-mount-point))
+                "")
+            (sexp-or-nothing "(locale ~S) " locale)
+            (sexp-or-nothing "(bootloader-name ~a)" bootloader-name)))
+  (let ((str (generate-boot-parameters)))
+    (call-with-input-string str read-boot-parameters)))
+
+(test-begin "boot-parameters")
+
+;; XXX: <warning: unrecognized boot parameters at '#f'>
+(test-assert "read, construction, mandatory fields"
+  (not (or (test-read-boot-parameters #:version #f)
+           (test-read-boot-parameters #:version 'false)
+           (test-read-boot-parameters #:version -1)
+           (test-read-boot-parameters #:version "0")
+           (test-read-boot-parameters #:root-device #f)
+           (test-read-boot-parameters #:kernel #f)
+           (test-read-boot-parameters #:label #f))))
+
+(test-assert "read, construction, optional fields"
+  (and (test-read-boot-parameters #:bootloader-name #f)
+       (test-read-boot-parameters #:kernel-arguments #f)
+       (test-read-boot-parameters #:with-store #f)
+       (test-read-boot-parameters #:store-device #f)
+       (test-read-boot-parameters #:store-device 'false)
+       (test-read-boot-parameters #:store-mount-point #f)
+       (test-read-boot-parameters #:locale #f)
+       (test-read-boot-parameters #:bootloader-name #f #:kernel-arguments #f
+                                  #:with-store #f #:locale #f)))
+
+;; No default case, match error
+(test-error "read, construction, missing initrd" #t
+            (test-read-boot-parameters #:initrd #f))
+
+(test-equal "read, default equality"
+  %grub-boot-parameters
+  (test-read-boot-parameters))
+
+(test-equal "read, root-device, label"
+  (file-system-label "my-root")
+  (boot-parameters-root-device
+   (test-read-boot-parameters #:root-device '(file-system-label "my-root"))))
+
+(test-equal "read, root-device, /dev node"
+  "/dev/sda2"
+  (boot-parameters-root-device
+   (test-read-boot-parameters #:root-device "/dev/sda2")))
+
+(test-equal "read, kernel, only store path"
+  %default-kernel
+  (boot-parameters-kernel
+   (test-read-boot-parameters #:kernel %default-kernel-path)))
+
+(test-equal "read, initrd, apply concatenation"
+  "/a/b"
+  (boot-parameters-initrd
+   (test-read-boot-parameters #:initrd (list 'string-append "/a" "/b"))))
+
+(test-eq "read, bootloader-name, default value"
+  'grub
+  (boot-parameters-bootloader-name
+   (test-read-boot-parameters #:bootloader-name #f)))
+
+(test-eq "read, kernel-arguments, default value"
+  '()
+  (boot-parameters-kernel-arguments
+   (test-read-boot-parameters #:kernel-arguments #f)))
+
+(test-assert "read, store-device, filter /dev"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:store-device "/dev/sda3"))))
+
+(test-assert "read, no-store, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3" #:with-store #f))))
+
+(test-assert "read, no store-device, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3"
+                                   #:store-device #f))))
+
+(test-assert "read, store-device #f, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3"
+                                   #:store-device 'false))))
+
+(test-equal "read, store-device, label (legacy)"
+  (file-system-label "my-store")
+  (boot-parameters-store-device
+   (test-read-boot-parameters #:store-device "my-store")))
+
+(test-equal "read, store-device, from root"
+  %default-root-device
+  (boot-parameters-store-device
+   (test-read-boot-parameters #:with-store #f)))
+
+(test-equal "read, no store-mount-point, default"
+  %root-path
+  (boot-parameters-store-mount-point
+   (test-read-boot-parameters #:store-mount-point #f)))
+
+(test-equal "read, no store, default store-mount-point"
+  %root-path
+  (boot-parameters-store-mount-point
+   (test-read-boot-parameters #:with-store #f)))
+
+(test-equal "from os, locale"
+  %default-locale
+  (boot-parameters-locale
+   (operating-system-boot-parameters %default-operating-system
+                                     %default-root-device)))
+
+(test-end "boot-parameters")
-- 
2.21.0


  reply	other threads:[~2019-04-23 13:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
2019-04-23 13:26 ` Miguel [this message]
2019-04-23 13:26 ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel
2019-04-23 13:26 ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel
2019-04-26 10:50 ` [bug#35394] [PATCH 3/4] gnu: grub: Add locale output for bootloading Miguel
2019-05-03 12:27   ` Miguel
2019-04-26 10:51 ` [bug#35394] [PATCH 4/4] system: Use locale information in grub.cfg Miguel
2019-05-03 12:27   ` Miguel
2019-04-29  7:56 ` [bug#35394] [PATCH 0/3] Bootloader localization Ludovic Courtès
     [not found]   ` <20191021124035.531bed75@gmail.com>
2019-10-21 10:46     ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel Arruga Vivas
2019-10-21 10:46     ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel Arruga Vivas
2019-10-21 10:46     ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel Arruga Vivas
2020-10-11 14:18 ` [bug#35394] [PATCH 1/1 v4] Grub i18n Miguel Ángel Arruga Vivas
2020-10-17 16:32   ` Ludovic Courtès
2020-10-18 15:09     ` [bug#35394] [PATCH 4/4 " Miguel Ángel Arruga Vivas
2020-10-18 15:43       ` Miguel Ángel Arruga Vivas
2020-10-19  8:50         ` Ludovic Courtès
2020-10-19 11:41           ` Miguel Ángel Arruga Vivas
2020-10-19 13:21             ` Ludovic Courtès
2020-10-19 13:44               ` Miguel Ángel Arruga Vivas
2020-10-20 20:50                 ` Ludovic Courtès
2020-10-20 21:19                   ` bug#35394: " Miguel Ángel Arruga Vivas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190423152620.2b4fa56b@gmail.com \
    --to=rosen644835@gmail.com \
    --cc=35394@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).