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