diff options
author | Ludovic Courtès <ludo@gnu.org> | 2014-10-29 00:09:38 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2014-10-29 00:31:23 +0100 |
commit | e6740741d188e01cb1a0b9c7db597a25128889d5 (patch) | |
tree | 5d9eae3c86e24a788204da4814dd06a40056507c /guix/tests.scm | |
parent | a96a82d79ead164e19a78f572254cf7f6f54d17c (diff) |
tests: Move some of the narinfo test tools to (guix tests).
* guix/tests.scm (derivation-narinfo, call-with-derivation-narinfo): New
procedures.
(with-derivation-narinfo): New macro.
* tests/derivations.scm ("derivation-prerequisites-to-build and
substitutes"): Use them.
Diffstat (limited to 'guix/tests.scm')
-rw-r--r-- | guix/tests.scm | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/guix/tests.scm b/guix/tests.scm index 4f7b0c8171..022679902a 100644 --- a/guix/tests.scm +++ b/guix/tests.scm @@ -23,9 +23,11 @@ #:use-module (gnu packages bootstrap) #:use-module (srfi srfi-34) #:use-module (rnrs bytevectors) + #:use-module (web uri) #:export (open-connection-for-tests random-text - random-bytevector)) + random-bytevector + with-derivation-narinfo)) ;;; Commentary: ;;; @@ -67,4 +69,59 @@ (loop (1+ i))) bv)))) + +;;; +;;; Narinfo files, as used by the substituter. +;;; + +(define* (derivation-narinfo drv #:optional (nar "example.nar")) + "Return the contents of the narinfo corresponding to DRV; NAR should be the +file name of the archive containing the substitute for DRV." + (format #f "StorePath: ~a +URL: ~a +Compression: none +NarSize: 1234 +References: +System: ~a +Deriver: ~a~%" + (derivation->output-path drv) ; StorePath + nar ; URL + (derivation-system drv) ; System + (basename + (derivation-file-name drv)))) ; Deriver + +(define (call-with-derivation-narinfo drv thunk) + "Call THUNK in a context where fake substituter data, as read by 'guix +substitute-binary', has been installed for DRV." + (let* ((output (derivation->output-path drv)) + (dir (uri-path + (string->uri (getenv "GUIX_BINARY_SUBSTITUTE_URL")))) + (info (string-append dir "/nix-cache-info")) + (narinfo (string-append dir "/" (store-path-hash-part output) + ".narinfo"))) + (dynamic-wind + (lambda () + (call-with-output-file info + (lambda (p) + (format p "StoreDir: ~a\nWantMassQuery: 0\n" + (%store-prefix)))) + (call-with-output-file narinfo + (lambda (p) + (display (derivation-narinfo drv) p)))) + thunk + (lambda () + (delete-file narinfo) + (delete-file info))))) + +(define-syntax-rule (with-derivation-narinfo drv body ...) + "Evaluate BODY in a context where DRV looks substitutable from the +substituter's viewpoint." + (call-with-derivation-narinfo drv + (lambda () + body ...))) + +;; Local Variables: +;; eval: (put 'call-with-derivation-narinfo 'scheme-indent-function 1) +;; End: + ;;; tests.scm ends here |