diff --git a/guix/derivations.scm b/guix/derivations.scm index b9ad9c9e8c4812c25428b8b3d192b62e680c9d5a..07803ca94f78b453290b1a2ee11e95e400dfbad5 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm @@ -82,6 +82,7 @@ (define-module (guix derivations) derivation-hash read-derivation + read-derivation-from-file write-derivation derivation->output-path derivation->output-paths @@ -241,8 +242,7 @@ (define* (derivation-prerequisites drv #:optional (cut? (const #f))) (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 @@ (define (dependencies drv) ;; 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 @@ (define (derivation-substitutable-info drv sub-drvs) (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 @@ (define %derivation-cache ;; 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 @@ (define (derivation->output-paths 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 @@ (define derivation-path->output-path (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 @@ (define derivation-path->base16-hash (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 @@ (define rewritten-input ((_ . 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)) diff --git a/guix/grafts.scm b/guix/grafts.scm index 11885db226d5082059b4556d24eb6448e971c129..d6b0e93e8db85e118e2944ab1c13ed1fc91c959b 100644 --- a/guix/grafts.scm +++ b/guix/grafts.scm @@ -156,7 +156,7 @@ (define (item->deriver store item) (() ;ITEM is a plain file (values #f #f)) ((drv-file _ ...) - (let ((drv (call-with-input-file drv-file read-derivation))) + (let ((drv (read-derivation-from-file drv-file))) (values drv (any (match-lambda ((name . path) diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm index 558e8e771906da953c345dd9b9c4fed85a707ed8..0571b874f128be5a0841708bcf38249e1c6f5d31 100644 --- a/guix/scripts/build.scm +++ b/guix/scripts/build.scm @@ -87,7 +87,7 @@ (define (find-url file) ;; Usually we'll have more luck with the output file name since ;; the deriver that was used by the server could be different, so ;; try one of the output file names. - (let ((drv (call-with-input-file file read-derivation))) + (let ((drv (read-derivation-from-file file))) (or (find-url (derivation->output-path drv)) (find-url file)))) (lambda args @@ -599,7 +599,7 @@ (define (ensure-list x) (append-map (match-lambda (('argument . (? string? spec)) (cond ((derivation-path? spec) - (list (call-with-input-file spec read-derivation))) + (list (read-derivation-from-file spec))) ((store-path? spec) ;; Nothing to do; maybe for --log-file. '()) diff --git a/guix/scripts/graph.scm b/guix/scripts/graph.scm index 0af1fa3ad339754b6786dbaa3165df2270009733..d5be442884b0a5d1073e562a70af2a06c66f24bd 100644 --- a/guix/scripts/graph.scm +++ b/guix/scripts/graph.scm @@ -221,15 +221,11 @@ (define %bag-emerged-node-type ;;; Derivation DAG. ;;; -(define (file->derivation file) - "Read the derivation from FILE and return it." - (call-with-input-file file read-derivation)) - (define (derivation-dependencies obj) "Return the <derivation> objects and store items corresponding to the dependencies of OBJ, a <derivation> or store item." (if (derivation? obj) - (append (map (compose file->derivation derivation-input-path) + (append (map (compose read-derivation-from-file derivation-input-path) (derivation-inputs obj)) (derivation-sources obj)) '())) @@ -263,7 +259,7 @@ (define %derivation-node-type ((? derivation-path? item) (mbegin %store-monad ((store-lift add-temp-root) item) - (return (list (file->derivation item))))) + (return (list (read-derivation-from-file item))))) (x (raise (condition (&message (message "unsupported argument for \ diff --git a/guix/scripts/offload.scm b/guix/scripts/offload.scm index 77b340cff6be266f861bb0a1cace38f80a832d5e..566d117b02e906d193e84de5566918718ca991cc 100644 --- a/guix/scripts/offload.scm +++ b/guix/scripts/offload.scm @@ -652,9 +652,8 @@ (define not-coma (with-error-handling (process-request (equal? (match:substring match 1) "1") (match:substring match 2) ; system - (call-with-input-file - (match:substring match 3) - read-derivation) + (read-derivation-from-file + (match:substring match 3)) (string-tokenize (match:substring match 4) not-coma) #:print-build-trace? print-build-trace? diff --git a/guix/scripts/perform-download.scm b/guix/scripts/perform-download.scm index aee506af461f38e4982727d8a82b3d40939b651c..18e2fc92f271fc57655842fa94914fac722dcf8b 100644 --- a/guix/scripts/perform-download.scm +++ b/guix/scripts/perform-download.scm @@ -106,11 +106,11 @@ (define (guix-perform-download . args) (match args (((? derivation-path? drv) (? store-path? output)) (assert-low-privileges) - (perform-download (call-with-input-file drv read-derivation) + (perform-download (read-derivation-from-file drv) output)) (((? derivation-path? drv)) ;backward compatibility (assert-low-privileges) - (perform-download (call-with-input-file drv read-derivation))) + (perform-download (read-derivation-from-file drv))) (("--version") (show-version-and-exit)) (x diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index c49c0c3e20562c42324dedbcbc8c98a0ac9944e3..a7e3e6d629bbc2be55ce6c58898ec975555fc585 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -225,10 +225,6 @@ (define %nix-cache-info ("WantMassQuery" . 0) ("Priority" . 100))) -(define (load-derivation file) - "Read the derivation from FILE." - (call-with-input-file file read-derivation)) - (define (signed-string s) "Sign the hash of the string S with the daemon's key." (let* ((public-key (%public-key)) @@ -286,7 +282,7 @@ (define* (narinfo-string store store-path key base-info (catch 'system-error (lambda () - (let ((drv (load-derivation deriver))) + (let ((drv (read-derivation-from-file deriver))) (format #f "~aSystem: ~a~%Deriver: ~a~%" base-info (derivation-system drv) (basename deriver))))