diff mbox series

[bug#55316] scripts: package: Transform before creating manifest entries.

Message ID 20220508141606.14085-1-dev@jpoiret.xyz
State New
Headers show
Series [bug#55316] scripts: package: Transform before creating manifest entries. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Josselin Poiret May 8, 2022, 2:16 p.m. UTC
* guix/scripts/package.scm (options->installable): Add TRANSFORM
argument, to be able to directly transform the new packages before
creating their manifest entries.
(process-actions): Remove transform-entry, and step3.
---
Hello everyone,

Someone on IRC [1] reported that they couldn't run

guix install emacs-avy emacs-embark --with-branch=emacs-avy=master --with-branch=emacs-embark=master

without guix complaining about conflicting entries of emacs-avy and
the propagated one from emacs-embark, even in a profile without either
of them.  The issue was that package transformations were applied to
the contents of the generated manifest entries, but weren't applied to
any of their dependencies.  To solve this, I figured it would be simpler
to just apply the transformation from the start, only creating the manifest
entries after they have been applied.  Also, the
default `package->manifest-entry` preserves transformations properties by default,
so this doesn't lose any info either.

With this patch applied, the above command works as expected for me.

Best,

Josselin Poiret

[1] https://logs.guix.gnu.org/guix/2022-05-08.log#134728

 guix/scripts/package.scm | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

Comments

Ludovic Courtès May 9, 2022, 9:51 a.m. UTC | #1
Hello!

Josselin Poiret <dev@jpoiret.xyz> skribis:

> * guix/scripts/package.scm (options->installable): Add TRANSFORM
> argument, to be able to directly transform the new packages before
> creating their manifest entries.
> (process-actions): Remove transform-entry, and step3.
> ---
> Hello everyone,
>
> Someone on IRC [1] reported that they couldn't run
>
> guix install emacs-avy emacs-embark --with-branch=emacs-avy=master --with-branch=emacs-embark=master
>
> without guix complaining about conflicting entries of emacs-avy and
> the propagated one from emacs-embark, even in a profile without either
> of them.  The issue was that package transformations were applied to
> the contents of the generated manifest entries, but weren't applied to
> any of their dependencies.

Interesting.

> To solve this, I figured it would be simpler to just apply the
> transformation from the start, only creating the manifest entries
> after they have been applied.  Also, the default
> `package->manifest-entry` preserves transformations properties by
> default, so this doesn't lose any info either.

As discussed on IRC, could you make sure transformation properties are
preserved in the manifest?

I only see one test that explicitly checks that,
"transaction-upgrade-entry, transformation options preserved" in
tests/packages.scm, and then there’s "options->transformation +
package->manifest-entry" in tests/transformations.scm.

Also, could you add a test that reproduces the problem being fixed?

Thanks!

Ludo’.
diff mbox series

Patch

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index d007005607..4673cf18b2 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -10,6 +10,7 @@ 
 ;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
 ;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
+;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -694,10 +695,10 @@  (define (package->manifest-entry* package output)
   (manifest-entry-with-provenance
    (package->manifest-entry package output)))
 
-(define (options->installable opts manifest transaction)
-  "Given MANIFEST, the current manifest, and OPTS, the result of 'args-fold',
-return an variant of TRANSACTION that accounts for the specified installations
-and upgrades."
+(define (options->installable opts manifest transform transaction)
+  "Given MANIFEST, the current manifest, OPTS, and TRANSFORM, the result of
+'args-fold', return an variant of TRANSACTION that accounts for the specified
+installations, upgrades and transformations."
   (define upgrade?
     (options->upgrade-predicate opts))
 
@@ -714,13 +715,14 @@  (define to-install
                   (('install . (? package? p))
                    ;; When given a package via `-e', install the first of its
                    ;; outputs (XXX).
-                   (package->manifest-entry* p "out"))
+                   (package->manifest-entry* (transform p) "out"))
                   (('install . (? string? spec))
                    (if (store-path? spec)
                        (store-item->manifest-entry spec)
                        (let-values (((package output)
                                      (specification->package+output spec)))
-                         (package->manifest-entry* package output))))
+                         (package->manifest-entry* (transform package)
+                                                   output))))
                   (('install . obj)
                    (leave (G_ "cannot install non-package object: ~s~%")
                           obj))
@@ -979,16 +981,6 @@  (define allow-collisions? (assoc-ref opts 'allow-collisions?))
   (define profile  (or (assoc-ref opts 'profile) %current-profile))
   (define transform (options->transformation opts))
 
-  (define (transform-entry entry)
-    (let ((item (transform (manifest-entry-item entry))))
-      (manifest-entry-with-transformations
-       (manifest-entry
-         (inherit entry)
-         (item item)
-         (version (if (package? item)
-                      (package-version item)
-                      (manifest-entry-version entry)))))))
-
   (when (equal? profile %current-profile)
     ;; Normally the daemon created %CURRENT-PROFILE when we connected, unless
     ;; it's a version that lacks the fix for <https://bugs.gnu.org/37744>
@@ -1021,16 +1013,12 @@  (define (transform-entry entry)
                              (map load-manifest files))))))
            (step1    (options->removable opts manifest
                                          (manifest-transaction)))
-           (step2    (options->installable opts manifest step1))
-           (step3    (manifest-transaction
-                      (inherit step2)
-                      (install (map transform-entry
-                                    (manifest-transaction-install step2)))))
-           (new      (manifest-perform-transaction manifest step3))
+           (step2    (options->installable opts manifest transform step1))
+           (new      (manifest-perform-transaction manifest step2))
            (trans    (if (null? files)
-                         step3
+                         step2
                          (fold manifest-transaction-install-entry
-                               step3
+                               step2
                                (manifest-entries manifest)))))
 
       (warn-about-old-distro)