From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id EKdPElkzwmNnbAEAbAwnHQ (envelope-from ) for ; Sat, 14 Jan 2023 05:45:13 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id KG5DElkzwmOxOwAAauVa8A (envelope-from ) for ; Sat, 14 Jan 2023 05:45:13 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0C00BA434 for ; Sat, 14 Jan 2023 05:45:12 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGY1V-0002tk-FK; Fri, 13 Jan 2023 23:20:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGY1T-0002sk-Cl for guix-patches@gnu.org; Fri, 13 Jan 2023 23:20:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pGY1S-0000Nz-S5 for guix-patches@gnu.org; Fri, 13 Jan 2023 23:20:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pGY1S-0000RC-Cx for guix-patches@gnu.org; Fri, 13 Jan 2023 23:20:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found. References: <20230114030542.23524-1-maxim.cournoyer@gmail.com> In-Reply-To: <20230114030542.23524-1-maxim.cournoyer@gmail.com> Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 14 Jan 2023 04:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60802 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60802@debbugs.gnu.org Cc: Josselin Poiret , Tobias Geerinckx-Rice , Maxim Cournoyer , Simon Tournier , Mathieu Othacehe , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines , Ricardo Wurmus Received: via spool by 60802-submit@debbugs.gnu.org id=B60802.16736699621618 (code B ref 60802); Sat, 14 Jan 2023 04:20:02 +0000 Received: (at 60802) by debbugs.gnu.org; 14 Jan 2023 04:19:22 +0000 Received: from localhost ([127.0.0.1]:52940 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGY0n-0000Q2-Fj for submit@debbugs.gnu.org; Fri, 13 Jan 2023 23:19:21 -0500 Received: from mail-qv1-f54.google.com ([209.85.219.54]:36383) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGY0l-0000Po-C3 for 60802@debbugs.gnu.org; Fri, 13 Jan 2023 23:19:19 -0500 Received: by mail-qv1-f54.google.com with SMTP id t7so16136408qvv.3 for <60802@debbugs.gnu.org>; Fri, 13 Jan 2023 20:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=d2yFsFQcb/8mWoUj6ZKYdIAUV55ddX33kj8Oo6ZN1Gw=; b=H3bEUfl/EIP8s9lfR0jjM7AkeSFt/Pht5aoM5Htn+YpqyiSYZQdv1UB9cTuqt0+kM4 bhM5T4Nkzqfb0H8oXexb0qKRzVdgvVn3pKA7RjgOk7MQTs7K4VjZrvD9874rDlOzlhA3 s0ySPN+cfwzgQnEGPOLc12lG12HnRN60jkTJmd2eeGTVBCF/YZl3eN98Z/SfS8p/NA3M NTE+lBty222C7OeXYp2hX3sY+YAT/TvSm7OjA7wFtOUMTxAcEj6SFPUTgIlK+Z6qHJJ1 t/qWxoaF4O/VKBRDNhSBPfVPOqh5uhfXH3TLfJH2roObakZkS7R4IFYARK+mdQ8BqD35 BafQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=d2yFsFQcb/8mWoUj6ZKYdIAUV55ddX33kj8Oo6ZN1Gw=; b=6zYo4pxUpFJlNTJgBmn885GgKNyYoAHUFDmKv2vMoOEgwQYPi7cfs09nVqegQaJrfl RcoEvwqFxdWMOhwANzoKKRiwnXiunMhtehcrkLtB+oXBg3+aOlNQ0UBCSLpx+kvPXrfz n+avL5Tp6hK8tjBb7HStlzNQ9OPbs05itKA9ek2k+6rLDXXzzjTKQyr6PFc/r28jJW42 A3kqbshPAAV4nI1i6X+QsdfG8L5rYHdTois3Nd1LU+UIK6iDZLyh4Drlz0PWUwY7zKwq XuvluOCPaGmHv55qPw6DySMRyNWMrgTbIEfGMFHcJ2GzrAxH9BWilUl4fgQ5igcm64M9 ysOg== X-Gm-Message-State: AFqh2kpUbLGpyyRY1PFNEvfmq/TNKewmQJlaq5NIOLoGO1cCx1Iz75zw MXPjvSy8yiIZ9gxk6Sq6JfEnOXA5/x81e/kq X-Google-Smtp-Source: AMrXdXtz19nmTaFd6KPSLYMd5mTgzD7JGUZKZYf4N4XnNTKQ0CH4iQmBOR6l8LEkQBYkPpAq2pP0WQ== X-Received: by 2002:a0c:ee2b:0:b0:4e3:6abf:ddb4 with SMTP id l11-20020a0cee2b000000b004e36abfddb4mr94918094qvs.23.1673669953405; Fri, 13 Jan 2023 20:19:13 -0800 (PST) Received: from localhost.localdomain (dsl-10-149-10.b2b2c.ca. [72.10.149.10]) by smtp.gmail.com with ESMTPSA id br31-20020a05620a461f00b006fa2cc1b0fbsm13770007qkb.11.2023.01.13.20.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 20:19:12 -0800 (PST) From: Maxim Cournoyer Date: Fri, 13 Jan 2023 23:19:02 -0500 Message-Id: <20230114041903.7121-2-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="H3bEUfl/"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1673671513; a=rsa-sha256; cv=none; b=J9uZTkJ2GZ/XQ6FeTwM3RpvEnoW+HxHE2dklXmdYw8JbaQkgYYDrpSyjCdIApCGPWKTGyg 9iyIocwIFnVslGBmHtdnFDZ0clOhrzi5w7ehf9bJga+N/oy9vCbXwD3bAQXwbBtc9TArmG CBj0JZk3RpIhrbFlA247sXg3a0ReOOfQ6R/aDFMXdNanKF6cOQ0wvLPM/iTh3ECTtUTAPg 06AA5JFnR5whYmFtQ//85sxAv65uUxOT7Qwwyx+DCGqXLctCzf768TpwbR+u4CKbHXoEFm C8IwdY5kKUYftyVvRNgGBtvFTZ/ElgZQGsLfB1G+xw+kel5cKvKwcetaxaw0vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1673671513; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=B9qYetHFA+hSJ11HpcGodD5zQEctTL9nm/RnScYEcTA=; b=rZItAkGO5irk0kiW7hl2i3dFLvJPmCpaURADE3QBzNRkUXDjIZCjHwamHyMshJmVzLVls5 0zpqgRHTGoZ1nshq7tM15HxNuW9UvgQpoSGMypy183fpS5NiYNuVaebkASFmxlFR3sa45u gRhCHtQCwxPvGsLw4YAQbabsLmi80ZGCiB87WdkBMRuNXCfSbwjVpMBA6s1KdBa2ghp8Ql 1jI8EYSk+cF09ZF2tGHY24VuMw6t4/AWlB1jUu8ZJRR6qtbuzzqjfzb0rJV1yl3dqIQOBV wet6lfBuKoN52R8YLq1zhoABpRiymfwyPeHoNTuOS7gTTB3+L44Ymo/8JCZp/A== X-Migadu-Queue-Id: 0C00BA434 X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="H3bEUfl/"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) X-Migadu-Spam-Score: -1.41 X-Spam-Score: -1.41 X-TUID: svsEN3S2l5f9 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 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 +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