stackage.scm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Federico Beffa <beffa@fbengineering.ch>
  3. ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
  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 scripts import stackage)
  20. #:use-module (guix ui)
  21. #:use-module (guix utils)
  22. #:use-module (guix packages)
  23. #:use-module (guix scripts)
  24. #:use-module (guix import stackage)
  25. #:use-module (guix scripts import)
  26. #:use-module (srfi srfi-1)
  27. #:use-module (srfi srfi-11)
  28. #:use-module (srfi srfi-37)
  29. #:use-module (ice-9 match)
  30. #:use-module (ice-9 format)
  31. #:export (guix-import-stackage))
  32. ;;;
  33. ;;; Command-line options.
  34. ;;;
  35. (define %default-options
  36. `((lts-version . "")
  37. (include-test-dependencies? . #t)))
  38. (define (show-help)
  39. (display (G_ "Usage: guix import stackage PACKAGE-NAME
  40. Import and convert the LTS Stackage package for PACKAGE-NAME.\n"))
  41. (display (G_ "
  42. -l VERSION, --lts-version=VERSION
  43. specify the LTS version to use"))
  44. (display (G_ "
  45. -h, --help display this help and exit"))
  46. (display (G_ "
  47. -r, --recursive import packages recursively"))
  48. (display (G_ "
  49. -t, --no-test-dependencies don't include test-only dependencies"))
  50. (display (G_ "
  51. -V, --version display version information and exit"))
  52. (newline)
  53. (show-bug-report-information))
  54. (define %options
  55. ;; Specification of the command-line options.
  56. (cons* (option '(#\h "help") #f #f
  57. (lambda args
  58. (show-help)
  59. (exit 0)))
  60. (option '(#\V "version") #f #f
  61. (lambda args
  62. (show-version-and-exit "guix import stackage")))
  63. (option '(#\t "no-test-dependencies") #f #f
  64. (lambda (opt name arg result)
  65. (alist-cons 'include-test-dependencies? #f
  66. (alist-delete 'include-test-dependencies?
  67. result))))
  68. (option '(#\l "lts-version") #t #f
  69. (lambda (opt name arg result)
  70. (alist-cons 'lts-version arg
  71. (alist-delete 'lts-version
  72. result))))
  73. (option '(#\r "recursive") #f #f
  74. (lambda (opt name arg result)
  75. (alist-cons 'recursive #t result)))
  76. %standard-import-options))
  77. ;;;
  78. ;;; Entry point.
  79. ;;;
  80. (define (guix-import-stackage . args)
  81. (define (parse-options)
  82. ;; Return the alist of option values.
  83. (args-fold* args %options
  84. (lambda (opt name arg result)
  85. (leave (G_ "~A: unrecognized option~%") name))
  86. (lambda (arg result)
  87. (alist-cons 'argument arg result))
  88. %default-options))
  89. (define (run-importer package-name opts error-fn)
  90. (let* ((arguments (list
  91. package-name
  92. #:include-test-dependencies?
  93. (assoc-ref opts 'include-test-dependencies?)
  94. #:lts-version (assoc-ref opts 'lts-version)))
  95. (sexp (if (assoc-ref opts 'recursive)
  96. ;; Recursive import
  97. (map (match-lambda
  98. ((and ('package ('name name) . rest) pkg)
  99. `(define-public ,(string->symbol name)
  100. ,pkg))
  101. (_ #f))
  102. (apply stackage-recursive-import arguments))
  103. ;; Single import
  104. (apply stackage->guix-package arguments))))
  105. (unless sexp (error-fn))
  106. sexp))
  107. (let* ((opts (parse-options))
  108. (args (filter-map (match-lambda
  109. (('argument . value)
  110. value)
  111. (_ #f))
  112. (reverse opts))))
  113. (match args
  114. ((package-name)
  115. (with-error-handling
  116. (run-importer package-name opts
  117. (lambda ()
  118. (leave (G_ "failed to download cabal file \
  119. for package '~a'~%")
  120. package-name)))))
  121. (()
  122. (leave (G_ "too few arguments~%")))
  123. ((many ...)
  124. (leave (G_ "too many arguments~%"))))))
  125. ;;; stackage.scm ends here