cvs.scm 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
  3. ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build cvs)
  20. #:use-module (guix build utils)
  21. #:use-module (ice-9 regex)
  22. #:use-module (ice-9 ftw)
  23. #:export (cvs-fetch))
  24. ;;; Commentary:
  25. ;;;
  26. ;;; This is the build-side support code of (guix cvs-download). It allows a
  27. ;;; CVS repository to be checked out at a specific revision or date.
  28. ;;;
  29. ;;; Code:
  30. (define (find-cvs-directories)
  31. (define (enter? path st result)
  32. (not (string-suffix? "/CVS" path)))
  33. (define (leaf path st result) result)
  34. (define (down path st result) result)
  35. (define (up path st result) result)
  36. (define (skip path st result)
  37. (if (and (string-suffix? "/CVS" path)
  38. (eqv? 'directory (stat:type st)))
  39. (cons path result)
  40. result))
  41. (define (error path st errno result)
  42. (format (current-error-port) "cvs-fetch: ~a: ~a~%"
  43. path (strerror errno)))
  44. (sort (file-system-fold enter? leaf down up skip error '() "." lstat)
  45. string<?))
  46. (define* (cvs-fetch cvs-root-directory module revision directory
  47. #:key (cvs-command "cvs"))
  48. "Fetch REVISION from MODULE of CVS-ROOT-DIRECTORY into DIRECTORY. REVISION
  49. must either be a date in ISO-8601 format (e.g. \"2012-12-21\") or a CVS tag.
  50. Return #t on success, #f otherwise."
  51. ;; Use "-z0" because enabling compression leads to hangs during checkout on
  52. ;; certain repositories, such as
  53. ;; ":pserver:anonymous@cvs.savannah.gnu.org:/sources/gnustandards".
  54. (invoke cvs-command "-z0"
  55. "-d" cvs-root-directory
  56. "checkout"
  57. (if (string-match "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" revision)
  58. "-D" "-r")
  59. revision
  60. module)
  61. ;; Copy rather than rename in case MODULE and DIRECTORY are on
  62. ;; different devices.
  63. (copy-recursively module directory)
  64. (with-directory-excursion directory
  65. (for-each delete-file-recursively (find-cvs-directories)))
  66. #t)
  67. ;;; cvs.scm ends here