From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id kGy0CKXcG2Vu2AAAG6o9tA:P1 (envelope-from ) for ; Tue, 03 Oct 2023 11:19:33 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id kGy0CKXcG2Vu2AAAG6o9tA (envelope-from ) for ; Tue, 03 Oct 2023 11:19:33 +0200 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 DC7D6AC7D for ; Tue, 3 Oct 2023 11:19:32 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=ultrarare.space header.s=dkim header.b=QrFvZtNp; 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=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1696324773; h=from:from:sender:sender:reply-to: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=NF4JW0/Yknw0f9tUlXGYLqtLnA4YroMjeEGMaOeoI+o=; b=RC9mQ+PSdO4HoScIFew9GZ7HaXgNqGMz3Ia+96EX7kZTwbyvhwAnDdAKmrnAVw6lji7E+E +T41vAK0dAryC40qHwYWL6plEPQEVuz4M8poiA29hQB0XZ+YOiT7toRuP52SSzIcZqsCmg KZGpkxkVVzC66ABqy3ycwNIhg43wvksu9yyvQdCjfED4bSVA/VcoZ8nl8+2VRh+cgHMr24 l4vf6OxLJYkZmoHX2kiqC3CfI6L0yy31TO4NP9ho9UO34HjLa9SaN1iFK1CHv8uiYAlB4I 5BdyAlOO4i5XtKrP7ndO8ravasxcBX+RzR00hkiBJAWakiyL+uHsXpgJ6WyYjw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1696324773; a=rsa-sha256; cv=none; b=HWF+iMw2Ub8wd02nXKvKkfT5ZF2/ykjySX7hi/W0KD4Zshmyx4bsiV7foJzMdBKsjtwAHv I4S9zI74eXo9jFarIRrDp56NQOQm5l4d+x5ZHKAgbIZUMeBo11EM+NGK2Vdh269WdtLpPg Qlib593auhtLiPfaGOrYmtH+sTX6m3UHv8LTVVC77yVN3yUNhT7tR9KP5bRU1cbg4mqMy3 q1w24dbniRKWs9g5BcmiCcRM6cCSYBlunSxB597Ubqnfrk2uJczxiIzvfqn4kc2YhxY7mH plAqq7GqfNKjzNI5Fqx0VIyeGW07IoZq+WcyXoxQ0k6mXwhTMSToKr9iCETRZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=ultrarare.space header.s=dkim header.b=QrFvZtNp; 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=pass (policy=none) header.from=gnu.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnbYP-000857-A2; Tue, 03 Oct 2023 05:18:57 -0400 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 1qnbYJ-00083g-JB for guix-patches@gnu.org; Tue, 03 Oct 2023 05:18:52 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnbYI-0002in-6o; Tue, 03 Oct 2023 05:18:51 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qnbYV-0003SC-1W; Tue, 03 Oct 2023 05:19:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65062] [PATCH v2 core-updates 2/2] packages: Lookup inputs by specification. Resent-From: Hilton Chain Original-Sender: "Debbugs-submit" Resent-CC: hako@ultrarare.space, ludo@gnu.org, dev@jpoiret.xyz, guix@cbaines.net, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 03 Oct 2023 09:19:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65062 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo patch To: 65062@debbugs.gnu.org Cc: Hilton Chain , Hilton Chain , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Josselin Poiret , Christopher Baines , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Hilton Chain , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Josselin Poiret , Christopher Baines , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 65062-submit@debbugs.gnu.org id=B65062.169632471813226 (code B ref 65062); Tue, 03 Oct 2023 09:19:03 +0000 Received: (at 65062) by debbugs.gnu.org; 3 Oct 2023 09:18:38 +0000 Received: from localhost ([127.0.0.1]:38795 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnbY6-0003RD-2M for submit@debbugs.gnu.org; Tue, 03 Oct 2023 05:18:38 -0400 Received: from mail.boiledscript.com ([144.168.59.46]:36166) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnbY4-0003R1-B2 for 65062@debbugs.gnu.org; Tue, 03 Oct 2023 05:18:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ultrarare.space; s=dkim; t=1696324585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NF4JW0/Yknw0f9tUlXGYLqtLnA4YroMjeEGMaOeoI+o=; b=QrFvZtNpFhHx0CQBjZrwzKRKeeERpNZtvn6mDIno2M+vejtIYUE7XjhNTensUW5u1n/Vds Qf9U2DJtK7crmqohFMAKis+eRT+X079/TtZctzk80C6uCLWLwVH/STEubZQO6JfrETsvWt FXU/fF2qIM3vw9ttHC3pQqWTAyjImFxr4mvXsjk8d/HQoFB45ZXawXZZ/9LyEVvBqzoW89 Sar5Cfri5iXJ2Fa2IdqtLJrL15/3j+Gb55EpV1VqRalYvY/Ik9ZdZSmrAqalOifG1Z9Zhm PPmS4QVwpyf6nPJQD5jJ5M12Qj1jgsjfYzCylpwxAz7eCdnfy6pKYkBwd6ojkA== Date: Tue, 3 Oct 2023 17:17:02 +0800 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: -- 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: Hilton Chain X-ACL-Warn: , Hilton Chain via Guix-patches From: Hilton Chain via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx0.migadu.com X-Migadu-Spam-Score: -4.73 X-Spam-Score: -4.73 X-Migadu-Queue-Id: DC7D6AC7D X-TUID: IK+Gmn6v3ZL0 * guix/packages.scm (specification->inputs): New procedure. (lookup-input,replace-input): Use it. (delete-input): New procedure. (modify-inputs)[delete]: Use it. --- guix/packages.scm | 72 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/guix/packages.scm b/guix/packages.scm index b004882cc6..45552bfb7f 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -1173,15 +1173,49 @@ (define (transitive-inputs inputs) ((input rest ...) (loop rest (cons input result) propagated first? seen))))) +(define (specification->inputs spec inputs) + "Lookup inputs specified by SPEC among INPUTS, an input list. Return an input +list consists of all matching inputs, or '(). SPEC may be a package name, +optionally containing a version number or an output name, as in these examples: + + guile + guile@2.0.9 + guile:debug + guile@2.0.9:debug + +If SPEC does not specify a version number, all versions are matched; if SPEC +does not specify an output, all outputs are matched. + +SPEC can be an input label as well." + (let ((name version sub-drv + (package-specification->name+version+output spec #f))) + (filter-map + (lambda (input) + (match input + (((? string? label) (? package? package) . outputs) + (and (or (and (string=? name (package-name package)) + (when version + (string-prefix? version (package-version package))) + (when sub-drv + (and (not (null? outputs)) + (string=? sub-drv (first outputs))))) + ;; fallback to input label + (string=? label spec)) + input)) + ;; not a package + (((? string? label) _ . _) + (and (string=? label spec) + input)))) + inputs))) + (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))) + (let ((candidates (specification->inputs name inputs))) + (and (not (null? candidates)) + (second (first candidates))))) (define (lookup-package-input package name) "Look up NAME among PACKAGE's inputs. Return it if found, #f otherwise." @@ -1202,17 +1236,25 @@ (define (lookup-package-direct-input package name) otherwise." (lookup-input (package-direct-inputs package) name)) +(define (delete-input name inputs) + "Delete input NAME within INPUTS." + (let ((to-delete (specification->inputs name inputs))) + (lset-difference equal? inputs to-delete))) + (define (replace-input name replacement inputs) "Replace input NAME by REPLACEMENT within INPUTS." - (map (lambda (input) - (match input - (((? string? label) _ . outputs) - (if (string=? label name) - (match replacement ;does REPLACEMENT specify an output? - ((_ _) (cons label replacement)) - (_ (cons* label replacement outputs))) - input)))) - inputs)) + (let ((to-replace (specification->inputs name inputs))) + (append + (lset-difference equal? inputs to-replace) + (if (null? to-replace) + '() + (map (lambda (input) + (match input + ((label _ . outputs) + (match replacement ;does REPLACEMENT specify an output? + ((_ _) (cons label replacement)) + (_ (cons* label replacement outputs)))))) + to-replace))))) (define-syntax prepend (lambda (s) @@ -1244,10 +1286,10 @@ (define-syntax modify-inputs ;; 'package-inputs' & co., is actually an alist with labels. Eventually, ;; it will operate on list of inputs without labels. ((_ inputs (delete name) clauses ...) - (modify-inputs (alist-delete name inputs) + (modify-inputs (delete-input name inputs) clauses ...)) ((_ inputs (delete names ...) clauses ...) - (modify-inputs (fold alist-delete inputs (list names ...)) + (modify-inputs (fold delete-input inputs (list names ...)) clauses ...)) ((_ inputs (prepend lst ...) clauses ...) (modify-inputs (append (map add-input-label (list lst ...)) inputs) -- 2.41.0