svn-download.scm 7.4 KB

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