[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitabl
From: |
Maxim Cournoyer |
Subject: |
[bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found. |
Date: |
Sat, 14 Jan 2023 10:14:56 -0500 |
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))
+
+;;;
+;;; 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))
+
;;;
;;; 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
- [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package, Maxim Cournoyer, 2023/01/13
- [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found.,
Maxim Cournoyer <=
- [bug#60802] [PATCH v3 2/2] gnu: Remove u-boot-malta., Maxim Cournoyer, 2023/01/14
- [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found., Josselin Poiret, 2023/01/15
- [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found., Maxim Cournoyer, 2023/01/15
- [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found., Simon Tournier, 2023/01/16
- [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found., Ludovic Courtès, 2023/01/17
- [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found., Simon Tournier, 2023/01/17
- [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found., Maxim Cournoyer, 2023/01/17
[bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package, Maxim Cournoyer, 2023/01/17