build: svn-fetch: Use "svn export".
[jackhill/guix/guix.git] / guix / svn-download.scm
CommitLineData
b3acf365 1;;; GNU Guix --- Functional package management for GNU
e9b046fd 2;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
b3acf365 3;;; Copyright © 2014 Sree Harsha Totakura <sreeharsha@totakura.in>
bef0db37 4;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
b3acf365
SHT
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21(define-module (guix svn-download)
22 #:use-module (guix records)
bc672694 23 #:use-module (guix gexp)
e87f0591 24 #:use-module (guix store)
bc672694 25 #:use-module (guix monads)
b3acf365 26 #:use-module (guix packages)
bef0db37
RW
27 #:use-module (guix utils)
28 #:use-module ((guix build svn) #:prefix build:)
b3acf365
SHT
29 #:use-module (ice-9 match)
30 #:export (svn-reference
31 svn-reference?
32 svn-reference-url
33 svn-reference-revision
bef0db37
RW
34 svn-fetch
35 download-svn-to-store))
b3acf365
SHT
36
37;;; Commentary:
38;;;
39;;; An <origin> method that fetches a specific revision from a Subversion
40;;; repository. The repository URL and REVISION are specified with a
41;;; <svn-reference> object. REVISION should be specified as a number.
42;;;
43;;; Code:
44
45(define-record-type* <svn-reference>
46 svn-reference make-svn-reference
47 svn-reference?
140dd8f8
RW
48 (url svn-reference-url) ; string
49 (revision svn-reference-revision) ; number
50 (user-name svn-reference-user-name (default #f))
51 (password svn-reference-password (default #f)))
b3acf365 52
bc672694
LC
53(define (subversion-package)
54 "Return the default Subversion package."
55 (let ((distro (resolve-interface '(gnu packages version-control))))
56 (module-ref distro 'subversion)))
57
f220a838 58(define* (svn-fetch ref hash-algo hash
b3acf365 59 #:optional name
f220a838 60 #:key (system (%current-system)) (guile (default-guile))
bc672694 61 (svn (subversion-package)))
f220a838
LC
62 "Return a fixed-output derivation that fetches REF, a <svn-reference>
63object. The output is expected to have recursive hash HASH of type
64HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
bc672694 65 (define build
e9b046fd
LC
66 (with-imported-modules '((guix build svn)
67 (guix build utils))
68 #~(begin
69 (use-modules (guix build svn))
70 (svn-fetch '#$(svn-reference-url ref)
71 '#$(svn-reference-revision ref)
72 #$output
73 #:svn-command (string-append #+svn "/bin/svn")
74 #:user-name #$(svn-reference-user-name ref)
75 #:password #$(svn-reference-password ref)))))
b3acf365 76
f220a838 77 (mlet %store-monad ((guile (package->derivation guile system)))
bc672694
LC
78 (gexp->derivation (or name "svn-checkout") build
79 #:system system
bc672694
LC
80 #:hash-algo hash-algo
81 #:hash hash
82 #:recursive? #t
f220a838
LC
83 #:guile-for-build guile
84 #:local-build? #t)))
b3acf365 85
bef0db37
RW
86(define* (download-svn-to-store store ref
87 #:optional (name (basename (svn-reference-url ref)))
88 #:key (log (current-error-port)))
89 "Download from REF, a <svn-reference> object to STORE. Write progress
90reports to LOG."
91 (call-with-temporary-directory
92 (lambda (temp)
93 (let ((result
94 (parameterize ((current-output-port log))
95 (build:svn-fetch (svn-reference-url ref)
96 (svn-reference-revision ref)
97 temp
98 #:user-name (svn-reference-user-name ref)
99 #:password (svn-reference-password ref)))))
100 (and result
101 (add-to-store store name #t "sha256" temp))))))
102
b3acf365 103;;; svn-download.scm ends here