opam.scm 3.4 KB

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