gem.scm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 David Thompson <davet@gnu.org>
  3. ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
  4. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  5. ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
  6. ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (guix scripts import gem)
  23. #:use-module (guix ui)
  24. #:use-module (guix utils)
  25. #:use-module (guix scripts)
  26. #:use-module (guix import gem)
  27. #:use-module (guix scripts import)
  28. #:use-module (srfi srfi-1)
  29. #:use-module (srfi srfi-11)
  30. #:use-module (srfi srfi-37)
  31. #:use-module (ice-9 match)
  32. #:use-module (ice-9 format)
  33. #:export (guix-import-gem))
  34. ;;;
  35. ;;; Command-line options.
  36. ;;;
  37. (define %default-options
  38. '())
  39. (define (show-help)
  40. (display (G_ "Usage: guix import gem PACKAGE-NAME
  41. Import and convert the RubyGems package for PACKAGE-NAME.\n"))
  42. (display (G_ "
  43. -h, --help display this help and exit"))
  44. (display (G_ "
  45. -V, --version display version information and exit"))
  46. (display (G_ "
  47. -r, --recursive generate package expressions for all Gem packages\
  48. that are not yet in Guix"))
  49. (newline)
  50. (show-bug-report-information))
  51. (define %options
  52. ;; Specification of the command-line options.
  53. (cons* (option '(#\h "help") #f #f
  54. (lambda args
  55. (show-help)
  56. (exit 0)))
  57. (option '(#\V "version") #f #f
  58. (lambda args
  59. (show-version-and-exit "guix import gem")))
  60. (option '(#\r "recursive") #f #f
  61. (lambda (opt name arg result)
  62. (alist-cons 'recursive #t result)))
  63. %standard-import-options))
  64. ;;;
  65. ;;; Entry point.
  66. ;;;
  67. (define (guix-import-gem . args)
  68. (define (parse-options)
  69. ;; Return the alist of option values.
  70. (parse-command-line args %options (list %default-options)
  71. #:build-options? #f))
  72. (let* ((opts (parse-options))
  73. (args (filter-map (match-lambda
  74. (('argument . value)
  75. value)
  76. (_ #f))
  77. (reverse opts))))
  78. (match args
  79. ((package-name)
  80. (let ((code (if (assoc-ref opts 'recursive)
  81. (map (match-lambda
  82. ((and ('package ('name name) . rest) pkg)
  83. `(define-public ,(string->symbol name)
  84. ,pkg))
  85. (_ #f))
  86. (gem-recursive-import package-name 'rubygems))
  87. (let ((sexp (gem->guix-package package-name)))
  88. (if sexp sexp #f)))))
  89. (match code
  90. ((or #f '(#f))
  91. (leave (G_ "failed to download meta-data for package '~a'~%")
  92. package-name))
  93. (_ code))))
  94. (()
  95. (leave (G_ "too few arguments~%")))
  96. ((many ...)
  97. (leave (G_ "too many arguments~%"))))))