svn-download.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014 Sree Harsha Totakura <sreeharsha@totakura.in>
  4. ;;; Copyright © 2017 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-fetch
  34. download-svn-to-store))
  35. ;;; Commentary:
  36. ;;;
  37. ;;; An <origin> method that fetches a specific revision from a Subversion
  38. ;;; repository. The repository URL and REVISION are specified with a
  39. ;;; <svn-reference> object. REVISION should be specified as a number.
  40. ;;;
  41. ;;; Code:
  42. (define-record-type* <svn-reference>
  43. svn-reference make-svn-reference
  44. svn-reference?
  45. (url svn-reference-url) ; string
  46. (revision svn-reference-revision) ; number
  47. (user-name svn-reference-user-name (default #f))
  48. (password svn-reference-password (default #f)))
  49. (define (subversion-package)
  50. "Return the default Subversion package."
  51. (let ((distro (resolve-interface '(gnu packages version-control))))
  52. (module-ref distro 'subversion)))
  53. (define* (svn-fetch ref hash-algo hash
  54. #:optional name
  55. #:key (system (%current-system)) (guile (default-guile))
  56. (svn (subversion-package)))
  57. "Return a fixed-output derivation that fetches REF, a <svn-reference>
  58. object. The output is expected to have recursive hash HASH of type
  59. HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
  60. (define build
  61. (with-imported-modules '((guix build svn)
  62. (guix build utils))
  63. #~(begin
  64. (use-modules (guix build svn))
  65. (svn-fetch '#$(svn-reference-url ref)
  66. '#$(svn-reference-revision ref)
  67. #$output
  68. #:svn-command (string-append #+svn "/bin/svn")
  69. #:user-name #$(svn-reference-user-name ref)
  70. #:password #$(svn-reference-password ref)))))
  71. (mlet %store-monad ((guile (package->derivation guile system)))
  72. (gexp->derivation (or name "svn-checkout") build
  73. #:system system
  74. #:hash-algo hash-algo
  75. #:hash hash
  76. #:recursive? #t
  77. #:guile-for-build guile
  78. #:local-build? #t)))
  79. (define* (download-svn-to-store store ref
  80. #:optional (name (basename (svn-reference-url ref)))
  81. #:key (log (current-error-port)))
  82. "Download from REF, a <svn-reference> object to STORE. Write progress
  83. reports to LOG."
  84. (call-with-temporary-directory
  85. (lambda (temp)
  86. (let ((result
  87. (parameterize ((current-output-port log))
  88. (build:svn-fetch (svn-reference-url ref)
  89. (svn-reference-revision ref)
  90. temp
  91. #:user-name (svn-reference-user-name ref)
  92. #:password (svn-reference-password ref)))))
  93. (and result
  94. (add-to-store store name #t "sha256" temp))))))
  95. ;;; svn-download.scm ends here