unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package
@ 2023-01-14  3:05 Maxim Cournoyer
  2023-01-14  3:08 ` [bug#60802] [PATCH 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-14  3:05 UTC (permalink / raw)
  To: 60802
  Cc: Josselin Poiret, Tobias Geerinckx-Rice, Maxim Cournoyer,
	Simon Tournier, Mathieu Othacehe, Ludovic Courtès,
	Christopher Baines, Ricardo Wurmus

The package was causing issues when migrating the make-u-boot-package
procedure to use Guix's infrastructure for cross-compilation, because Guix
would now attempt to build a cross-compiler for mips64el, which is not
supported per (guix platforms).


Maxim Cournoyer (2):
  platforms: Raise an exception when no suitable platform is found.
  gnu: Remove u-boot-malta.

 gnu/packages/bootloaders.scm |  3 ---
 gnu/packages/bootstrap.scm   |  2 +-
 guix/platform.scm            | 44 ++++++++++++++++++++++++++----------
 3 files changed, 33 insertions(+), 16 deletions(-)


base-commit: 4913ac74915c4229aeb3ca26a5f9920c759fb6a3
-- 
2.38.1





^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-14  3:05 [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
@ 2023-01-14  3:08 ` Maxim Cournoyer
  2023-01-14  3:08   ` [bug#60802] [PATCH 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
  2023-01-14  4:19 ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-14  3:08 UTC (permalink / raw)
  To: 60802
  Cc: Josselin Poiret, Tobias Geerinckx-Rice, Maxim Cournoyer,
	Simon Tournier, Mathieu Othacehe, Ludovic Courtès,
	Christopher Baines, Ricardo Wurmus

This was motivated by #60786, which produced a cryptic, hard to understand
backtrace.

* guix/platform.scm (&platform-not-found-error): New exception type.
(make-platform-not-found-error): New exception constructor.
(platform-not-found-error?): New predicate.
(lookup-platform-by-system): Raise an exception when no platform is found.
Update documentation.
(lookup-platform-by-target): Likewise.
(lookup-platform-by-target-or-system): Likewise.
---

 gnu/packages/bootstrap.scm |  2 +-
 guix/platform.scm          | 44 +++++++++++++++++++++++++++-----------
 2 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm
index d2914fb5a7..772be7e5e4 100644
--- a/gnu/packages/bootstrap.scm
+++ b/gnu/packages/bootstrap.scm
@@ -315,7 +315,7 @@ (define* (glibc-dynamic-linker
                                  (%current-system))))
   "Return the name of Glibc's dynamic linker for SYSTEM."
   ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
-  (let ((platform (lookup-platform-by-system system)))
+  (let ((platform (false-if-exception (lookup-platform-by-system system))))
     (cond
      ((platform? platform)
       (platform-glibc-dynamic-linker platform))
diff --git a/guix/platform.scm b/guix/platform.scm
index f873913fe0..c2be66e227 100644
--- a/guix/platform.scm
+++ b/guix/platform.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
+;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -21,6 +22,7 @@ (define-module (guix platform)
   #:use-module (guix memoization)
   #:use-module (guix records)
   #:use-module (guix ui)
+  #:use-module (ice-9 exceptions)
   #:use-module (srfi srfi-1)
   #:export (platform
             platform?
@@ -29,6 +31,10 @@ (define-module (guix platform)
             platform-linux-architecture
             platform-glibc-dynamic-linker
 
+            &platform-not-found-error
+            make-platform-not-found-error
+            platform-not-found-error?
+
             platform-modules
             platforms
             lookup-platform-by-system
@@ -70,6 +76,14 @@ (define-record-type* <platform> platform make-platform
                         (default #false))
   (glibc-dynamic-linker platform-glibc-dynamic-linker))
 
+\f
+;;;
+;;; Exception types.
+;;;
+(define-exception-type &platform-not-found-error &error
+  make-platform-not-found-error platform-not-found-error?)
+
+
 \f
 ;;;
 ;;; Platforms.
@@ -94,23 +108,29 @@ (define platforms
                                    (platform-modules)))))
 
 (define (lookup-platform-by-system system)
-  "Return the platform corresponding to the given SYSTEM."
-  (find (lambda (platform)
-          (let ((s (platform-system platform)))
-            (and (string? s) (string=? s system))))
-        (platforms)))
+  "Return the platform corresponding to the given SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((s (platform-system platform)))
+                (and (string? s) (string=? s system))))
+            (platforms))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (lookup-platform-by-target target)
-  "Return the platform corresponding to the given TARGET."
-  (find (lambda (platform)
-          (let ((t (platform-target platform)))
-            (and (string? t) (string=? t target))))
-        (platforms)))
+  "Return the platform corresponding to the given TARGET.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((t (platform-target platform)))
+                (and (string? t) (string=? t target))))
+            (platforms))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (lookup-platform-by-target-or-system target-or-system)
-  "Return the platform corresponding to the given TARGET or SYSTEM."
+  "Return the platform corresponding to the given TARGET or SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
   (or (lookup-platform-by-target target-or-system)
-      (lookup-platform-by-system target-or-system)))
+      (lookup-platform-by-system target-or-system)
+      (raise-exception (make-platform-not-found-error))))
 
 (define (platform-system->target system)
   "Return the target matching the given SYSTEM if it exists or false
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH 2/2] gnu: Remove u-boot-malta.
  2023-01-14  3:08 ` [bug#60802] [PATCH 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
@ 2023-01-14  3:08   ` Maxim Cournoyer
  0 siblings, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-14  3:08 UTC (permalink / raw)
  To: 60802; +Cc: Maxim Cournoyer

Relates to <https://issues.guix.gnu.org/60786>.

The mips64el architecture is not currently supported, causing (guix platform)
to raise an exception when attempting to cross-build the package.

* gnu/packages/bootloaders.scm (u-boot-malta): Delete variable.

---

 gnu/packages/bootloaders.scm | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 6e6bdb4c08..8dc6ff698d 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -965,9 +965,6 @@ (define*-public (make-u-boot-package board triplet
                   uboot-files)
                  #t)))))))))
 
-(define-public u-boot-malta
-  (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
-
 (define-public u-boot-am335x-boneblack
   (let ((base (make-u-boot-package
                "am335x_evm" "arm-linux-gnueabihf"
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-14  3:05 [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
  2023-01-14  3:08 ` [bug#60802] [PATCH 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
@ 2023-01-14  4:19 ` Maxim Cournoyer
  2023-01-14  4:19   ` [bug#60802] [PATCH v2 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
                     ` (2 more replies)
  2023-01-14 15:14 ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
  2023-01-17 15:34 ` [bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
  3 siblings, 3 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-14  4:19 UTC (permalink / raw)
  To: 60802
  Cc: Josselin Poiret, Tobias Geerinckx-Rice, Maxim Cournoyer,
	Simon Tournier, Mathieu Othacehe, Ludovic Courtès,
	Christopher Baines, Ricardo Wurmus

This was motivated by #60786, which produced a cryptic, hard to understand
backtrace.

* guix/platform.scm (&platform-not-found-error): New exception type.
(make-platform-not-found-error): New exception constructor.
(platform-not-found-error?): New predicate.
(false-if-platform-not-found): New syntax.
(lookup-platform-by-system): Raise an exception when no platform is found.
Update documentation.
(lookup-platform-by-target): Likewise.
(lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
false-if-platform-not-found.

---

Changes in v2:
- Add false-if-platform-not-found syntax
- Use it while evaluating lookup-platform-by-target-or-system

 gnu/packages/bootstrap.scm |  2 +-
 guix/platform.scm          | 51 ++++++++++++++++++++++++++++----------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm
index d2914fb5a7..772be7e5e4 100644
--- a/gnu/packages/bootstrap.scm
+++ b/gnu/packages/bootstrap.scm
@@ -315,7 +315,7 @@ (define* (glibc-dynamic-linker
                                  (%current-system))))
   "Return the name of Glibc's dynamic linker for SYSTEM."
   ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
-  (let ((platform (lookup-platform-by-system system)))
+  (let ((platform (false-if-exception (lookup-platform-by-system system))))
     (cond
      ((platform? platform)
       (platform-glibc-dynamic-linker platform))
diff --git a/guix/platform.scm b/guix/platform.scm
index f873913fe0..2e61c6827a 100644
--- a/guix/platform.scm
+++ b/guix/platform.scm
@@ -21,6 +21,7 @@ (define-module (guix platform)
   #:use-module (guix memoization)
   #:use-module (guix records)
   #:use-module (guix ui)
+  #:use-module (ice-9 exceptions)
   #:use-module (srfi srfi-1)
   #:export (platform
             platform?
@@ -29,6 +30,11 @@ (define-module (guix platform)
             platform-linux-architecture
             platform-glibc-dynamic-linker
 
+            &platform-not-found-error
+            make-platform-not-found-error
+            platform-not-found-error?
+            false-if-platform-not-found
+
             platform-modules
             platforms
             lookup-platform-by-system
@@ -70,6 +76,19 @@ (define-record-type* <platform> platform make-platform
                         (default #false))
   (glibc-dynamic-linker platform-glibc-dynamic-linker))
 
+\f
+;;;
+;;; Exceptions.
+;;;
+(define-exception-type &platform-not-found-error &error
+  make-platform-not-found-error platform-not-found-error?)
+
+(define-syntax-rule (false-if-platform-not-found exp)
+  "Evaluate EXP but return #f if it raises a platform-not-found-error?
+exception."
+  (guard (ex ((platform-not-found-error? ex) #f))
+    exp))
+
 \f
 ;;;
 ;;; Platforms.
@@ -94,23 +113,29 @@ (define platforms
                                    (platform-modules)))))
 
 (define (lookup-platform-by-system system)
-  "Return the platform corresponding to the given SYSTEM."
-  (find (lambda (platform)
-          (let ((s (platform-system platform)))
-            (and (string? s) (string=? s system))))
-        (platforms)))
+  "Return the platform corresponding to the given SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((s (platform-system platform)))
+                (and (string? s) (string=? s system))))
+            (platforms))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (lookup-platform-by-target target)
-  "Return the platform corresponding to the given TARGET."
-  (find (lambda (platform)
-          (let ((t (platform-target platform)))
-            (and (string? t) (string=? t target))))
-        (platforms)))
+  "Return the platform corresponding to the given TARGET.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((t (platform-target platform)))
+                (and (string? t) (string=? t target))))
+            (platforms))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (lookup-platform-by-target-or-system target-or-system)
-  "Return the platform corresponding to the given TARGET or SYSTEM."
-  (or (lookup-platform-by-target target-or-system)
-      (lookup-platform-by-system target-or-system)))
+  "Return the platform corresponding to the given TARGET or SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (false-if-platform-not-found (lookup-platform-by-target target-or-system))
+      (false-if-platform-not-found (lookup-platform-by-system target-or-system))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (platform-system->target system)
   "Return the target matching the given SYSTEM if it exists or false
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v2 2/2] gnu: Remove u-boot-malta.
  2023-01-14  4:19 ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
@ 2023-01-14  4:19   ` Maxim Cournoyer
  2023-01-14 14:34   ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Ludovic Courtès
  2023-01-14 14:34   ` Ludovic Courtès
  2 siblings, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-14  4:19 UTC (permalink / raw)
  To: 60802; +Cc: Maxim Cournoyer

Relates to <https://issues.guix.gnu.org/60786>.

The mips64el architecture is not currently supported, causing (guix platform)
to raise an exception when attempting to cross-build the package.

* gnu/packages/bootloaders.scm (u-boot-malta): Delete variable.

---

(no changes since v1)

 gnu/packages/bootloaders.scm | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 6e6bdb4c08..8dc6ff698d 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -965,9 +965,6 @@ (define*-public (make-u-boot-package board triplet
                   uboot-files)
                  #t)))))))))
 
-(define-public u-boot-malta
-  (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
-
 (define-public u-boot-am335x-boneblack
   (let ((base (make-u-boot-package
                "am335x_evm" "arm-linux-gnueabihf"
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-14  4:19 ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
  2023-01-14  4:19   ` [bug#60802] [PATCH v2 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
@ 2023-01-14 14:34   ` Ludovic Courtès
  2023-01-16 17:46     ` Maxim Cournoyer
  2023-01-14 14:34   ` Ludovic Courtès
  2 siblings, 1 reply; 21+ messages in thread
From: Ludovic Courtès @ 2023-01-14 14:34 UTC (permalink / raw)
  To: Maxim Cournoyer
  Cc: Tobias Geerinckx-Rice, Josselin Poiret, 60802, Simon Tournier,
	Mathieu Othacehe, Christopher Baines, Ricardo Wurmus

Hi,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> This was motivated by #60786, which produced a cryptic, hard to understand
> backtrace.
>
> * guix/platform.scm (&platform-not-found-error): New exception type.
> (make-platform-not-found-error): New exception constructor.
> (platform-not-found-error?): New predicate.
> (false-if-platform-not-found): New syntax.
> (lookup-platform-by-system): Raise an exception when no platform is found.
> Update documentation.
> (lookup-platform-by-target): Likewise.
> (lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
> false-if-platform-not-found.

Sounds like a good idea!

> +++ b/gnu/packages/bootstrap.scm
> @@ -315,7 +315,7 @@ (define* (glibc-dynamic-linker
>                                   (%current-system))))
>    "Return the name of Glibc's dynamic linker for SYSTEM."
>    ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
> -  (let ((platform (lookup-platform-by-system system)))
> +  (let ((platform (false-if-exception (lookup-platform-by-system system))))

Maybe we don’t need to protect here, because it’s a 

> +++ b/guix/platform.scm
> @@ -21,6 +21,7 @@ (define-module (guix platform)
>    #:use-module (guix memoization)
>    #:use-module (guix records)
>    #:use-module (guix ui)
> +  #:use-module (ice-9 exceptions)

So far the we use (srfi srfi-35) exclusively to define condition types;
I think we should do the same here, for consistency.

> +            &platform-not-found-error
> +            make-platform-not-found-error

The constructor doesn’t need to be exposed.

> +;;;
> +;;; Exceptions.
> +;;;
> +(define-exception-type &platform-not-found-error &error
> +  make-platform-not-found-error platform-not-found-error?)

So this would become (define-condition-type …).

Otherwise LGTM, thanks!

Ludo’.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-14  4:19 ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
  2023-01-14  4:19   ` [bug#60802] [PATCH v2 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
  2023-01-14 14:34   ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Ludovic Courtès
@ 2023-01-14 14:34   ` Ludovic Courtès
  2023-01-19  1:55     ` bug#60802: [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
  2 siblings, 1 reply; 21+ messages in thread
From: Ludovic Courtès @ 2023-01-14 14:34 UTC (permalink / raw)
  To: Maxim Cournoyer
  Cc: Tobias Geerinckx-Rice, Josselin Poiret, 60802, Simon Tournier,
	Mathieu Othacehe, Christopher Baines, Ricardo Wurmus

Hi,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> This was motivated by #60786, which produced a cryptic, hard to understand
> backtrace.
>
> * guix/platform.scm (&platform-not-found-error): New exception type.
> (make-platform-not-found-error): New exception constructor.
> (platform-not-found-error?): New predicate.
> (false-if-platform-not-found): New syntax.
> (lookup-platform-by-system): Raise an exception when no platform is found.
> Update documentation.
> (lookup-platform-by-target): Likewise.
> (lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
> false-if-platform-not-found.

Sounds like a good idea!

> +++ b/guix/platform.scm
> @@ -21,6 +21,7 @@ (define-module (guix platform)
>    #:use-module (guix memoization)
>    #:use-module (guix records)
>    #:use-module (guix ui)
> +  #:use-module (ice-9 exceptions)

So far the we use (srfi srfi-35) exclusively to define condition types;
I think we should do the same here, for consistency.

> +            &platform-not-found-error
> +            make-platform-not-found-error

The constructor doesn’t need to be exposed.

> +;;;
> +;;; Exceptions.
> +;;;
> +(define-exception-type &platform-not-found-error &error
> +  make-platform-not-found-error platform-not-found-error?)

So this would become (define-condition-type …).

Otherwise LGTM, thanks!

Ludo’.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-14  3:05 [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
  2023-01-14  3:08 ` [bug#60802] [PATCH 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
  2023-01-14  4:19 ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
@ 2023-01-14 15:14 ` Maxim Cournoyer
  2023-01-14 15:14   ` [bug#60802] [PATCH v3 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
  2023-01-15 13:57   ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Josselin Poiret via Guix-patches via
  2023-01-17 15:34 ` [bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
  3 siblings, 2 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-14 15:14 UTC (permalink / raw)
  To: 60802
  Cc: Josselin Poiret, Tobias Geerinckx-Rice, Maxim Cournoyer,
	Simon Tournier, Mathieu Othacehe, ludo, Christopher Baines,
	Ricardo Wurmus

This was motivated by #60786, which produced a cryptic, hard to understand
backtrace.

* guix/platform.scm (&platform-not-found-error): New exception type.
(make-platform-not-found-error): New exception constructor.
(platform-not-found-error?): New predicate.
(false-if-platform-not-found): New syntax.
(lookup-platform-by-system): Raise an exception when no platform is found.
Update documentation.
(lookup-platform-by-target): Likewise.
(lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
false-if-platform-not-found.
* gnu/packages/bootstrap.scm (glibc-dynamic-linker): Handle
lookup-platform-by-system call to preserve existing behavior.

---

Changes in v3:
- Use false-if-platform-not-found instead of false-if-exception in (gnu
packages bootstrap)
- Do not export make-platform-not-found-error constructor

Changes in v2:
- Add false-if-platform-not-found syntax
- Use it while evaluating lookup-platform-by-target-or-system

 gnu/packages/bootstrap.scm |  3 ++-
 guix/platform.scm          | 50 ++++++++++++++++++++++++++++----------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm
index d2914fb5a7..9ea1a3e4d1 100644
--- a/gnu/packages/bootstrap.scm
+++ b/gnu/packages/bootstrap.scm
@@ -315,7 +315,8 @@ (define* (glibc-dynamic-linker
                                  (%current-system))))
   "Return the name of Glibc's dynamic linker for SYSTEM."
   ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
-  (let ((platform (lookup-platform-by-system system)))
+  (let ((platform (false-if-platform-not-found
+                   (lookup-platform-by-system system))))
     (cond
      ((platform? platform)
       (platform-glibc-dynamic-linker platform))
diff --git a/guix/platform.scm b/guix/platform.scm
index f873913fe0..4f4da002f7 100644
--- a/guix/platform.scm
+++ b/guix/platform.scm
@@ -21,6 +21,7 @@ (define-module (guix platform)
   #:use-module (guix memoization)
   #:use-module (guix records)
   #:use-module (guix ui)
+  #:use-module (ice-9 exceptions)
   #:use-module (srfi srfi-1)
   #:export (platform
             platform?
@@ -29,6 +30,10 @@ (define-module (guix platform)
             platform-linux-architecture
             platform-glibc-dynamic-linker
 
+            &platform-not-found-error
+            platform-not-found-error?
+            false-if-platform-not-found
+
             platform-modules
             platforms
             lookup-platform-by-system
@@ -70,6 +75,19 @@ (define-record-type* <platform> platform make-platform
                         (default #false))
   (glibc-dynamic-linker platform-glibc-dynamic-linker))
 
+\f
+;;;
+;;; Exceptions.
+;;;
+(define-exception-type &platform-not-found-error &error
+  make-platform-not-found-error platform-not-found-error?)
+
+(define-syntax-rule (false-if-platform-not-found exp)
+  "Evaluate EXP but return #f if it raises a platform-not-found-error?
+exception."
+  (guard (ex ((platform-not-found-error? ex) #f))
+    exp))
+
 \f
 ;;;
 ;;; Platforms.
@@ -94,23 +112,29 @@ (define platforms
                                    (platform-modules)))))
 
 (define (lookup-platform-by-system system)
-  "Return the platform corresponding to the given SYSTEM."
-  (find (lambda (platform)
-          (let ((s (platform-system platform)))
-            (and (string? s) (string=? s system))))
-        (platforms)))
+  "Return the platform corresponding to the given SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((s (platform-system platform)))
+                (and (string? s) (string=? s system))))
+            (platforms))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (lookup-platform-by-target target)
-  "Return the platform corresponding to the given TARGET."
-  (find (lambda (platform)
-          (let ((t (platform-target platform)))
-            (and (string? t) (string=? t target))))
-        (platforms)))
+  "Return the platform corresponding to the given TARGET.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((t (platform-target platform)))
+                (and (string? t) (string=? t target))))
+            (platforms))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (lookup-platform-by-target-or-system target-or-system)
-  "Return the platform corresponding to the given TARGET or SYSTEM."
-  (or (lookup-platform-by-target target-or-system)
-      (lookup-platform-by-system target-or-system)))
+  "Return the platform corresponding to the given TARGET or SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (false-if-platform-not-found (lookup-platform-by-target target-or-system))
+      (false-if-platform-not-found (lookup-platform-by-system target-or-system))
+      (raise-exception (make-platform-not-found-error))))
 
 (define (platform-system->target system)
   "Return the target matching the given SYSTEM if it exists or false
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 2/2] gnu: Remove u-boot-malta.
  2023-01-14 15:14 ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
@ 2023-01-14 15:14   ` Maxim Cournoyer
  2023-01-15 13:57   ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Josselin Poiret via Guix-patches via
  1 sibling, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-14 15:14 UTC (permalink / raw)
  To: 60802; +Cc: ludo, Maxim Cournoyer

Relates to <https://issues.guix.gnu.org/60786>.

The mips64el architecture is not currently supported, causing (guix platform)
to raise an exception when attempting to cross-build the package.

* gnu/packages/bootloaders.scm (u-boot-malta): Delete variable.

---

(no changes since v1)

 gnu/packages/bootloaders.scm | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 6e6bdb4c08..8dc6ff698d 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -965,9 +965,6 @@ (define*-public (make-u-boot-package board triplet
                   uboot-files)
                  #t)))))))))
 
-(define-public u-boot-malta
-  (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
-
 (define-public u-boot-am335x-boneblack
   (let ((base (make-u-boot-package
                "am335x_evm" "arm-linux-gnueabihf"
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-14 15:14 ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
  2023-01-14 15:14   ` [bug#60802] [PATCH v3 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
@ 2023-01-15 13:57   ` Josselin Poiret via Guix-patches via
  2023-01-15 22:11     ` Maxim Cournoyer
                       ` (2 more replies)
  1 sibling, 3 replies; 21+ messages in thread
From: Josselin Poiret via Guix-patches via @ 2023-01-15 13:57 UTC (permalink / raw)
  To: Maxim Cournoyer, 60802
  Cc: Tobias Geerinckx-Rice, Maxim Cournoyer, Simon Tournier,
	Mathieu Othacehe, ludo, Christopher Baines, Ricardo Wurmus

Hi Maxim,

This looks good to me, although in the grand scheme of things I wonder
if that change is a step forward: for those kinds of procedures, we
could expect consumers to instead always properly handle the #f case
themselves, rather than baby-sitting them and systematically relying on
exceptions in the parent procedure, no?  As a caricatural example: the
SRFI-1 `find` could raise an exception instead of returning #f, but I
don't think anyone would consider that proper behaviour.

I don't have a particularly strong opinion towards either option, which
probably means that there's some discussion to be had here.

Best,
-- 
Josselin Poiret




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-15 13:57   ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Josselin Poiret via Guix-patches via
@ 2023-01-15 22:11     ` Maxim Cournoyer
  2023-01-16 11:00     ` Simon Tournier
  2023-01-17  8:59     ` Ludovic Courtès
  2 siblings, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-15 22:11 UTC (permalink / raw)
  To: Josselin Poiret
  Cc: Tobias Geerinckx-Rice, 60802, Simon Tournier, Mathieu Othacehe,
	ludo, Christopher Baines, Ricardo Wurmus

Hi Josselin,

Josselin Poiret <dev@jpoiret.xyz> writes:

> Hi Maxim,
>
> This looks good to me, although in the grand scheme of things I wonder
> if that change is a step forward: for those kinds of procedures, we
> could expect consumers to instead always properly handle the #f case
> themselves, rather than baby-sitting them and systematically relying on
> exceptions in the parent procedure, no?

I like exceptions; I think they are an improvement to C-style ad-hoc
checking of each call return; when things fail they fail early and in a
clear fashion, rather than indirectly, which is easier to debug and
removes the burden to duplicate the same checks at every call site.

> As a caricatural example: the SRFI-1 `find` could raise an exception
> instead of returning #f, but I don't think anyone would consider that
> proper behaviour.

I think the find interface is well established;
lookup-platform-by-system and friends is not really intended to return
#f, as shown in the few usages in our code base (there's only one place
where it needed to be handled in previous code, and that's a TODO
waiting to move more things to (guix platform)).

> I don't have a particularly strong opinion towards either option, which
> probably means that there's some discussion to be had here.

Good, that's what reviews are for :-).

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-15 13:57   ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Josselin Poiret via Guix-patches via
  2023-01-15 22:11     ` Maxim Cournoyer
@ 2023-01-16 11:00     ` Simon Tournier
  2023-01-17  8:59     ` Ludovic Courtès
  2 siblings, 0 replies; 21+ messages in thread
From: Simon Tournier @ 2023-01-16 11:00 UTC (permalink / raw)
  To: Josselin Poiret, Maxim Cournoyer, 60802
  Cc: Christopher Baines, Maxim Cournoyer, Mathieu Othacehe, ludo,
	Tobias Geerinckx-Rice, Ricardo Wurmus

Hi Josselin,

On dim., 15 janv. 2023 at 14:57, Josselin Poiret via Guix-patches via <guix-patches@gnu.org> wrote:

> This looks good to me, although in the grand scheme of things I wonder
> if that change is a step forward: for those kinds of procedures, we
> could expect consumers to instead always properly handle the #f case
> themselves, rather than baby-sitting them and systematically relying on
> exceptions in the parent procedure, no?  As a caricatural example: the
> SRFI-1 `find` could raise an exception instead of returning #f, but I
> don't think anyone would consider that proper behaviour.

How to handle, is it not somehow a convention?  Using the example
’find’, we could imagine it returns an exception ’not-found’ instead of
the current plain #f – this #f appears to me a convention, no?  Or
’find’ could return some Maybe monad (’Just the-result’ or None) –
another convention.

Well, how to handle appears to me a convention when composing. :-)


Cheers,
simon




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-14 14:34   ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Ludovic Courtès
@ 2023-01-16 17:46     ` Maxim Cournoyer
  2023-01-17  9:22       ` Ludovic Courtès
  0 siblings, 1 reply; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-16 17:46 UTC (permalink / raw)
  To: Ludovic Courtès
  Cc: Tobias Geerinckx-Rice, Josselin Poiret, 60802, Simon Tournier,
	Mathieu Othacehe, Christopher Baines, Ricardo Wurmus

Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> writes:

> Hi,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> This was motivated by #60786, which produced a cryptic, hard to understand
>> backtrace.
>>
>> * guix/platform.scm (&platform-not-found-error): New exception type.
>> (make-platform-not-found-error): New exception constructor.
>> (platform-not-found-error?): New predicate.
>> (false-if-platform-not-found): New syntax.
>> (lookup-platform-by-system): Raise an exception when no platform is found.
>> Update documentation.
>> (lookup-platform-by-target): Likewise.
>> (lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
>> false-if-platform-not-found.
>
> Sounds like a good idea!

Good!

>> +++ b/gnu/packages/bootstrap.scm
>> @@ -315,7 +315,7 @@ (define* (glibc-dynamic-linker
>>                                   (%current-system))))
>>    "Return the name of Glibc's dynamic linker for SYSTEM."
>>    ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
>> -  (let ((platform (lookup-platform-by-system system)))
>> +  (let ((platform (false-if-exception (lookup-platform-by-system system))))
>
> Maybe we don’t need to protect here, because it’s a

We cannot do this, otherwise the other cond clauses would never been
evaluated:

--8<---------------cut here---------------start------------->8---
  (let ((platform (false-if-exception (lookup-platform-by-system system))))
    (cond
     ((platform? platform)
      (platform-glibc-dynamic-linker platform))

--> Clauses below here are evaluated when platform was not found.

     ;; TODO: Define those as platforms.
     ((string=? system "i686-gnu") "/lib/ld.so.1")
     ((string=? system "powerpc64-linux") "/lib/ld64.so.1")
     ((string=? system "alpha-linux") "/lib/ld-linux.so.2")

     ;; XXX: This one is used bare-bones, without a libc, so add a case
     ;; here just so we can keep going.
     ((string=? system "arm-elf") "no-ld.so")
     ((string=? system "arm-eabi") "no-ld.so")
     ((string=? system "xtensa-elf") "no-ld.so")
     ((string=? system "avr") "no-ld.so")
     ((string=? system "propeller-elf") "no-ld.so")
     ((string=? system "i686-mingw") "no-ld.so")
     ((string=? system "x86_64-mingw") "no-ld.so")
     ((string=? system "vc4-elf") "no-ld.so")

     (else (error "dynamic linker name not known for this system"
                  system))))
--8<---------------cut here---------------end--------------->8---

I'll change it to use false-if-platform-not-found though.

>> +++ b/guix/platform.scm
>> @@ -21,6 +21,7 @@ (define-module (guix platform)
>>    #:use-module (guix memoization)
>>    #:use-module (guix records)
>>    #:use-module (guix ui)
>> +  #:use-module (ice-9 exceptions)
>
> So far the we use (srfi srfi-35) exclusively to define condition types;
> I think we should do the same here, for consistency.

Could we instead start migrating away from srfi-35 to (ice-9
exceptions), which is the new native way to use exceptions in Guile?  I
think it'd be nicer to use it in the future, to avoid newcomers being
confusing about the 3 or 4 ways to manage exceptions in Guile
(recommended read on the topic:
https://vijaymarupudi.com/blog/2022-02-13-error-handling-in-guile.html).

Migrating the whole code at once doesn't seem a good idea, so gradually
transitioning (such as using (ice-9 exceptions) for new code) appears a
good idea to me, if we agree on the direction!

>> +            &platform-not-found-error
>> +            make-platform-not-found-error
>
> The constructor doesn’t need to be exposed.

Good point.  Fixed in the latest revision.

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-15 13:57   ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Josselin Poiret via Guix-patches via
  2023-01-15 22:11     ` Maxim Cournoyer
  2023-01-16 11:00     ` Simon Tournier
@ 2023-01-17  8:59     ` Ludovic Courtès
  2023-01-17 12:35       ` Simon Tournier
  2 siblings, 1 reply; 21+ messages in thread
From: Ludovic Courtès @ 2023-01-17  8:59 UTC (permalink / raw)
  To: Josselin Poiret
  Cc: Tobias Geerinckx-Rice, 60802, Maxim Cournoyer, Simon Tournier,
	Mathieu Othacehe, Christopher Baines, Ricardo Wurmus

Hi Josselin,

Josselin Poiret <dev@jpoiret.xyz> skribis:

> This looks good to me, although in the grand scheme of things I wonder
> if that change is a step forward: for those kinds of procedures, we
> could expect consumers to instead always properly handle the #f case
> themselves, rather than baby-sitting them and systematically relying on
> exceptions in the parent procedure, no?  As a caricatural example: the
> SRFI-1 `find` could raise an exception instead of returning #f, but I
> don't think anyone would consider that proper behaviour.

I share this sentiment in general (plus the fact that we should keep UI
aspects, such as error reports, separate from core logic).  Here there’s
a precedent with other lookup procedures though
(‘lookup-bootloader-by-name’, ‘lookup-compressor’,
‘lookup-image-type-by-name’, etc.), so I think it’s okay to keep it that
way.

Ludo’.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-16 17:46     ` Maxim Cournoyer
@ 2023-01-17  9:22       ` Ludovic Courtès
  0 siblings, 0 replies; 21+ messages in thread
From: Ludovic Courtès @ 2023-01-17  9:22 UTC (permalink / raw)
  To: Maxim Cournoyer
  Cc: Tobias Geerinckx-Rice, Josselin Poiret, 60802, Simon Tournier,
	Mathieu Othacehe, Christopher Baines, Ricardo Wurmus

Hi,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

>>> +++ b/gnu/packages/bootstrap.scm
>>> @@ -315,7 +315,7 @@ (define* (glibc-dynamic-linker
>>>                                   (%current-system))))
>>>    "Return the name of Glibc's dynamic linker for SYSTEM."
>>>    ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
>>> -  (let ((platform (lookup-platform-by-system system)))
>>> +  (let ((platform (false-if-exception (lookup-platform-by-system system))))
>>
>> Maybe we don’t need to protect here, because it’s a
>
> We cannot do this, otherwise the other cond clauses would never been
> evaluated:

Yes sorry, I realized later but hit “Send” before deleting the sentence
prototype.  :-)

>> So far the we use (srfi srfi-35) exclusively to define condition types;
>> I think we should do the same here, for consistency.
>
> Could we instead start migrating away from srfi-35 to (ice-9
> exceptions), which is the new native way to use exceptions in Guile?

Maybe, but I’m not convinced it’s worth it.

> I think it'd be nicer to use it in the future, to avoid newcomers
> being confusing about the 3 or 4 ways to manage exceptions in Guile

That’s why I suggest sticking to one way in Guix, which is currently
SRFI-34/35.

> Migrating the whole code at once doesn't seem a good idea, so gradually
> transitioning (such as using (ice-9 exceptions) for new code) appears a
> good idea to me, if we agree on the direction!

I’m not convinced it’s worth transitioning, and I’m even less convinced
about a gradual transition, as that would make it harder for newcomers
to join, people wouldn’t be sure which style to use, etc.

It’s a discussion worth having though, but I think we can have it
separately.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-17  8:59     ` Ludovic Courtès
@ 2023-01-17 12:35       ` Simon Tournier
  2023-01-17 14:38         ` Maxim Cournoyer
  0 siblings, 1 reply; 21+ messages in thread
From: Simon Tournier @ 2023-01-17 12:35 UTC (permalink / raw)
  To: Ludovic Courtès, Josselin Poiret
  Cc: 60802, Maxim Cournoyer, Mathieu Othacehe, Tobias Geerinckx-Rice,
	Christopher Baines, Ricardo Wurmus

Hi,

On mar., 17 janv. 2023 at 09:59, Ludovic Courtès <ludo@gnu.org> wrote:
> Josselin Poiret <dev@jpoiret.xyz> skribis:
>
>> This looks good to me, although in the grand scheme of things I wonder
>> if that change is a step forward: for those kinds of procedures, we
>> could expect consumers to instead always properly handle the #f case
>> themselves, rather than baby-sitting them and systematically relying on
>> exceptions in the parent procedure, no?  As a caricatural example: the
>> SRFI-1 `find` could raise an exception instead of returning #f, but I
>> don't think anyone would consider that proper behaviour.
>
> I share this sentiment in general (plus the fact that we should keep UI
> aspects, such as error reports, separate from core logic).  Here there’s
> a precedent with other lookup procedures though
> (‘lookup-bootloader-by-name’, ‘lookup-compressor’,
> ‘lookup-image-type-by-name’, etc.), so I think it’s okay to keep it that
> way.

Well, from my small experience with other programming language, they
barely do return a boolean when they fail.  I think this way using a
boolean is because some historical reasons when exceptions was not
implemented in Scheme (or other languages).

Exception allows the motto: «ask for forgiveness, not permission» while
keeping under control the side effects.  Well, IMHO exception is often a
good practise for dynamically typed programming language; as Scheme (or
Python).

From my point of view, exception is not related to “should keep UI
aspects, such as error reports, separated from core logic”.  This is how
the exception is handled.  It is often easier to propagate exception
until an handler than propagate a boolean (as with ’find’).

And if the exception is not handled, then it just returns a backtrace,
which is more informative, IMHO.


For instance, Python returns an exception:

--8<---------------cut here---------------start------------->8---
$ guix shell python python-ipython -- ipython
Python 3.9.9 (main, Jan  1 1970, 00:00:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: lst = [1,2,3]
lst = [1,2,3]

In [2]: lst.index(2)
Out[2]: 1

In [3]: lst.index(10)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 lst.index(10)

ValueError: 10 is not in list
--8<---------------cut here---------------end--------------->8---

For other instances, OCaml implements two ’find’ [1], one using an
exception and another using a Maybe monad (named ’option’).

--8<---------------cut here---------------start------------->8---
val find : ('a -> bool) -> 'a list -> 'a
Raises Not_found if there is no value that satisfies f in the list l.

val find_opt : ('a -> bool) -> 'a list -> 'a option
--8<---------------cut here---------------end--------------->8---

Haskell returns a Maybe monad [2]:

--8<---------------cut here---------------start------------->8---
find :: Foldable t => (a -> Bool) -> t a -> Maybe a 
--8<---------------cut here---------------end--------------->8---

Well, from a signature point of view, ’find’ from SRFI-1 returns an
union type (value or boolean) which can lead to hard to detect bugs:
when composing functions, the error can be incorrectly pointed by the
compiler to a totally unrelated place.

Instead, the exception allows to keep an expected signature (say one
value as with ’find’) but raises the error at the correct place.  If
there is no handler, it just raises the backtrace.

From my point of view, code using exception cannot be worse* than
without.  That’s my general sentiment. :-)

*worse: for sure, we could discuss some performance penalty depending on
        the context.

1: <https://v2.ocaml.org/api/List.html>
2: <https://hackage.haskell.org/package/base-4.17.0.0/docs/Data-List.html>


Cheers,
simon




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-17 12:35       ` Simon Tournier
@ 2023-01-17 14:38         ` Maxim Cournoyer
  0 siblings, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-17 14:38 UTC (permalink / raw)
  To: Simon Tournier
  Cc: Josselin Poiret, 60802, Mathieu Othacehe, Ludovic Courtès,
	Tobias Geerinckx-Rice, Christopher Baines, Ricardo Wurmus

Hi Simon,

Simon Tournier <zimon.toutoune@gmail.com> writes:

> Hi,
>
> On mar., 17 janv. 2023 at 09:59, Ludovic Courtès <ludo@gnu.org> wrote:
>> Josselin Poiret <dev@jpoiret.xyz> skribis:
>>
>>> This looks good to me, although in the grand scheme of things I wonder
>>> if that change is a step forward: for those kinds of procedures, we
>>> could expect consumers to instead always properly handle the #f case
>>> themselves, rather than baby-sitting them and systematically relying on
>>> exceptions in the parent procedure, no?  As a caricatural example: the
>>> SRFI-1 `find` could raise an exception instead of returning #f, but I
>>> don't think anyone would consider that proper behaviour.
>>
>> I share this sentiment in general (plus the fact that we should keep UI
>> aspects, such as error reports, separate from core logic).  Here there’s
>> a precedent with other lookup procedures though
>> (‘lookup-bootloader-by-name’, ‘lookup-compressor’,
>> ‘lookup-image-type-by-name’, etc.), so I think it’s okay to keep it that
>> way.
>
> Well, from my small experience with other programming language, they
> barely do return a boolean when they fail.  I think this way using a
> boolean is because some historical reasons when exceptions was not
> implemented in Scheme (or other languages).
>
> Exception allows the motto: «ask for forgiveness, not permission» while
> keeping under control the side effects.  Well, IMHO exception is often a
> good practise for dynamically typed programming language; as Scheme (or
> Python).
>
> From my point of view, exception is not related to “should keep UI
> aspects, such as error reports, separated from core logic”.  This is how
> the exception is handled.  It is often easier to propagate exception
> until an handler than propagate a boolean (as with ’find’).
>
> And if the exception is not handled, then it just returns a backtrace,
> which is more informative, IMHO.

You've summarized well the reasons I think using an exception here makes
sense (and why using exceptions rather than C-style booleans to
propagate error conditions is preferable in general for languages where
it's possible to do so -- luckily Scheme is one).

I'll send a v4 reworking it to use srfi-34/35, so that the discussion to
migrate to (ice-9 exceptions) can be kept separate.

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package
  2023-01-14  3:05 [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
                   ` (2 preceding siblings ...)
  2023-01-14 15:14 ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
@ 2023-01-17 15:34 ` Maxim Cournoyer
  2023-01-17 15:34   ` [bug#60802] [PATCH v4 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
  2023-01-17 15:34   ` [bug#60802] [PATCH v4 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
  3 siblings, 2 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-17 15:34 UTC (permalink / raw)
  To: 60802
  Cc: Josselin Poiret, Tobias Geerinckx-Rice, Maxim Cournoyer,
	Simon Tournier, Mathieu Othacehe, ludo, Christopher Baines,
	Ricardo Wurmus

The package was causing issues when migrating the make-u-boot-package
procedure to use Guix's infrastructure for cross-compilation, because Guix
would now attempt to build a cross-compiler for mips64el, which is not
supported per (guix platforms).

Changes in v4:
- Use (srfi srfi-35) condition instead of (ice-9 exceptions)
- Add a target-or-system field to the condition type for extra information

Changes in v3:
- Use false-if-platform-not-found instead of false-if-exception in (gnu
packages bootstrap)
- Do not export make-platform-not-found-error constructor

Changes in v2:
- Add false-if-platform-not-found syntax
- Use it while evaluating lookup-platform-by-target-or-system

Maxim Cournoyer (2):
  platforms: Raise an exception when no suitable platform is found.
  gnu: Remove u-boot-malta.

 gnu/packages/bootloaders.scm |  3 --
 gnu/packages/bootstrap.scm   |  3 +-
 guix/platform.scm            | 55 +++++++++++++++++++++++++++---------
 3 files changed, 44 insertions(+), 17 deletions(-)


base-commit: ecda67a577570f412b103e5dd8ed1a44193a9c11
-- 
2.38.1





^ permalink raw reply	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v4 1/2] platforms: Raise an exception when no suitable platform is found.
  2023-01-17 15:34 ` [bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
@ 2023-01-17 15:34   ` Maxim Cournoyer
  2023-01-17 15:34   ` [bug#60802] [PATCH v4 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
  1 sibling, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-17 15:34 UTC (permalink / raw)
  To: 60802
  Cc: Josselin Poiret, Tobias Geerinckx-Rice, Maxim Cournoyer,
	Simon Tournier, Mathieu Othacehe, ludo, Christopher Baines,
	Ricardo Wurmus

This was motivated by #60786, which produced a cryptic, hard to understand
backtrace.

Given the following reproducer:
    (use-modules (guix packages)
                 (gnu packages cross-base))

    (define linux-libre-headers-cross-mips64el-linux-gnuabi64
      (cross-kernel-headers "mips64el-linux-gnuabi64"))

    (package-arguments linux-libre-headers-cross-mips64el-linux-gnuabi64)

Before this change:
    ice-9/boot-9.scm:1685:16: In procedure raise-exception:
    In procedure struct-vtable: Wrong type argument in position 1 (expecting struct): #f

After this change:
    ice-9/boot-9.scm:1685:16: In procedure raise-exception:
    ERROR:
      1. &platform-not-found-error: "mips64el-linux-gnuabi64"

* guix/platform.scm (&platform-not-found-error): New condition.
(platform-not-found-error?): New predicate.
(false-if-platform-not-found): New syntax.
(lookup-platform-by-system): Raise an exception when no platform is found.
Update documentation.
(lookup-platform-by-target): Likewise.
(lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
false-if-platform-not-found.
* gnu/packages/bootstrap.scm (glibc-dynamic-linker): Handle
lookup-platform-by-system call to preserve existing behavior.

---

Changes in v4:
- Use (srfi srfi-35) condition instead of (ice-9 exceptions)
- Add a target-or-system field to the condition type for extra information

Changes in v3:
- Use false-if-platform-not-found instead of false-if-exception in (gnu
packages bootstrap)
- Do not export make-platform-not-found-error constructor

Changes in v2:
- Add false-if-platform-not-found syntax
- Use it while evaluating lookup-platform-by-target-or-system

 gnu/packages/bootstrap.scm |  3 ++-
 guix/platform.scm          | 55 +++++++++++++++++++++++++++++---------
 2 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm
index d2914fb5a7..9ea1a3e4d1 100644
--- a/gnu/packages/bootstrap.scm
+++ b/gnu/packages/bootstrap.scm
@@ -315,7 +315,8 @@ (define* (glibc-dynamic-linker
                                  (%current-system))))
   "Return the name of Glibc's dynamic linker for SYSTEM."
   ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
-  (let ((platform (lookup-platform-by-system system)))
+  (let ((platform (false-if-platform-not-found
+                   (lookup-platform-by-system system))))
     (cond
      ((platform? platform)
       (platform-glibc-dynamic-linker platform))
diff --git a/guix/platform.scm b/guix/platform.scm
index f873913fe0..a2d95ab507 100644
--- a/guix/platform.scm
+++ b/guix/platform.scm
@@ -22,6 +22,8 @@ (define-module (guix platform)
   #:use-module (guix records)
   #:use-module (guix ui)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:export (platform
             platform?
             platform-target
@@ -29,6 +31,10 @@ (define-module (guix platform)
             platform-linux-architecture
             platform-glibc-dynamic-linker
 
+            &platform-not-found-error
+            platform-not-found-error?
+            false-if-platform-not-found
+
             platform-modules
             platforms
             lookup-platform-by-system
@@ -70,6 +76,20 @@ (define-record-type* <platform> platform make-platform
                         (default #false))
   (glibc-dynamic-linker platform-glibc-dynamic-linker))
 
+\f
+;;;
+;;; Exceptions.
+;;;
+(define-condition-type &platform-not-found-error &error
+  platform-not-found-error?
+  (target-or-system platform-not-found-error-target-or-system))
+
+(define-syntax-rule (false-if-platform-not-found exp)
+  "Evaluate EXP but return #f if it raises a platform-not-found-error?
+exception."
+  (guard (ex ((platform-not-found-error? ex) #f))
+    exp))
+
 \f
 ;;;
 ;;; Platforms.
@@ -94,23 +114,32 @@ (define platforms
                                    (platform-modules)))))
 
 (define (lookup-platform-by-system system)
-  "Return the platform corresponding to the given SYSTEM."
-  (find (lambda (platform)
-          (let ((s (platform-system platform)))
-            (and (string? s) (string=? s system))))
-        (platforms)))
+  "Return the platform corresponding to the given SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((s (platform-system platform)))
+                (and (string? s) (string=? s system))))
+            (platforms))
+      (raise-exception (condition (&platform-not-found-error
+                                   (target-or-system system))))))
 
 (define (lookup-platform-by-target target)
-  "Return the platform corresponding to the given TARGET."
-  (find (lambda (platform)
-          (let ((t (platform-target platform)))
-            (and (string? t) (string=? t target))))
-        (platforms)))
+  "Return the platform corresponding to the given TARGET.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((t (platform-target platform)))
+                (and (string? t) (string=? t target))))
+            (platforms))
+      (raise-exception (condition (&platform-not-found-error
+                                   (target-or-system target))))))
 
 (define (lookup-platform-by-target-or-system target-or-system)
-  "Return the platform corresponding to the given TARGET or SYSTEM."
-  (or (lookup-platform-by-target target-or-system)
-      (lookup-platform-by-system target-or-system)))
+  "Return the platform corresponding to the given TARGET or SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (false-if-platform-not-found (lookup-platform-by-target target-or-system))
+      (false-if-platform-not-found (lookup-platform-by-system target-or-system))
+      (raise-exception (condition (&platform-not-found-error
+                                   (target-or-system target-or-system))))))
 
 (define (platform-system->target system)
   "Return the target matching the given SYSTEM if it exists or false
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [bug#60802] [PATCH v4 2/2] gnu: Remove u-boot-malta.
  2023-01-17 15:34 ` [bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
  2023-01-17 15:34   ` [bug#60802] [PATCH v4 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
@ 2023-01-17 15:34   ` Maxim Cournoyer
  1 sibling, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-17 15:34 UTC (permalink / raw)
  To: 60802; +Cc: ludo, Maxim Cournoyer

Relates to <https://issues.guix.gnu.org/60786>.

The mips64el architecture is not currently supported, causing (guix platform)
to raise an exception when attempting to cross-build the package.

* gnu/packages/bootloaders.scm (u-boot-malta): Delete variable.

---

(no changes since v1)

 gnu/packages/bootloaders.scm | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 6e6bdb4c08..8dc6ff698d 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -965,9 +965,6 @@ (define*-public (make-u-boot-package board triplet
                   uboot-files)
                  #t)))))))))
 
-(define-public u-boot-malta
-  (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
-
 (define-public u-boot-am335x-boneblack
   (let ((base (make-u-boot-package
                "am335x_evm" "arm-linux-gnueabihf"
-- 
2.38.1





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* bug#60802: [PATCH 0/2] Remove unsupported u-boot-malta package
  2023-01-14 14:34   ` Ludovic Courtès
@ 2023-01-19  1:55     ` Maxim Cournoyer
  0 siblings, 0 replies; 21+ messages in thread
From: Maxim Cournoyer @ 2023-01-19  1:55 UTC (permalink / raw)
  To: Ludovic Courtès
  Cc: Josselin Poiret, Christopher Baines, Simon Tournier,
	Mathieu Othacehe, Tobias Geerinckx-Rice, Ricardo Wurmus,
	60802-done

Hello,

Ludovic Courtès <ludo@gnu.org> writes:

> Hi,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> This was motivated by #60786, which produced a cryptic, hard to understand
>> backtrace.
>>
>> * guix/platform.scm (&platform-not-found-error): New exception type.
>> (make-platform-not-found-error): New exception constructor.
>> (platform-not-found-error?): New predicate.
>> (false-if-platform-not-found): New syntax.
>> (lookup-platform-by-system): Raise an exception when no platform is found.
>> Update documentation.
>> (lookup-platform-by-target): Likewise.
>> (lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
>> false-if-platform-not-found.
>
> Sounds like a good idea!
>
>> +++ b/guix/platform.scm
>> @@ -21,6 +21,7 @@ (define-module (guix platform)
>>    #:use-module (guix memoization)
>>    #:use-module (guix records)
>>    #:use-module (guix ui)
>> +  #:use-module (ice-9 exceptions)
>
> So far the we use (srfi srfi-35) exclusively to define condition types;
> I think we should do the same here, for consistency.
>
>> +            &platform-not-found-error
>> +            make-platform-not-found-error
>
> The constructor doesn’t need to be exposed.
>
>> +;;;
>> +;;; Exceptions.
>> +;;;
>> +(define-exception-type &platform-not-found-error &error
>> +  make-platform-not-found-error platform-not-found-error?)
>
> So this would become (define-condition-type …).
>
> Otherwise LGTM, thanks!

The latest version incorporate these changes and use srfi-34/35 as is
currently custom in Guix.

I've now applied it.

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-01-19  1:57 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-14  3:05 [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
2023-01-14  3:08 ` [bug#60802] [PATCH 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
2023-01-14  3:08   ` [bug#60802] [PATCH 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
2023-01-14  4:19 ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
2023-01-14  4:19   ` [bug#60802] [PATCH v2 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
2023-01-14 14:34   ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Ludovic Courtès
2023-01-16 17:46     ` Maxim Cournoyer
2023-01-17  9:22       ` Ludovic Courtès
2023-01-14 14:34   ` Ludovic Courtès
2023-01-19  1:55     ` bug#60802: [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
2023-01-14 15:14 ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
2023-01-14 15:14   ` [bug#60802] [PATCH v3 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
2023-01-15 13:57   ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Josselin Poiret via Guix-patches via
2023-01-15 22:11     ` Maxim Cournoyer
2023-01-16 11:00     ` Simon Tournier
2023-01-17  8:59     ` Ludovic Courtès
2023-01-17 12:35       ` Simon Tournier
2023-01-17 14:38         ` Maxim Cournoyer
2023-01-17 15:34 ` [bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
2023-01-17 15:34   ` [bug#60802] [PATCH v4 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
2023-01-17 15:34   ` [bug#60802] [PATCH v4 2/2] gnu: Remove u-boot-malta Maxim Cournoyer

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).