Commit | Line | Data |
---|---|---|
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> |
f97c9e4c | 4 | ;;; Copyright © 2017, 2019 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 | 34 | svn-fetch |
f97c9e4c RW |
35 | download-svn-to-store |
36 | ||
37 | svn-multi-reference | |
38 | svn-multi-reference? | |
39 | svn-multi-reference-url | |
40 | svn-multi-reference-revision | |
41 | svn-multi-reference-locations | |
42 | svn-multi-fetch)) | |
b3acf365 SHT |
43 | |
44 | ;;; Commentary: | |
45 | ;;; | |
46 | ;;; An <origin> method that fetches a specific revision from a Subversion | |
47 | ;;; repository. The repository URL and REVISION are specified with a | |
48 | ;;; <svn-reference> object. REVISION should be specified as a number. | |
49 | ;;; | |
50 | ;;; Code: | |
51 | ||
52 | (define-record-type* <svn-reference> | |
53 | svn-reference make-svn-reference | |
54 | svn-reference? | |
140dd8f8 RW |
55 | (url svn-reference-url) ; string |
56 | (revision svn-reference-revision) ; number | |
57 | (user-name svn-reference-user-name (default #f)) | |
58 | (password svn-reference-password (default #f))) | |
b3acf365 | 59 | |
bc672694 LC |
60 | (define (subversion-package) |
61 | "Return the default Subversion package." | |
62 | (let ((distro (resolve-interface '(gnu packages version-control)))) | |
63 | (module-ref distro 'subversion))) | |
64 | ||
f220a838 | 65 | (define* (svn-fetch ref hash-algo hash |
b3acf365 | 66 | #:optional name |
f220a838 | 67 | #:key (system (%current-system)) (guile (default-guile)) |
bc672694 | 68 | (svn (subversion-package))) |
f220a838 LC |
69 | "Return a fixed-output derivation that fetches REF, a <svn-reference> |
70 | object. The output is expected to have recursive hash HASH of type | |
71 | HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." | |
bc672694 | 72 | (define build |
e9b046fd LC |
73 | (with-imported-modules '((guix build svn) |
74 | (guix build utils)) | |
75 | #~(begin | |
76 | (use-modules (guix build svn)) | |
77 | (svn-fetch '#$(svn-reference-url ref) | |
78 | '#$(svn-reference-revision ref) | |
79 | #$output | |
80 | #:svn-command (string-append #+svn "/bin/svn") | |
81 | #:user-name #$(svn-reference-user-name ref) | |
82 | #:password #$(svn-reference-password ref))))) | |
b3acf365 | 83 | |
f97c9e4c RW |
84 | (mlet %store-monad ((guile (package->derivation guile system))) |
85 | (gexp->derivation (or name "svn-checkout") build | |
86 | #:system system | |
87 | #:hash-algo hash-algo | |
88 | #:hash hash | |
89 | #:recursive? #t | |
90 | #:guile-for-build guile | |
91 | #:local-build? #t))) | |
92 | ||
93 | (define-record-type* <svn-multi-reference> | |
94 | svn-multi-reference make-svn-multi-reference | |
95 | svn-multi-reference? | |
96 | (url svn-multi-reference-url) ; string | |
97 | (revision svn-multi-reference-revision) ; number | |
98 | (locations svn-multi-reference-locations) ; list of strings | |
99 | (user-name svn-multi-reference-user-name (default #f)) | |
100 | (password svn-multi-reference-password (default #f))) | |
101 | ||
102 | (define* (svn-multi-fetch ref hash-algo hash | |
103 | #:optional name | |
104 | #:key (system (%current-system)) (guile (default-guile)) | |
105 | (svn (subversion-package))) | |
106 | "Return a fixed-output derivation that fetches REF, a <svn-multi-reference> | |
107 | object. The output is expected to have recursive hash HASH of type | |
108 | HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." | |
109 | (define build | |
110 | (with-imported-modules '((guix build svn) | |
111 | (guix build utils)) | |
112 | #~(begin | |
113 | (use-modules (guix build svn) | |
114 | (guix build utils) | |
115 | (srfi srfi-1)) | |
116 | (every (lambda (location) | |
117 | ;; The directory must exist if we are to fetch only a | |
118 | ;; single file. | |
119 | (unless (string-suffix? "/" location) | |
120 | (mkdir-p (string-append #$output "/" (dirname location)))) | |
121 | (svn-fetch (string-append '#$(svn-multi-reference-url ref) | |
122 | "/" location) | |
123 | '#$(svn-multi-reference-revision ref) | |
124 | (if (string-suffix? "/" location) | |
125 | (string-append #$output "/" location) | |
126 | (string-append #$output "/" (dirname location))) | |
127 | #:svn-command (string-append #+svn "/bin/svn") | |
128 | #:user-name #$(svn-multi-reference-user-name ref) | |
129 | #:password #$(svn-multi-reference-password ref))) | |
130 | '#$(svn-multi-reference-locations ref))))) | |
131 | ||
f220a838 | 132 | (mlet %store-monad ((guile (package->derivation guile system))) |
bc672694 LC |
133 | (gexp->derivation (or name "svn-checkout") build |
134 | #:system system | |
bc672694 LC |
135 | #:hash-algo hash-algo |
136 | #:hash hash | |
137 | #:recursive? #t | |
f220a838 LC |
138 | #:guile-for-build guile |
139 | #:local-build? #t))) | |
b3acf365 | 140 | |
bef0db37 RW |
141 | (define* (download-svn-to-store store ref |
142 | #:optional (name (basename (svn-reference-url ref))) | |
143 | #:key (log (current-error-port))) | |
144 | "Download from REF, a <svn-reference> object to STORE. Write progress | |
145 | reports to LOG." | |
146 | (call-with-temporary-directory | |
147 | (lambda (temp) | |
148 | (let ((result | |
149 | (parameterize ((current-output-port log)) | |
150 | (build:svn-fetch (svn-reference-url ref) | |
151 | (svn-reference-revision ref) | |
152 | temp | |
153 | #:user-name (svn-reference-user-name ref) | |
154 | #:password (svn-reference-password ref))))) | |
155 | (and result | |
156 | (add-to-store store name #t "sha256" temp)))))) | |
157 | ||
b3acf365 | 158 | ;;; svn-download.scm ends here |