From patchwork Fri Jun 18 16:09:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: M X-Patchwork-Id: 30375 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3EA3C27BC81; Fri, 18 Jun 2021 17:13:52 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B988027BC78 for ; Fri, 18 Jun 2021 17:13:51 +0100 (BST) Received: from localhost ([::1]:45142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luH7u-0005oZ-Pq for patchwork@mira.cbaines.net; Fri, 18 Jun 2021 12:13:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luH5C-000069-Np for guix-patches@gnu.org; Fri, 18 Jun 2021 12:11:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luH5C-00024Q-Cz for guix-patches@gnu.org; Fri, 18 Jun 2021 12:11:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1luH5C-0002xS-93 for guix-patches@gnu.org; Fri, 18 Jun 2021 12:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49025] [[PATCH v2 core-updates] 03/37] packages: Define this-package-input and this-package-native-input. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 18 Jun 2021 16:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49025 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49025@debbugs.gnu.org Cc: othacehe@gnu.org, Maxime Devos Received: via spool by 49025-submit@debbugs.gnu.org id=B49025.162403261310905 (code B ref 49025); Fri, 18 Jun 2021 16:11:02 +0000 Received: (at 49025) by debbugs.gnu.org; 18 Jun 2021 16:10:13 +0000 Received: from localhost ([127.0.0.1]:57697 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luH4O-0002pc-8L for submit@debbugs.gnu.org; Fri, 18 Jun 2021 12:10:12 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:49146) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luH4L-0002o5-HW for 49025@debbugs.gnu.org; Fri, 18 Jun 2021 12:10:09 -0400 Received: from localhost.localdomain ([188.188.242.184]) by baptiste.telenet-ops.be with bizsmtp id Jg9t250053zRM2s01gA8Ld; Fri, 18 Jun 2021 18:10:09 +0200 From: Maxime Devos Date: Fri, 18 Jun 2021 18:09:02 +0200 Message-Id: <20210618160936.18972-3-maximedevos@telenet.be> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210618160936.18972-1-maximedevos@telenet.be> References: <20210618160936.18972-1-maximedevos@telenet.be> MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1624032609; bh=ktlZPKOFCiKBCSKOml0XVUAO70kiPtFkDzCU75II8EQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=cvmCAGKwLgN88eu8pcUIdZP6m4oZGhdpckDMlAVrs8nmFEETqpDgIG6XdOgTnkSr5 +asQiBurFdEb7k/YnHYop16KaRDRhxkO4+C37kVa6Bygt9k9jtNpwdcudCCcGxXYFh CDUjivqKwDPZjvOJwaQ/uctRrh20nwPvA6adb16U1An99fy8JXCd6D1DG5gwLeRjf+ Tzj4aIUea6INP6N4YDl2XQ/K4Hi6vqhnpMbr1czo2cm+paIiMRSy/0w7fv/lxyJrI5 uTl54yJRqHLe+F6pxsrWjY/ZsoZheCBB+bvAUy8XcVlOtA4asTIrQCHNKEP1y6oPA1 0ARwKGoq94DxA== 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: , Reply-To: 49025@debbugs.gnu.org Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches These macros are intended to be used in build phases. More precisely, (assoc-ref %build-inputs "input") can be replaced by #$(this-package-input "input") or #+(this-package-native-input "native-input") as appropriate. * guix/packages.scm (package-input, package-native-input): New (unexported) procedures. (this-package-input, this-package-native-input): New macros. --- guix/packages.scm | 29 +++++++++++++++++++++++++++++ tests/packages.scm | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/guix/packages.scm b/guix/packages.scm index a66dbea1b7..80c8bbebf0 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -108,6 +108,9 @@ deprecated-package package-field-location + this-package-input + this-package-native-input + package-direct-sources package-transitive-sources package-direct-inputs @@ -513,6 +516,32 @@ object." #f))) (_ #f))) +(define (package-input package name) + "Return the package input NAME of PACKAGE--i.e., an input +from the ‘inputs’ or ‘propagated-inputs’ field. Native inputs are not +considered. If this input does not exist, return #f instead." + (and=> (or (assoc-ref (package-inputs package) name) + (assoc-ref (package-propagated-inputs package) name)) + car)) + +(define (package-native-input package name) + "Return the native package input NAME of PACKAGE--i.e., an input +from the ‘native-inputs’ field. If this native input does not exist, +return #f instead." + (and=> (assoc-ref (package-native-inputs package) name) + car)) + +(define-syntax-rule (this-package-input name) + "Return the input NAME of the package being defined--i.e., an input +from the ‘inputs’ or ‘propagated-inputs’ field. Native inputs are not +considered. If this input does not exist, return #f instead." + (package-input this-package name)) + +(define-syntax-rule (this-package-native-input name) + "Return the native package input NAME of the package being defined--i.e., +an input from the ‘native-inputs’ field. If this native input does not +exist, return #f instead." + (package-native-input this-package name)) ;; Error conditions. diff --git a/tests/packages.scm b/tests/packages.scm index 47d10af5bc..91ec38e4cc 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2021 Maxim Cournoyer +;;; Copyright © 2021 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -1851,6 +1852,39 @@ (package-location (specification->package "guile@2")) (specification->location "guile@2")) +(test-eq "this-package-input, exists" + hello + (package-arguments + (dummy-package "a" + (inputs `(("hello" ,hello))) + (arguments (this-package-input "hello"))))) + +(test-eq "this-package-input, exists in propagated-inputs" + hello + (package-arguments + (dummy-package "a" + (propagated-inputs `(("hello" ,hello))) + (arguments (this-package-input "hello"))))) + +(test-eq "this-package-input, does not exist" + #f + (package-arguments + (dummy-package "a" + (arguments (this-package-input "hello"))))) + +(test-eq "this-package-native-input, exists" + hello + (package-arguments + (dummy-package "a" + (native-inputs `(("hello" ,hello))) + (arguments (this-package-native-input "hello"))))) + +(test-eq "this-package-native-input, does not exists" + #f + (package-arguments + (dummy-package "a" + (arguments (this-package-native-input "hello"))))) + (test-end "packages") ;;; Local Variables: