From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EE6XBcWo0WBAKAAAgWs5BA (envelope-from ) for ; Tue, 22 Jun 2021 11:09:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id GO06AcWo0WDHOQAAbx9fmQ (envelope-from ) for ; Tue, 22 Jun 2021 09:09:25 +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 92030185B3 for ; Tue, 22 Jun 2021 11:09:24 +0200 (CEST) Received: from localhost ([::1]:46862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lvcPL-0000YJ-Js for larch@yhetil.org; Tue, 22 Jun 2021 05:09:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvcP4-0008U1-DH for guix-patches@gnu.org; Tue, 22 Jun 2021 05:09:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54503) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lvcP1-00032X-Um for guix-patches@gnu.org; Tue, 22 Jun 2021 05:09:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lvcP1-0007np-PD for guix-patches@gnu.org; Tue, 22 Jun 2021 05:09:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49169] [PATCH 04/11] 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: Tue, 22 Jun 2021 09:09:03 +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.162435293529938 (code B ref 49169); Tue, 22 Jun 2021 09:09:03 +0000 Received: (at 49169) by debbugs.gnu.org; 22 Jun 2021 09:08:55 +0000 Received: from localhost ([127.0.0.1]:37807 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lvcOs-0007mj-RX for submit@debbugs.gnu.org; Tue, 22 Jun 2021 05:08:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32836) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lvcOn-0007lJ-PX for 49169@debbugs.gnu.org; Tue, 22 Jun 2021 05:08:50 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:52816) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lvcOi-0002o4-KJ; Tue, 22 Jun 2021 05:08:44 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=49370 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 1lvcOi-0000B8-7m; Tue, 22 Jun 2021 05:08:44 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 22 Jun 2021 11:08:23 +0200 Message-Id: <20210622090830.15561-4-ludo@gnu.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210622090830.15561-1-ludo@gnu.org> References: <20210622090830.15561-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=1624352964; 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=RoirJWXANSCfFtGJwnNcbos9qkGeJHZtzTeLTuru2r0=; b=qOCaJL+ssjIvK58ICfn/LYs1t/V7YMAt+OxqujvRaMZ9ai7q26GNbui+3WvkzZcyemDpme eroB3Jfdjg9MFAIiz+KnWhPsiOb9zOwfDXrlfB2nmVK+b5b+NBzkDBzy7WNJw5aNeTJTm9 zmeFMa4MGAwJMP9rENX/Qb42k4XdiBM8DtBRrAKnGVf3PKCzvGLgd2nw/qkaeGQnJj2qzD uPwM8ampBf001dCMUcnLmg0pHRnTNgs0QmfOKWQ1gswC+Yol3o10BZC97RQSYjFs0mMtdp Y5zhG0qslZkWXLHpF4M58wsDES9qqKH695NpFERECrEvn7CcyHQepzfyMjPCfw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1624352964; a=rsa-sha256; cv=none; b=j5lHvxU64ftCKkiyI/n6m3xP8NO38xm92fryDrOiXHOW1q7nVob3W6762gcLmmDUb15icI iL4MHN+5+TwZOacp7SPO/YFffO2pCxLWpJOxQRAOQbQGic0Wyfes3woensPilWA8jrbVsl I1uZxjCcBZpAIndOupQCo4c2iXXcfmvGuOzYPOd0B322UNmFGmz3XIbisvy8Mm1gDr+RDX vR0mB4uoGiy1IIYplMeoFIRuPx9fZ9zxo2of8XrnBpuQV0V9zQxqXUZDjhnwoKxKAtVJhg AqXnXB+x7ufWIpWOWvUrXWvb0QVfECUbWMIODbs0mnalkaclPkZ14Ronuy2EKA== 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: 2.07 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: 92030185B3 X-Spam-Score: 2.07 X-Migadu-Scanner: scn1.migadu.com X-TUID: 9pLZF/otlg7O * 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 5ff3898ff1..aeb0b2160a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6802,6 +6802,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