From patchwork Mon Oct 17 06:49:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 43458 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 C141C27BBEA; Mon, 17 Oct 2022 07:53:37 +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=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable 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 312AB27BBE9 for ; Mon, 17 Oct 2022 07:53:37 +0100 (BST) Received: from localhost ([::1]:46894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okK0E-0000Hh-95 for patchwork@mira.cbaines.net; Mon, 17 Oct 2022 02:53:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okJwq-0000DC-02 for guix-patches@gnu.org; Mon, 17 Oct 2022 02:50:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1okJwp-00043C-NL for guix-patches@gnu.org; Mon, 17 Oct 2022 02:50:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1okJwp-0007av-J1 for guix-patches@gnu.org; Mon, 17 Oct 2022 02:50:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58579] [PATCH 3/4] grafts: Rewrite using gexps. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Oct 2022 06:50:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58579 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58579@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 58579-submit@debbugs.gnu.org id=B58579.166598938329137 (code B ref 58579); Mon, 17 Oct 2022 06:50:03 +0000 Received: (at 58579) by debbugs.gnu.org; 17 Oct 2022 06:49:43 +0000 Received: from localhost ([127.0.0.1]:46989 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1okJwV-0007Zo-0q for submit@debbugs.gnu.org; Mon, 17 Oct 2022 02:49:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37056) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1okJwQ-0007Yx-7s for 58579@debbugs.gnu.org; Mon, 17 Oct 2022 02:49:38 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okJwK-0003ub-0s; Mon, 17 Oct 2022 02:49:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=4grPZ3QYbdwMtZpD3r6COPe6d9Ns6AbWIa9pGrQv33o=; b=m5+aPj1AtQ/VoeYaqbAu 6IsnBLybHk6bRt+ZNj5ezJiDUbSeM+1TBPnCMcHt8Ly0X4iAOiHOmOtU5t2G6BMuio/1nHCp3cqak AgmiAyqdzbKtn8P2lhhpYLCqrx0xZrs/12UpPh1n203S8eYTuQo9D5PaYSfG2Vu0NC3L/qvxNhbMw DpyxdtJ2sTD6iJCoEFGpCPqcOQx2XBMemO8FxqX6+Sx6C8fGI+3hzigoD3d+qa2TPHtuzPjjkzxYh i69IpF0v1fz1gbaBVRw7xhhLpT8pkP2V3nQ6vjSnKxht0ydrgouO7xE/JlpWrx6Ep6HbIc2ZjzTVt nge8kVBHDthIgg==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=47894 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 1okJwJ-0004tN-G8; Mon, 17 Oct 2022 02:49:31 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 17 Oct 2022 08:49:23 +0200 Message-Id: <20221017064924.2379-3-ludo@gnu.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221017064924.2379-1-ludo@gnu.org> References: <20221017064924.2379-1-ludo@gnu.org> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Fixes . * guix/grafts.scm (graft-derivation/shallow): Rewrite using gexps and remove 'store' parameter. (graft-derivation/shallow*): New variable. (cumulative-grafts): Use it instead of 'graft-derivation/shallow'. --- guix/grafts.scm | 103 +++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 57 deletions(-) diff --git a/guix/grafts.scm b/guix/grafts.scm index 252abfd8b3..88406e1087 100644 --- a/guix/grafts.scm +++ b/guix/grafts.scm @@ -24,6 +24,7 @@ (define-module (guix grafts) #:use-module (guix derivations) #:use-module ((guix utils) #:select (%current-system)) #:use-module (guix sets) + #:use-module (guix gexp) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9 gnu) #:use-module (srfi srfi-26) @@ -78,7 +79,7 @@ (define (graft-origin-file-name graft) (($ (? string? item)) item))) -(define* (graft-derivation/shallow store drv grafts +(define* (graft-derivation/shallow drv grafts #:key (name (derivation-name drv)) (outputs (derivation-output-names drv)) @@ -87,72 +88,60 @@ (define* (graft-derivation/shallow store drv grafts "Return a derivation called NAME, which applies GRAFTS to the specified OUTPUTS of DRV. This procedure performs \"shallow\" grafting in that GRAFTS are not recursively applied to dependencies of DRV." - ;; XXX: Someday rewrite using gexps. (define mapping ;; List of store item pairs. - (map (match-lambda - (($ source source-output target target-output) - (cons (if (derivation? source) - (derivation->output-path source source-output) - source) - (if (derivation? target) - (derivation->output-path target target-output) - target)))) + (map (lambda (graft) + (gexp + ((ungexp (graft-origin graft) + (graft-origin-output graft)) + . (ungexp (graft-replacement graft) + (graft-replacement-output graft))))) grafts)) - (define output-pairs - (map (lambda (output) - (cons output - (derivation-output-path - (assoc-ref (derivation-outputs drv) output)))) - outputs)) - (define build - `(begin - (use-modules (guix build graft) - (guix build utils) - (ice-9 match)) + (with-imported-modules '((guix build graft) + (guix build utils) + (guix build debug-link) + (guix elf)) + #~(begin + (use-modules (guix build graft) + (guix build utils) + (ice-9 match)) - (let* ((old-outputs ',output-pairs) - (mapping (append ',mapping - (map (match-lambda - ((name . file) - (cons (assoc-ref old-outputs name) - file))) - %outputs)))) - (graft old-outputs %outputs mapping)))) + (define %outputs + (ungexp (outputs->gexp outputs))) + + (let* ((old-outputs '(ungexp + (map (lambda (output) + (gexp ((ungexp output) + . (ungexp drv output)))) + outputs))) + (mapping (append '(ungexp mapping) + (map (match-lambda + ((name . file) + (cons (assoc-ref old-outputs name) + file))) + %outputs)))) + (graft old-outputs %outputs mapping))))) - (define add-label - (cut cons "x" <>)) (define properties `((type . graft) (graft (count . ,(length grafts))))) - (match grafts - ((($ sources source-outputs targets target-outputs) ...) - (let ((sources (zip sources source-outputs)) - (targets (zip targets target-outputs))) - (build-expression->derivation store name build - #:system system - #:guile-for-build guile - #:modules '((guix build graft) - (guix build utils) - (guix build debug-link) - (guix elf)) - #:inputs `(,@(map (lambda (out) - `("x" ,drv ,out)) - outputs) - ,@(append (map add-label sources) - (map add-label targets))) - #:outputs outputs + (gexp->derivation name build + #:system system + #:guile-for-build guile - ;; Grafts are computationally cheap so no - ;; need to offload or substitute. - #:local-build? #t - #:substitutable? #f + ;; Grafts are computationally cheap so no + ;; need to offload or substitute. + #:local-build? #t + #:substitutable? #f - #:properties properties))))) + #:properties properties)) + +(define graft-derivation/shallow* + (store-lower graft-derivation/shallow)) (define (non-self-references store drv outputs) "Return the list of references of the OUTPUTS of DRV, excluding self @@ -291,10 +280,10 @@ (define (dependency-grafts items) ;; Use APPLICABLE, the subset of GRAFTS that is really ;; applicable to DRV, to avoid creating several identical ;; grafted variants of DRV. - (let* ((new (graft-derivation/shallow store drv applicable - #:outputs outputs - #:guile guile - #:system system)) + (let* ((new (graft-derivation/shallow* store drv applicable + #:outputs outputs + #:guile guile + #:system system)) (grafts (append (map (lambda (output) (graft (origin drv)