[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#50597: different fixed-output when using ’--with-source’ transformat
From: |
Ludovic Courtès |
Subject: |
bug#50597: different fixed-output when using ’--with-source’ transformation |
Date: |
Wed, 22 Sep 2021 12:25:12 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Hi,
zimoun <zimon.toutoune@gmail.com> skribis:
> On Sat, 18 Sep 2021 at 18:06, Ludovic Courtès <ludo@gnu.org> wrote:
>> zimoun <zimon.toutoune@gmail.com> skribis:
>>
>>> Why the store item of source tarball is it different when applying the
>>> transformation?
>>>
>>> Maxime provided a clue [1].
>>
>> Maxime is right: ‘--with-source’ passes #:recursive? #t unconditionally,
>> whereas it’s usually #f for a ‘url-fetch’ kind of URI.
>
> Thanks for confirming. Why is it different?
Because we want ‘--with-source’ to also work with directories (see
comment in ‘package-with-source’).
>> What we could do is make it #t if and only if the URL denotes a local
>> file and that file is a directory. I think that would achieve what you
>> want without any observable regression in practice.
>
> What I expect is that 2 (fixed-output) files with the same hash
> (0ssi1w…) lives at the same store location…
>
> $ guix hash /gnu/store/chariqd6k0sli3s7vcl4q3al0crirz5v-hello-2.10.tar.gz
> 0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
>
> $ guix hash /gnu/store/hbdalsf5lpf01x4dcknwx6xbn6n5km6k-hello-2.10.tar.gz
> 0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
The difference here is that one is marked as “recursive” and the other
is not.
The patch below does one I suggested earlier: passing #:recursive? #t if
and only if we know the source is a directory.
However it’s not enough to get the same derivation: we’d also need
<downloaded-file> to return a fixed-output derivation rather than a
plain store file name. (See also <https://issues.guix.gnu.org/49696>.)
To be continued…
Ludo’.
diff --git a/guix/transformations.scm b/guix/transformations.scm
index 5ae1977cb2..e0f5579c28 100644
--- a/guix/transformations.scm
+++ b/guix/transformations.scm
@@ -46,6 +46,7 @@
#:use-module (srfi srfi-37)
#:use-module (ice-9 match)
#:use-module (ice-9 vlist)
+ #:autoload (web uri) (string->uri uri-scheme uri-path)
#:export (options->transformation
manifest-entry-with-transformations
@@ -106,15 +107,25 @@ extensions."
(define* (package-with-source p uri #:optional version)
"Return a package based on P but with its source taken from URI. Extract
the new package's version number from URI."
- (let ((base (tarball-base-name (basename uri))))
+ (let ((base (tarball-base-name (basename uri)))
+ (file (match (string->uri uri)
+ (#f uri)
+ (uri (and (eq? 'file (uri-scheme uri))
+ (uri-path uri))))))
(let-values (((_ version*)
(hyphen-package-name->name+version base)))
(package (inherit p)
(version (or version version*
(package-version p)))
- ;; Use #:recursive? #t to allow for directories.
- (source (downloaded-file uri #t))))))
+ ;; Default to #:recursive? #f to match what 'url-fetch' does,
+ ;; but use #t when URI denotes a directory.
+ (source (let ((recursive?
+ (and file
+ (match (stat file #f)
+ (#f #t)
+ (st (eq? 'directory (stat:type st)))))))
+ (downloaded-file uri recursive?)))))))
;;;