From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 SFoiNjzAxmMhfQEAbAwnHQ (envelope-from ) for ; Tue, 17 Jan 2023 16:35:24 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id aNMGNjzAxmME4gAA9RJhRA (envelope-from ) for ; Tue, 17 Jan 2023 16:35:24 +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 935DA16EC0 for ; Tue, 17 Jan 2023 16:35:24 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHnzU-00032l-N4; Tue, 17 Jan 2023 10:35:12 -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 1pHnzK-00031J-CI for guix-patches@gnu.org; Tue, 17 Jan 2023 10:35: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 1pHnzK-0005d3-3q for guix-patches@gnu.org; Tue, 17 Jan 2023 10:35:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pHnzK-0005YA-07 for guix-patches@gnu.org; Tue, 17 Jan 2023 10:35:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60802] [PATCH v4 1/2] platforms: Raise an exception when no suitable platform is found. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 17 Jan 2023 15:35:01 +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 , ludo@gnu.org, Christopher Baines , Ricardo Wurmus Received: via spool by 60802-submit@debbugs.gnu.org id=B60802.167396969421298 (code B ref 60802); Tue, 17 Jan 2023 15:35:01 +0000 Received: (at 60802) by debbugs.gnu.org; 17 Jan 2023 15:34:54 +0000 Received: from localhost ([127.0.0.1]:37984 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pHnzB-0005XM-Cx for submit@debbugs.gnu.org; Tue, 17 Jan 2023 10:34:54 -0500 Received: from mail-yw1-f175.google.com ([209.85.128.175]:37813) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pHnz9-0005X1-Vg for 60802@debbugs.gnu.org; Tue, 17 Jan 2023 10:34:52 -0500 Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-4e4a6af2d99so107989117b3.4 for <60802@debbugs.gnu.org>; Tue, 17 Jan 2023 07:34:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y4XPlDddqK4NoaX+kNEJ+cMlu2cUdms/s7uZN7IfHe8=; b=nWBY+bthSoRebd3qEoSFWv5iInX/MoycLiHDBo8ODXMNYM7eZIfYnNh1n9UusgU47q bisHzohWNKmRUaS+DmTFq0TFZRpeZdAmyCK8GKAwaSIjwJGaySBBpNbrnOYafBnPVDMx jIlIn7JSn9O0v7ioxVjy7y7zMyM8gC1HYFWshMBDX0/MXaFyKarZ41uAOPO/z3Qw/G4k lEcSRHGpipW6z+v/W3+xI1fPXFl7waI8Ov6v9YIs05IlGjjf0BF8eTpd7cyowItfR8mL eOhJI5Dh/yR8mvYajbSb2qm6k08Y5E5M0yO8AF8d1g2mA/9WFVSRR2pa58hA0J4kuuCQ o3Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y4XPlDddqK4NoaX+kNEJ+cMlu2cUdms/s7uZN7IfHe8=; b=JIdnHTBsNOWpfNK8/HWW8P5MmMzzWnNksBw2OHSbqM62JTwNI9seGPxn+thyihywHu upQkRXSyBorBW3Yzx24Njpdrd1cPuwnUv8tz0+AKitFp37CzCysxtYmsHfSEUZwJzMiP XBAxelQyLHyfKfiJgUGujfzZsgRiuvOvihp+lAkMhmYw689PU+UMaDp+SOliD7P8cBiy sNx9r3W1HvoJ+VbUgTa80DY/+VeEKqChAfa+ssAWZ7OU3gq842XTvSp3awW2Tyi0Sd2Q Vlx9xSDTbYce5ulRWR6thWlb2wmVLDuDlrAHyb3UHx2w3tUjdeyVcv+BHGUtNChH7nd7 0UTQ== X-Gm-Message-State: AFqh2kq0vAzL9e47LaEIZMlId9CgP6XRiyW1vuQTwuHaPCQTcDUgwS6U Reg+g8Foak1iaGnfQwZgWDvYPDRKzmsCA0VK X-Google-Smtp-Source: AMrXdXvRuaqbM4Re9svmHzrXaGRUjL33iozW41hQAHamXFhO+8jxKwCkj60fdbbvq6ZmP65uBUf44Q== X-Received: by 2002:a05:7508:1315:b0:49:d9d4:d7dd with SMTP id cr21-20020a057508131500b00049d9d4d7ddmr117100gbb.12.1673969686141; Tue, 17 Jan 2023 07:34:46 -0800 (PST) Received: from localhost.localdomain (dsl-205-233-125-107.b2b2c.ca. [205.233.125.107]) by smtp.gmail.com with ESMTPSA id dt41-20020a05620a47a900b00705e7daf6f0sm5206505qkb.129.2023.01.17.07.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 07:34:45 -0800 (PST) From: Maxim Cournoyer Date: Tue, 17 Jan 2023 10:34:30 -0500 Message-Id: <20230117153432.23719-2-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230117153432.23719-1-maxim.cournoyer@gmail.com> References: <20230117153432.23719-1-maxim.cournoyer@gmail.com> 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=nWBY+bth; 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=1673969724; a=rsa-sha256; cv=none; b=Ll9OcWi+YBXE9nixj8VBm9RiMYeOhFRsB8SlsyV+aNaQO8dTdOIGjlszsDA+zUuvEosDL8 27jfzGLJ6nzB+vZJble74aBK1ZySljT/1OwUxUrCE1fMee+dy7reStqRPiXpXOVcP0MhLi eygg1xlwp4xLL/B2CFKEsJjF8yO/cTrNRpLywb1tg+k0b/7XNKaD6tWvgrJgdp9P4+67/S KMI1gT9vSSi5j1Hps+15jozmxtNZlj9ZNXql4Tf2OTauN1lhTijw+rhKCJUfK341rXXUp/ voRN2PUADm+RDCvJROINUhQT9fxt4YqxGTxmRFTtiw3ZSacsM4E3F1HS2UqOgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1673969724; 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=+VTYD/6JMbjDFqN1p9WrRELDfFhMFBfV5c32BbxCmlw=; b=B2cklTj6w/Rl+5oFZXBC3Ay0Iu4pLXdz62SMtVUi/vWyCVHERilh0Faig8dZDlAv3rH+/f wDiFaXswa8bdVCtuTLw0Cj+6il0O1kXYSn1rqGCWY4s/KF2DXz/IU8g5WOLMZrIO2RPES1 tBGJkmbACYe8uT9xu263JU2J92QB78rWyUpfhwbEJtF052oxiwDzcAWsyTAYOTfKCMU1lm O/IwhaO5iX4GfOLzACZn9u65wHDe/TDzFJsTWISjjicCeMyabHDpS2ChAg93YwlryuNkGK sNyMhSBFMC2LA/J+1K1vy7nEOZ9zzPuvNOl92pXHLbW8FJyII2x5KO95Mr6VNQ== Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=nWBY+bth; 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: -0.03 X-Spam-Score: -0.03 X-Migadu-Queue-Id: 935DA16EC0 X-Migadu-Scanner: scn1.migadu.com X-TUID: UGjlVa4yY8nj 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 make-platform (default #false)) (glibc-dynamic-linker platform-glibc-dynamic-linker)) + +;;; +;;; 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)) + ;;; ;;; 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