hg.scm 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
  3. ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
  5. ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix build hg)
  22. #:use-module (guix build utils)
  23. #:use-module (srfi srfi-34)
  24. #:use-module (ice-9 format)
  25. #:export (hg-fetch))
  26. ;;; Commentary:
  27. ;;;
  28. ;;; This is the build-side support code of (guix hg-download). It allows a
  29. ;;; Mercurial repository to be cloned and checked out at a specific changeset
  30. ;;; identifier.
  31. ;;;
  32. ;;; Code:
  33. (define* (hg-fetch url changeset directory
  34. #:key (hg-command "hg"))
  35. "Fetch CHANGESET from URL into DIRECTORY. CHANGESET must be a valid
  36. Mercurial changeset identifier. Return #t on success, #f otherwise."
  37. (mkdir-p directory)
  38. (guard (c ((invoke-error? c)
  39. (format (current-error-port)
  40. "hg-fetch: '~a~{ ~a~}' failed with exit code ~a~%"
  41. (invoke-error-program c)
  42. (invoke-error-arguments c)
  43. (or (invoke-error-exit-status c)
  44. (invoke-error-stop-signal c)
  45. (invoke-error-term-signal c)))
  46. (delete-file-recursively directory)
  47. #f))
  48. (with-directory-excursion directory
  49. (invoke hg-command
  50. "clone" url
  51. "--rev" changeset
  52. ;; Disable TLS certificate verification. The hash of
  53. ;; the checkout is known in advance anyway.
  54. "--insecure"
  55. directory)
  56. ;; The contents of '.hg' vary as a function of the current
  57. ;; status of the Mercurial repo. Since we want a fixed
  58. ;; output, this directory needs to be taken out.
  59. ;; Since the '.hg' file is also in sub-modules, we have to
  60. ;; search for it in all sub-directories.
  61. (for-each delete-file-recursively
  62. (find-files directory "^\\.hg$" #:directories? #t))
  63. #t)))
  64. ;;; hg.scm ends here