From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id ePOmH0WCNGOTEwEAbAwnHQ (envelope-from ) for ; Wed, 28 Sep 2022 19:20:05 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 0LyKH0WCNGOhHQEAauVa8A (envelope-from ) for ; Wed, 28 Sep 2022 19:20:05 +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 E82ECBB32 for ; Wed, 28 Sep 2022 19:20:04 +0200 (CEST) Received: from localhost ([::1]:47770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odaj4-0004HR-Tb for larch@yhetil.org; Wed, 28 Sep 2022 13:20:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odaD9-00038x-4p for guix-patches@gnu.org; Wed, 28 Sep 2022 12:47:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35357) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odaD8-0001Dd-E4 for guix-patches@gnu.org; Wed, 28 Sep 2022 12:47:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1odaD7-00059e-Sj for guix-patches@gnu.org; Wed, 28 Sep 2022 12:47:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#43193] bug#58032: [PATCH] transformations: '--with-source' now operates in depth. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 28 Sep 2022 16:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43193 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 58032@debbugs.gnu.org, Ludovic =?UTF-8?Q?Court=C3=A8s?= , 43193@debbugs.gnu.org, philippe.swartvagher@inria.fr Received: via spool by 43193-submit@debbugs.gnu.org id=B43193.166438361019790 (code B ref 43193); Wed, 28 Sep 2022 16:47:01 +0000 Received: (at 43193) by debbugs.gnu.org; 28 Sep 2022 16:46:50 +0000 Received: from localhost ([127.0.0.1]:34433 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odaCv-000597-UC for submit@debbugs.gnu.org; Wed, 28 Sep 2022 12:46:50 -0400 Received: from mail-qk1-f169.google.com ([209.85.222.169]:46965) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odaCt-00058p-5y; Wed, 28 Sep 2022 12:46:47 -0400 Received: by mail-qk1-f169.google.com with SMTP id d17so8196606qko.13; Wed, 28 Sep 2022 09:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:from:to:cc:subject :date; bh=VDX+dRJLNfdkz2VJLwYss0AD/4bj/g76rUPmoyLIuJg=; b=oQ9wPmRAZDdRl0KyIfwvdxTMK2JoQkvmQVw44pUIsqzvMPAJQScwDBdxlXARNZI9DT HSWrqXaCJkki6zEFpLgLbsTqf3iKPnYEMHyu9LilWMzo+/B+HT27VFXIqBq1eWNvITeE koV2KHvbc8VnbCjNA3Lkf3Uej+GPJydcPv3TYBFlB0rtx75TlfbeaJ7QYHYc5jessyM5 5rbzxAqOPOavbEx1QhJtMeU/sii9HhZjCypsJNq+upxF5/B3xOw+PBbrfffc9b09ovNo hOmE0SBAWJR1g/Nf9HmauozQWWlCo/FmrCmCQu8pGb2lqzFrowyX/QqDsYxDIB7iHxPv 4mgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date; bh=VDX+dRJLNfdkz2VJLwYss0AD/4bj/g76rUPmoyLIuJg=; b=teuNq0c0x7Wq+JSVUHvnuMKs/I9wTN9nyXjiwyCI+4ixlMXjbohmrxvMMLllgUXcYo D4u4NLcaSl7lWOkynG0ihP907u/JJ1B1Kw78HOSBppnAOjGFiQRzwQuZYT9odBuK0nXi Tv/5uisZsthjRMB8t4iBD40lr6zsHoLA1kcO2PxNNbcZST3kEISI7bmGDASj2XfEcqpG pyaNXLx00D41JRxUxj9Og9NQdWSRlliPgpcVZi8F5kYpqSPDmBOh/bSupeygkfdeTLlO kVJgpTEqvtFVVCOW4iQmMhd3IZhuy52YIz381DSbW3cG3EGTwz9LtZ2OkxJfvcC1zX8T thlw== X-Gm-Message-State: ACrzQf0KuUcKCPMBVNHCPBk2sJih3imltgyk1zveXZBrNaOtzQcY/6AC GBRcMp2zg1BqhawntdClD+lKkkCvlp/vTw== X-Google-Smtp-Source: AMsMyM7mZ/Tia31jQAOvjSo3qclAivL/ITqCm1con5WTACVVgbQY7yknklQ/g9hbGV0DeaJ/NK0qSg== X-Received: by 2002:a37:b782:0:b0:6ce:1c45:c201 with SMTP id h124-20020a37b782000000b006ce1c45c201mr22770029qkf.454.1664383601193; Wed, 28 Sep 2022 09:46:41 -0700 (PDT) Received: from hurd (dsl-148-95.b2b2c.ca. [66.158.148.95]) by smtp.gmail.com with ESMTPSA id bb20-20020a05622a1b1400b003435bb7fe9csm3131273qtb.78.2022.09.28.09.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 09:46:40 -0700 (PDT) From: Maxim Cournoyer References: <20220923204208.31957-1-ludo@gnu.org> Date: Wed, 28 Sep 2022 12:46:39 -0400 In-Reply-To: <20220923204208.31957-1-ludo@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Fri, 23 Sep 2022 22:42:08 +0200") Message-ID: <87fsgbwiog.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664385605; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: 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=VDX+dRJLNfdkz2VJLwYss0AD/4bj/g76rUPmoyLIuJg=; b=Jfes/yweTKzSRa4JDKUi03CmK2fHp9gMDFxw+nfsQBhtZ2CE+FQ80l3qGP7QFs20EaVq5f 8vJHCWdKcY1tJFArgQOsAeNdxCcbVFPf5E9PKxYL+JHkSsfKCCHYrzxXc5wcbO3zNxDGOi KDkMPUsnKsHMBuCT2XxCxqApukOsBTDn9eDB5QKfDbyZa2Ba97L2/RD5mvbEHIGG2veDJ7 sMZ+0xt/c/060tUf3iMnuNy6/rsfW2SQ1p59ya7Ujh2BvwAag5fPHlMZ2jqLWN1k3ZcMyz FAZeZbkfvnrhuIbDUa+R/HeXcQT/df4Io+a7rhaAXN8XzLMo7q9G+nYZIPaZpw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664385605; a=rsa-sha256; cv=none; b=Q9JIbCz/cxC8FaHAnTfPh1E1xhTdPAWxylU+cvLc/mBnsf7tsfVA/3Vk/zlAz4qL+zIGGy pdOqNYLEDoPnoKAcZoELvpiVzGItT2+Zca9XJzLJxGKJLWm+W6vmxA0LvpMCsE6fjWvT+u G7zUCBNKYBx2mY7DLpg+KRIv1Jc4QzidmyIYncid3TjuZ9eY0v+lvfpAVvnoN5/ZEChaRh SrZ0/fp4Md9KCKVhFQCrsH2sGjLc7IC73ImZxFJMy9V2v9mTaxAsWL3LUFyX/qFIF3u2M/ JrbRmeDatyZjO+6UMnc1IT1HVtCwcyrvcnnuY9IC2CPgcC1dMNLy/KT/+KN5Xg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=oQ9wPmRA; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Spam-Score: 6.15 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=oQ9wPmRA; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Queue-Id: E82ECBB32 X-Spam-Score: 6.15 X-Migadu-Scanner: scn1.migadu.com X-TUID: TZJCp+Wl5Wod Hi, Ludovic Court=C3=A8s writes: > From: Ludovic Court=C3=A8s > > The '--with-source' option is the first one that was implemented, and > it's the only one that would operate only on leaf packages rather than > traversing the dependency graph. This change makes it consistent with > the rest of the transformation options. Good idea! I needed to workaround the lack of recursion at least once. [...] > diff --git a/guix/transformations.scm b/guix/transformations.scm > index 411c4014cb..be2d31b8c7 100644 > --- a/guix/transformations.scm > +++ b/guix/transformations.scm > @@ -129,42 +129,46 @@ (define* (package-with-source p uri #:optional vers= ion) > ;;; Transformations. > ;;; >=20=20 > -(define (transform-package-source sources) > +(define (evaluate-source-replacement-specs specs) > + "Parse SPECS, a list of strings like \"guile=3D/tmp/guile-4.2.tar.gz\"= or just > +\"/tmp/guile-4.2.tar.gz\" and return a list of package spec/procedure pa= irs as > +expected by 'package-input-rewriting/spec'. Raise an error if an elemen= t of > +SPECS uses invalid syntax." > + (define not-equal > + (char-set-complement (char-set #\=3D))) > + > + (map (lambda (spec) > + (match (string-tokenize spec not-equal) > + ((uri) > + (let* ((base (tarball-base-name (basename uri))) Unrelated, but 'tarball-base-name' is a bit of a misnomer since the file could be a single, non-tarball archive (or plain file). > + (name (hyphen-package-name->name+version base))) > + (cons name > + (lambda (old) > + (package-with-source old uri))))) > + ((spec uri) > + (let-values (((name version) > + (package-name->name+version spec))) You usually recommend (srfi srfi-71) when using multiple values; why not use it here? I don't have a preference myself (I find srfi-71 surprising for the non-initiated (I was), although I like its simple interface! :-)). > + ;; Note: Here VERSION is used as the version string of the= new > + ;; package rather than as part of the spec of the package = being > + ;; targeted. > + (cons name > + (lambda (old) > + (package-with-source old uri version))))) > + (_ > + (raise (formatted-message > + (G_ "invalid source replacement specification: ~s") > + spec))))) > + specs)) > + > +(define (transform-package-source replacement-specs) > "Return a transformation procedure that replaces package sources with = the > -matching URIs given in SOURCES." > - (define new-sources > - (map (lambda (uri) > - (match (string-index uri #\=3D) > - (#f > - ;; Determine the package name and version from URI. > - (call-with-values > - (lambda () > - (hyphen-package-name->name+version > - (tarball-base-name (basename uri)))) > - (lambda (name version) > - (list name version uri)))) > - (index > - ;; What's before INDEX is a "PKG@VER" or "PKG" spec. > - (call-with-values > - (lambda () > - (package-name->name+version (string-take uri index))) > - (lambda (name version) > - (list name version > - (string-drop uri (+ 1 index)))))))) > - sources)) > - > - (lambda (obj) > - (let loop ((sources new-sources) > - (result '())) > - (match obj > - ((? package? p) > - (match (assoc-ref sources (package-name p)) > - ((version source) > - (package-with-source p source version)) > - (#f > - p))) > - (_ > - obj))))) > +matching URIs given in REPLACEMENT-SPECS." > + (let* ((replacements (evaluate-source-replacement-specs replacement-sp= ecs)) > + (rewrite (package-input-rewriting/spec replacements))) > + (lambda (obj) > + (if (package? obj) > + (rewrite obj) > + obj)))) >=20=20 > (define (evaluate-replacement-specs specs proc) > "Parse SPECS, a list of strings like \"guile=3Dguile@2.1\" and return = a list > diff --git a/tests/transformations.scm b/tests/transformations.scm > index dbfe523518..47b1fc650d 100644 > --- a/tests/transformations.scm > +++ b/tests/transformations.scm > @@ -103,16 +103,11 @@ (define-module (test-transformations) > "sha256" f)))))))))) >=20=20 > (test-assert "options->transformation, with-source, no matches" > - ;; When a transformation in not applicable, a warning must be raised. > (let* ((p (dummy-package "foobar")) > (s (search-path %load-path "guix.scm")) > (t (options->transformation `((with-source . ,s))))) > - (let* ((port (open-output-string)) > - (new (parameterize ((guix-warning-port port)) > - (t p)))) > - (and (eq? new p) > - (string-contains (get-output-string port) > - "had no effect"))))) > + (eq? (package-source (t p)) > + (package-source p)))) I'd personally find it a better interface if it failed noisily when --with-source doesn't have any effect. The warning was of little use because it got lost in the other outputs; now it would be totally silent, right? > (test-assert "options->transformation, with-source, PKG=3DURI" > (let* ((p (dummy-package "foo")) > @@ -147,6 +142,29 @@ (define-module (test-transformations) > (add-to-store store (basename s) #t > "sha256" s))))))) >=20=20 > +(test-assert "options->transformation, with-source, in depth" > + (let* ((p0 (dummy-package "foo" (version "0.0"))) > + (s (search-path %load-path "guix.scm")) > + (f (string-append "foo@42.0=3D" s)) > + (t (options->transformation `((with-source . ,f)))) > + (p1 (dummy-package "bar" (inputs (list p0)))) > + (p2 (dummy-package "baz" (inputs (list p1))))) > + (with-store store > + (let ((new (t p2))) > + (and (not (eq? new p2)) > + (match (package-inputs new) > + ((("bar" p1*)) > + (match (package-inputs p1*) > + ((("foo" p0*)) > + (and (not (eq? p0* p0)) > + (string=3D? (package-name p0*) (package-name p0)) > + (string=3D? (package-version p0*) "42.0") > + (string=3D? (add-to-store store (basename s) #t > + "sha256" s) > + (run-with-store store > + (lower-object > + (package-source p0*)))))))))))))) > + The recursive? option should probably be #f in the add-store above, since the "dummy" source is a single file. It may be better to create the dummy file ourselves instead of relying on the existence of a 'guix.scm' one (it'd help clarify the test too, that bit was a bit mysterious at first). Other than that, LGTM! Thanks, Maxim