From cc54e1c5021119bfaba07849e83ea31f7099970e Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Sat, 4 Sep 2021 15:35:51 +0200 Subject: [PATCH 3/6] gexp: Allow computing the hash of the local file in advance. The new field is currently unused. The following patches will populate and use the field to reduce the time-to-derivation when the file is already interned in the store. * guix/gexp.scm (): Add sha256 field. (%local-file): Add sha256 argument for populating the field. (local-file-compiler): Adjust 'match' expression. --- guix/gexp.scm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/guix/gexp.scm b/guix/gexp.scm index f3d278b3e6..a633984688 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -419,13 +419,16 @@ Here TARGET is bound to the cross-compilation triplet or #f." ;; A local file name. FILE is the file name the user entered, which can be a ;; relative file name, and ABSOLUTE is a promise that computes its canonical ;; absolute file name. We keep it in a promise to compute it lazily and avoid -;; repeated 'stat' calls. +;; repeated 'stat' calls. Allow computing the hash of the file in advance, +;; to avoid having to send the file to the daemon when it is already interned +;; in the store. (define-record-type - (%%local-file file absolute name recursive? select?) + (%%local-file file absolute name sha256 recursive? select?) local-file? (file local-file-file) ;string (absolute %local-file-absolute-file-name) ;promise string (name local-file-name) ;string + (sha256 local-file-sha256) ;sha256 bytevector | #f (recursive? local-file-recursive?) ;Boolean (select? local-file-select?)) ;string stat -> Boolean @@ -434,6 +437,7 @@ Here TARGET is bound to the cross-compilation triplet or #f." (define* (%local-file file promise #:optional (name (basename file)) #:key (literal? #t) location + sha256 recursive? (select? true)) ;; This intermediate procedure is part of our ABI, but the underlying ;; %%LOCAL-FILE is not. @@ -441,7 +445,7 @@ Here TARGET is bound to the cross-compilation triplet or #f." (warning (and=> location source-properties->location) (G_ "resolving '~a' relative to current directory~%") file)) - (%%local-file file promise name recursive? select?)) + (%%local-file file promise name sha256 recursive? select?)) (define (absolute-file-name file directory) "Return the canonical absolute file name for FILE, which lives in the @@ -517,7 +521,7 @@ appears." (define-gexp-compiler (local-file-compiler (file ) system target) ;; "Compile" FILE by adding it to the store. (match file - (($ file (= force absolute) name recursive? select?) + (($ file (= force absolute) name sha256 recursive? select?) ;; Canonicalize FILE so that if it's a symlink, it is resolved. Failing ;; to do that, when RECURSIVE? is #t, we could end up creating a dangling ;; symlink in the store, and when RECURSIVE? is #f 'add-to-store' would -- 2.33.0