From: "Ludovic Courtès" <ludo@gnu.org>
To: 32174@debbugs.gnu.org
Subject: [bug#32174] [PATCH 5/6] gexp: 'imported-files/derivation' can copy files instead of symlinking.
Date: Mon, 16 Jul 2018 15:33:26 +0200 [thread overview]
Message-ID: <20180716133327.15901-5-ludo@gnu.org> (raw)
In-Reply-To: <20180716133327.15901-1-ludo@gnu.org>
* guix/gexp.scm (imported-files/derivation): Add #:symlink? and honor
it.
(imported-files): Pass #:symlink? to 'imported-files/derivation'.
* tests/gexp.scm ("imported-files with file-like objects"): Add 'file=?'
and use it instead of calling 'readlink'.
---
guix/gexp.scm | 8 ++++++--
tests/gexp.scm | 11 +++++++----
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/guix/gexp.scm b/guix/gexp.scm
index 19d90f5ee..ffc976d61 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -1078,6 +1078,7 @@ to a tree suitable for 'interned-file-tree'."
(define* (imported-files/derivation files
#:key (name "file-import")
+ (symlink? #f)
(system (%current-system))
(guile (%guile-for-build))
@@ -1091,7 +1092,8 @@ to a tree suitable for 'interned-file-tree'."
"Return a derivation that imports FILES into STORE. FILES must be a list
of (FINAL-PATH . FILE) pairs. Each FILE is mapped to FINAL-PATH in the
resulting store path. FILE can be either a file name, or a file-like object,
-as returned by 'local-file' for example."
+as returned by 'local-file' for example. If SYMLINK? is true, create symlinks
+to the source files instead of copying them."
(define file-pair
(match-lambda
((final-path . (? string? file-name))
@@ -1114,7 +1116,8 @@ as returned by 'local-file' for example."
(for-each (match-lambda
((final-path store-path)
(mkdir-p (dirname final-path))
- (symlink store-path final-path)))
+ ((ungexp (if symlink? 'symlink 'copy-file))
+ store-path final-path)))
'(ungexp files)))))
;; TODO: Pass FILES as an environment variable so that BUILD remains
@@ -1160,6 +1163,7 @@ as returned by 'local-file' for example."
(_ #f))
files))
(imported-files/derivation files #:name name
+ #:symlink? derivation?
#:system system #:guile guile
#:deprecation-warnings deprecation-warnings)
(interned-file-tree `(,name directory
diff --git a/tests/gexp.scm b/tests/gexp.scm
index 2a43b739c..5a547fee4 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -652,16 +652,19 @@
(files -> `(("a/b/c" . ,q-scm)
("p/q" . ,plain)))
(drv (imported-files files)))
+ (define (file=? file1 file2)
+ ;; Assume deduplication is in place.
+ (= (stat:ino (lstat file1))
+ (stat:ino (lstat file2))))
+
(mbegin %store-monad
(built-derivations (list drv))
(mlet %store-monad ((dir -> (derivation->output-path drv))
(plain* (text-file "foo" "bar!"))
(q-scm* (interned-file q-scm "c")))
(return
- (and (string=? (readlink (string-append dir "/a/b/c"))
- q-scm*)
- (string=? (readlink (string-append dir "/p/q"))
- plain*)))))))
+ (and (file=? (string-append dir "/a/b/c") q-scm*)
+ (file=? (string-append dir "/p/q") plain*)))))))
(test-equal "gexp-modules & ungexp"
'((bar) (foo))
--
2.18.0
next prev parent reply other threads:[~2018-07-16 13:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-16 13:30 [bug#32174] [PATCH 0/6] Add 'add-file-tree-to-store' and related facilities Ludovic Courtès
2018-07-16 13:33 ` [bug#32174] [PATCH 1/6] serialization: Add 'write-file-tree' Ludovic Courtès
2018-07-16 13:33 ` [bug#32174] [PATCH 2/6] store: Add 'add-file-tree-to-store' Ludovic Courtès
2018-07-16 13:33 ` [bug#32174] [PATCH 3/6] gexp: Remove unnecessary 'mlet' Ludovic Courtès
2018-07-16 13:33 ` [bug#32174] [PATCH 4/6] gexp: 'imported-files' no longer creates a derivation by default Ludovic Courtès
2018-07-16 13:33 ` Ludovic Courtès [this message]
2018-07-16 13:33 ` [bug#32174] [PATCH 6/6] self: Use the new 'imported-files' Ludovic Courtès
2018-07-19 9:57 ` bug#32174: [PATCH 0/6] Add 'add-file-tree-to-store' and related facilities Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180716133327.15901-5-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=32174@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.