summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-10-03 11:02:11 +0200
committerLudovic Courtès <ludo@gnu.org>2014-10-03 18:03:09 +0200
commit882383a9aa5fbeef6f29d359a786a6db7c9e03db (patch)
tree323b5cffbe95c01b070064f1c89f3f968ba95ba2
parentb497a85be8490f0f91279119904fd76ae13cbea5 (diff)
download: Allow raw file names or file:// URLs.
* guix/download.scm (url-fetch): When URL is a string, if it's not a URI or if it's a URI with 'file' or #f scheme, use 'add-to-store'. * tests/builders.scm ("url-fetch, file", "url-fetch, file URI"): New tests.
-rw-r--r--guix/download.scm31
-rw-r--r--tests/builders.scm17
2 files changed, 35 insertions, 13 deletions
diff --git a/guix/download.scm b/guix/download.scm
index e956e084701..2d4bf749518 100644
--- a/guix/download.scm
+++ b/guix/download.scm
@@ -242,20 +242,25 @@ must be a list of symbol/URL-list pairs."
242 (url-fetch '#$url #$output 242 (url-fetch '#$url #$output
243 #:mirrors '#$mirrors))) 243 #:mirrors '#$mirrors)))
244 244
245 (run-with-store store 245 (let ((uri (and (string? url) (string->uri url))))
246 (gexp->derivation (or name file-name) builder 246 (if (or (and (string? url) (not uri))
247 #:system system 247 (and uri (memq (uri-scheme uri) '(#f file))))
248 #:hash-algo hash-algo 248 (add-to-store store (or name file-name)
249 #:hash hash 249 #f "sha256" (if uri (uri-path uri) url))
250 #:modules '((guix build download) 250 (run-with-store store
251 (guix build utils) 251 (gexp->derivation (or name file-name) builder
252 (guix ftp-client)) 252 #:system system
253 #:guile-for-build guile-for-build 253 #:hash-algo hash-algo
254 #:hash hash
255 #:modules '((guix build download)
256 (guix build utils)
257 (guix ftp-client))
258 #:guile-for-build guile-for-build
254 259
255 ;; In general, offloading downloads is not a good idea. 260 ;; In general, offloading downloads is not a good idea.
256 #:local-build? #t) 261 #:local-build? #t)
257 #:guile-for-build guile-for-build 262 #:guile-for-build guile-for-build
258 #:system system)) 263 #:system system))))
259 264
260(define* (download-to-store store url #:optional (name (basename url)) 265(define* (download-to-store store url #:optional (name (basename url))
261 #:key (log (current-error-port))) 266 #:key (log (current-error-port)))
diff --git a/tests/builders.scm b/tests/builders.scm
index ce1f3852d70..a2f500a94d9 100644
--- a/tests/builders.scm
+++ b/tests/builders.scm
@@ -25,6 +25,7 @@
25 #:use-module (guix utils) 25 #:use-module (guix utils)
26 #:use-module (guix base32) 26 #:use-module (guix base32)
27 #:use-module (guix derivations) 27 #:use-module (guix derivations)
28 #:use-module (guix hash)
28 #:use-module (guix tests) 29 #:use-module (guix tests)
29 #:use-module ((guix packages) 30 #:use-module ((guix packages)
30 #:select (package-derivation package-native-search-paths)) 31 #:select (package-derivation package-native-search-paths))
@@ -74,6 +75,22 @@
74 (file-exists? out-path) 75 (file-exists? out-path)
75 (valid-path? %store out-path)))) 76 (valid-path? %store out-path))))
76 77
78(test-assert "url-fetch, file"
79 (let* ((file (search-path %load-path "guix.scm"))
80 (hash (call-with-input-file file port-sha256))
81 (out (url-fetch %store file 'sha256 hash)))
82 (and (file-exists? out)
83 (valid-path? %store out))))
84
85(test-assert "url-fetch, file URI"
86 (let* ((file (search-path %load-path "guix.scm"))
87 (hash (call-with-input-file file port-sha256))
88 (out (url-fetch %store
89 (string-append "file://" (canonicalize-path file))
90 'sha256 hash)))
91 (and (file-exists? out)
92 (valid-path? %store out))))
93
77(test-assert "gnu-build-system" 94(test-assert "gnu-build-system"
78 (and (build-system? gnu-build-system) 95 (and (build-system? gnu-build-system)
79 (eq? gnu-build (build-system-builder gnu-build-system)))) 96 (eq? gnu-build (build-system-builder gnu-build-system))))