aboutsummaryrefslogtreecommitdiff
path: root/guix/derivations.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludovic.courtes@inria.fr>2017-06-12 17:11:22 +0200
committerLudovic Courtès <ludo@gnu.org>2017-06-12 17:53:51 +0200
commit015f17e8b9eff97f656852180ac51c75438d7f9d (patch)
treed2fe6f9a2917aa3f2bf57e4220e23a3e7d63d8d2 /guix/derivations.scm
parentb46712159c15f72fc28b71d17d5a7c74fcb64ed0 (diff)
downloadguix-015f17e8b9eff97f656852180ac51c75438d7f9d.tar
guix-015f17e8b9eff97f656852180ac51c75438d7f9d.tar.gz
derivations: Introduce 'read-derivation-from-file'.
This avoids the open/fstat/close syscalls upon a cache hit that we had with the previous idiom: (call-with-input-file file read-derivation) where caching happened in 'read-derivation' itself. * guix/derivations.scm (%read-derivation): Rename to... (read-derivation): ... this. (read-derivation-from-file): New procedure. (derivation-prerequisites, substitution-oracle) (derivation-prerequisites-to-build): (derivation-path->output-path, derivation-path->output-paths): (derivation-path->base16-hash, map-derivation): Use 'read-derivation-from-file' instead of (call-with-input-file … read-derivation). * guix/grafts.scm (item->deriver): Likewise. * guix/scripts/build.scm (log-url, options->things-to-build): Likewise. * guix/scripts/graph.scm (file->derivation): Remove. (derivation-dependencies, %derivation-node-type): Use 'read-derivation-from-file' instead. * guix/scripts/offload.scm (guix-offload): Likewise. * guix/scripts/perform-download.scm (guix-perform-download): Likewise. * guix/scripts/publish.scm (load-derivation): Remove. (narinfo-string): Use 'read-derivation-from-file'.
Diffstat (limited to 'guix/derivations.scm')
-rw-r--r--guix/derivations.scm47
1 files changed, 22 insertions, 25 deletions
diff --git a/guix/derivations.scm b/guix/derivations.scm
index b9ad9c9e8c..07803ca94f 100644
--- a/guix/derivations.scm
+++ b/guix/derivations.scm
@@ -82,6 +82,7 @@
derivation-hash
read-derivation
+ read-derivation-from-file
write-derivation
derivation->output-path
derivation->output-paths
@@ -241,8 +242,7 @@ result is the set of prerequisites of DRV not already in valid."
(append inputs result)
(fold set-insert input-set inputs)
(map (lambda (i)
- (call-with-input-file (derivation-input-path i)
- read-derivation))
+ (read-derivation-from-file (derivation-input-path i)))
inputs)))))
(define (offloadable-derivation? drv)
@@ -295,9 +295,8 @@ substituter many times."
;; info is not already in cache.
;; Also, skip derivations marked as non-substitutable.
(append-map (lambda (input)
- (let ((drv (call-with-input-file
- (derivation-input-path input)
- read-derivation)))
+ (let ((drv (read-derivation-from-file
+ (derivation-input-path input))))
(if (substitutable-derivation? drv)
(derivation-input-output-paths input)
'())))
@@ -400,13 +399,15 @@ one-argument procedure similar to that returned by 'substitution-oracle'."
(derivation-inputs drv))
substitute)
(map (lambda (i)
- (call-with-input-file (derivation-input-path i)
- read-derivation))
+ (read-derivation-from-file
+ (derivation-input-path i)))
inputs)
(map derivation-input-sub-derivations inputs)))))))
-(define (%read-derivation drv-port)
- ;; Actually read derivation from DRV-PORT.
+(define (read-derivation drv-port)
+ "Read the derivation from DRV-PORT and return the corresponding <derivation>
+object. Most of the time you'll want to use 'read-derivation-from-file',
+which caches things as appropriate and is thus more efficient."
(define comma (string->symbol ","))
@@ -482,17 +483,16 @@ one-argument procedure similar to that returned by 'substitution-oracle'."
;; XXX: This is redundant with 'atts-cache' in the store.
(make-weak-value-hash-table 200))
-(define (read-derivation drv-port)
- "Read the derivation from DRV-PORT and return the corresponding
+(define (read-derivation-from-file file)
+ "Read the derivation in FILE, a '.drv' file, and return the corresponding
<derivation> object."
- ;; Memoize that operation because `%read-derivation' is quite expensive,
+ ;; Memoize that operation because 'read-derivation' is quite expensive,
;; and because the same argument is read more than 15 times on average
;; during something like (package-derivation s gdb).
- (let ((file (port-filename drv-port)))
- (or (and file (hash-ref %derivation-cache file))
- (let ((drv (%read-derivation drv-port)))
- (hash-set! %derivation-cache file drv)
- drv))))
+ (or (and file (hash-ref %derivation-cache file))
+ (let ((drv (call-with-input-file file read-derivation)))
+ (hash-set! %derivation-cache file drv)
+ drv)))
(define-inlinable (write-sequence lst write-item port)
;; Write each element of LST with WRITE-ITEM to PORT, separating them with a
@@ -608,8 +608,7 @@ DRV."
(define derivation-path->output-path
;; This procedure is called frequently, so memoize it.
(let ((memoized (mlambda (path output)
- (derivation->output-path (call-with-input-file path
- read-derivation)
+ (derivation->output-path (read-derivation-from-file path)
output))))
(lambda* (path #:optional (output "out"))
"Read the derivation from PATH (`/gnu/store/xxx.drv'), and return the store
@@ -619,7 +618,7 @@ path of its output OUTPUT."
(define (derivation-path->output-paths path)
"Read the derivation from PATH (`/gnu/store/xxx.drv'), and return the
list of name/path pairs of its outputs."
- (derivation->output-paths (call-with-input-file path read-derivation)))
+ (derivation->output-paths (read-derivation-from-file path)))
;;;
@@ -630,10 +629,8 @@ list of name/path pairs of its outputs."
(mlambda (file)
"Return a string containing the base16 representation of the hash of the
derivation at FILE."
- (call-with-input-file file
- (compose bytevector->base16-string
- derivation-hash
- read-derivation))))
+ (bytevector->base16-string
+ (derivation-hash (read-derivation-from-file file)))))
(define derivation-hash ; `hashDerivationModulo' in derivations.cc
(mlambda (drv)
@@ -896,7 +893,7 @@ recursively."
((_ . replacement)
(list replacement))
(#f
- (let* ((drv (loop (call-with-input-file path read-derivation))))
+ (let* ((drv (loop (read-derivation-from-file path))))
(cons drv sub-drvs))))))))
(let loop ((drv drv))