From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YGcWOw7Z3GAmZQEAgWs5BA (envelope-from ) for ; Wed, 30 Jun 2021 22:50:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id iDy+Ng7Z3GDERAAAB5/wlQ (envelope-from ) for ; Wed, 30 Jun 2021 20:50:22 +0000 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 A81CF1D99D for ; Wed, 30 Jun 2021 22:50:22 +0200 (CEST) Received: from localhost ([::1]:53940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyhA5-0001SJ-O1 for larch@yhetil.org; Wed, 30 Jun 2021 16:50:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyh9o-0000qG-H5 for guix-patches@gnu.org; Wed, 30 Jun 2021 16:50:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyh9o-0001hQ-9J for guix-patches@gnu.org; Wed, 30 Jun 2021 16:50:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lyh9o-0005CC-3T for guix-patches@gnu.org; Wed, 30 Jun 2021 16:50:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49169] [PATCH v2 04/16] packages: Add 'lookup-package-input' & co. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 30 Jun 2021 20:50:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49169@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 49169-submit@debbugs.gnu.org id=B49169.162508615319801 (code B ref 49169); Wed, 30 Jun 2021 20:50:04 +0000 Received: (at 49169) by debbugs.gnu.org; 30 Jun 2021 20:49:13 +0000 Received: from localhost ([127.0.0.1]:58930 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyh8y-000599-Lm for submit@debbugs.gnu.org; Wed, 30 Jun 2021 16:49:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47868) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyh8k-00055k-Ks for 49169@debbugs.gnu.org; Wed, 30 Jun 2021 16:48:59 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:53126) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyh8f-0000xG-DW; Wed, 30 Jun 2021 16:48:53 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=42586 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyh8f-0001jQ-5o; Wed, 30 Jun 2021 16:48:53 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 30 Jun 2021 22:48:20 +0200 Message-Id: <20210630204832.25753-5-ludo@gnu.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210630204832.25753-1-ludo@gnu.org> References: <20210622090221.15182-1-ludo@gnu.org> <20210630204832.25753-1-ludo@gnu.org> 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" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1625086222; 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; bh=u0Y1BtarpkGphkwjeGxDWKtKm+SWSrCOQNuQ3ISKaao=; b=RvDMSbB+/38w2dGQCtVt14sTIeMxopxENJFlqLVVWrd2IJOGrLGGgYHhVj3h4QhLkeT8rh hunZQ49zkQqclIAuJ0sz2cJYqKc01fNlcSDDSVOUvRlg/bpIHMbBBemlMq0OF8SFyCocC4 GMlryOgz1xDmK2/MgME89WDaquyDLeGk6TQKUiU88iZvgMNkWh8RMkY5j2fz8CnqPAeBnI qQ1uoDHLoeCYyb/uiODj8fP0Bp+reEK3aL180FhZPetSg8K6k/nsO+T0iKyyV2C9hqRyaS 5IOvyhLg+4ei7dFH6i6qUNifDQyQg2xq5SeWU8g+LcwG53QtyjLoO6HcJnl91A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1625086222; a=rsa-sha256; cv=none; b=IXHBNj7SsKkuYXH2wOUWcztQVRxd0XdzNTIzsAMkgbuKATDVr32B0AeTUe/b0vpf7JACrk JlF6geneejF8OhLn4xyVysJC+IIphR6+rJgBUXTWj2IuFqLQm20lW8Pi4R5z8LcheAB0FN ta5IEfGYOg2Tyt3hHjQ4e+jttnY/gVS3j3IEGmGtSXLhOIl7MlUHvmuYQRhsWskPLlllnf jmZt6yaymSBBgf9qj/1XaBpyyFGXEckasiKxgykvILKD08EgvgCBlepULcQxx5Zb9J7yxe arfz5dPY0myU0XFRmNQxow14G9nxvoat5rBDLXEBrCtRPBvkvIukXK0OEhoUCw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 3.58 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: A81CF1D99D X-Spam-Score: 3.58 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9Vf9u528Edlu * guix/packages.scm (lookup-input, lookup-package-input) (lookup-package-native-input, lookup-package-propagated-input) (lookup-package-direct-input): New procedures. * doc/guix.texi (package Reference): Document them. --- doc/guix.texi | 24 ++++++++++++++++++++++++ guix/packages.scm | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index 0e5d1a9fa7..d88f857c3a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6817,6 +6817,30 @@ cross-compiling: It is an error to refer to @code{this-package} outside a package definition. @end deffn +The following helper procedures are provided to help deal with package +inputs. + +@deffn {Scheme Procedure} lookup-package-input @var{package} @var{name} +@deffnx {Scheme Procedure} lookup-package-native-input @var{package} @var{name} +@deffnx {Scheme Procedure} lookup-package-propagated-input @var{package} @var{name} +@deffnx {Scheme Procedure} lookup-package-direct-input @var{package} @var{name} +Look up @var{name} among @var{package}'s inputs (or native, propagated, +or direct inputs). Return it if found, @code{#f} otherwise. + +@var{name} is the name of a package depended on. Here's how you might +use it: + +@lisp +(use-modules (guix packages) (gnu packages base)) + +(lookup-package-direct-input coreutils "gmp") +@result{} # +@end lisp + +In this example we obtain the @code{gmp} package that is among the +direct inputs of @code{coreutils}. +@end deffn + Because packages are regular Scheme objects that capture a complete dependency graph and associated build procedures, it is often useful to write procedures that take a package and return a modified version diff --git a/guix/packages.scm b/guix/packages.scm index 087e6e6a4a..c845026827 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -108,6 +108,11 @@ deprecated-package package-field-location + lookup-package-input + lookup-package-native-input + lookup-package-propagated-input + lookup-package-direct-input + package-direct-sources package-transitive-sources package-direct-inputs @@ -889,6 +894,35 @@ preserved, and only duplicate propagated inputs are removed." ((input rest ...) (loop rest (cons input result) propagated first? seen))))) +(define (lookup-input inputs name) + "Lookup NAME among INPUTS, an input list." + ;; Note: Currently INPUTS is assumed to be an input list that contains input + ;; labels. In the future, input labels will be gone and this procedure will + ;; check package names. + (match (assoc-ref inputs name) + ((obj) obj) + ((obj _) obj) + (#f #f))) + +(define (lookup-package-input package name) + "Look up NAME among PACKAGE's inputs. Return it if found, #f otherwise." + (lookup-input (package-inputs package) name)) + +(define (lookup-package-native-input package name) + "Look up NAME among PACKAGE's native inputs. Return it if found, #f +otherwise." + (lookup-input (package-native-inputs package) name)) + +(define (lookup-package-propagated-input package name) + "Look up NAME among PACKAGE's propagated inputs. Return it if found, #f +otherwise." + (lookup-input (package-propagated-inputs package) name)) + +(define (lookup-package-direct-input package name) + "Look up NAME among PACKAGE's direct inputs. Return it if found, #f +otherwise." + (lookup-input (package-direct-inputs package) name)) + (define (package-direct-sources package) "Return all source origins associated with PACKAGE; including origins in PACKAGE's inputs." -- 2.32.0