svn-download.scm 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014 Sree Harsha Totakura <sreeharsha@totakura.in>
  4. ;;; Copyright © 2017, 2019, 2021 Ricardo Wurmus <rekado@elephly.net>
  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. (define-module (guix svn-download)
  21. #:use-module (guix records)
  22. #:use-module (guix gexp)
  23. #:use-module (guix store)
  24. #:use-module (guix monads)
  25. #:use-module (guix packages)
  26. #:use-module (guix utils)
  27. #:use-module ((guix build svn) #:prefix build:)
  28. #:use-module ((guix build utils) #:select (mkdir-p))
  29. #:use-module (ice-9 match)
  30. #:use-module (srfi srfi-1)
  31. #:export (svn-reference
  32. svn-reference?
  33. svn-reference-url
  34. svn-reference-revision
  35. svn-reference-recursive?
  36. svn-fetch
  37. download-svn-to-store
  38. svn-multi-reference
  39. svn-multi-reference?
  40. svn-multi-reference-url
  41. svn-multi-reference-revision
  42. svn-multi-reference-locations
  43. svn-multi-reference-recursive?
  44. svn-multi-fetch
  45. download-multi-svn-to-store))
  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. (define-record-type* <svn-reference>
  54. svn-reference make-svn-reference
  55. svn-reference?
  56. (url svn-reference-url) ; string
  57. (revision svn-reference-revision) ; number
  58. (recursive? svn-reference-recursive? (default #t))
  59. (user-name svn-reference-user-name (default #f))
  60. (password svn-reference-password (default #f)))
  61. (define (subversion-package)
  62. "Return the default Subversion package."
  63. (let ((distro (resolve-interface '(gnu packages version-control))))
  64. (module-ref distro 'subversion)))
  65. (define* (svn-fetch ref hash-algo hash
  66. #:optional name
  67. #:key (system (%current-system)) (guile (default-guile))
  68. (svn (subversion-package)))
  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."
  72. (define build
  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. #:recursive? #$(svn-reference-recursive? ref)
  82. #:user-name #$(svn-reference-user-name ref)
  83. #:password #$(svn-reference-password ref)))))
  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. (define-record-type* <svn-multi-reference>
  93. svn-multi-reference make-svn-multi-reference
  94. svn-multi-reference?
  95. (url svn-multi-reference-url) ; string
  96. (revision svn-multi-reference-revision) ; number
  97. (locations svn-multi-reference-locations) ; list of strings
  98. (recursive? svn-multi-reference-recursive? (default #t))
  99. (user-name svn-multi-reference-user-name (default #f))
  100. (password svn-multi-reference-password (default #f)))
  101. (define* (svn-multi-fetch ref hash-algo hash
  102. #:optional name
  103. #:key (system (%current-system)) (guile (default-guile))
  104. (svn (subversion-package)))
  105. "Return a fixed-output derivation that fetches REF, a <svn-multi-reference>
  106. object. The output is expected to have recursive hash HASH of type
  107. HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
  108. (define build
  109. (with-imported-modules '((guix build svn)
  110. (guix build utils))
  111. #~(begin
  112. (use-modules (guix build svn)
  113. (guix build utils)
  114. (srfi srfi-1))
  115. (every (lambda (location)
  116. ;; The directory must exist if we are to fetch only a
  117. ;; single file.
  118. (unless (string-suffix? "/" location)
  119. (mkdir-p (string-append #$output "/" (dirname location))))
  120. (svn-fetch (string-append '#$(svn-multi-reference-url ref)
  121. "/" location)
  122. '#$(svn-multi-reference-revision ref)
  123. (if (string-suffix? "/" location)
  124. (string-append #$output "/" location)
  125. (string-append #$output "/" (dirname location)))
  126. #:svn-command (string-append #+svn "/bin/svn")
  127. #:recursive?
  128. #$(svn-multi-reference-recursive? ref)
  129. #:user-name #$(svn-multi-reference-user-name ref)
  130. #:password #$(svn-multi-reference-password ref)))
  131. '#$(sexp->gexp (svn-multi-reference-locations ref))))))
  132. (mlet %store-monad ((guile (package->derivation guile system)))
  133. (gexp->derivation (or name "svn-checkout") build
  134. #:leaked-env-vars '("http_proxy" "https_proxy"
  135. "LC_ALL" "LC_MESSAGES" "LANG"
  136. "COLUMNS")
  137. #:system system
  138. #:hash-algo hash-algo
  139. #:hash hash
  140. #:recursive? #t
  141. #:guile-for-build guile
  142. #:local-build? #t)))
  143. (define* (download-svn-to-store store ref
  144. #:optional (name (basename (svn-reference-url ref)))
  145. #:key (log (current-error-port)))
  146. "Download from REF, a <svn-reference> object to STORE. Write progress
  147. reports to LOG."
  148. (call-with-temporary-directory
  149. (lambda (temp)
  150. (let ((result
  151. (parameterize ((current-output-port log))
  152. (build:svn-fetch (svn-reference-url ref)
  153. (svn-reference-revision ref)
  154. (string-append temp "/svn")
  155. #:user-name (svn-reference-user-name ref)
  156. #:password (svn-reference-password ref)))))
  157. (and result
  158. (add-to-store store name #t "sha256"
  159. (string-append temp "/svn")))))))
  160. (define* (download-multi-svn-to-store store ref
  161. #:optional (name (basename (svn-multi-reference-url ref)))
  162. #:key (log (current-error-port)))
  163. "Download from REF, a <svn-multi-reference> object to STORE. Write progress
  164. reports to LOG."
  165. (call-with-temporary-directory
  166. (lambda (temp)
  167. (and (every (lambda (location)
  168. (let ((dir (string-append temp "/" (dirname location))))
  169. (mkdir-p dir))
  170. (parameterize ((current-output-port log))
  171. (build:svn-fetch (string-append (svn-multi-reference-url ref)
  172. "/" location)
  173. (svn-multi-reference-revision ref)
  174. (if (string-suffix? "/" location)
  175. (string-append temp "/" location)
  176. (string-append temp "/" (dirname location)))
  177. #:recursive?
  178. (svn-multi-reference-recursive? ref)
  179. #:user-name (svn-multi-reference-user-name ref)
  180. #:password (svn-multi-reference-password ref))))
  181. (svn-multi-reference-locations ref))
  182. (add-to-store store name #t "sha256" temp)))))
  183. ;;; svn-download.scm ends here