From patchwork Tue Oct 3 09:17:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hilton Chain X-Patchwork-Id: 54461 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 9202927BBE9; Tue, 3 Oct 2023 10:19:16 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6F7B127BBE2 for ; Tue, 3 Oct 2023 10:19:15 +0100 (BST) 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== Authentication-Results: mail.boiledscript.com; auth=pass smtp.mailfrom=hako@ultrarare.space Date: Tue, 3 Oct 2023 17:17:02 +0800 Message-ID: In-Reply-To: References: MIME-Version: 1.0 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 X-Patchwork-Original-From: Hilton Chain via Guix-patches via From: Hilton Chain Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * 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)