stackage.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix scripts import stackage)
  21. #:use-module (guix ui)
  22. #:use-module (guix utils)
  23. #:use-module (guix packages)
  24. #:use-module (guix scripts)
  25. #:use-module (guix import stackage)
  26. #:use-module (guix scripts import)
  27. #:use-module (srfi srfi-1)
  28. #:use-module (srfi srfi-11)
  29. #:use-module (srfi srfi-37)
  30. #:use-module (ice-9 match)
  31. #:use-module (ice-9 format)
  32. #:export (guix-import-stackage))
  33. ;;;
  34. ;;; Command-line options.
  35. ;;;
  36. (define %default-options
  37. `((lts-version . "")
  38. (include-test-dependencies? . #t)))
  39. (define (show-help)
  40. (display (G_ "Usage: guix import stackage PACKAGE-NAME
  41. Import and convert the LTS Stackage package for PACKAGE-NAME.\n"))
  42. (display (G_ "
  43. -l VERSION, --lts-version=VERSION
  44. specify the LTS version to use"))
  45. (display (G_ "
  46. -h, --help display this help and exit"))
  47. (display (G_ "
  48. -r, --recursive import packages recursively"))
  49. (display (G_ "
  50. -t, --no-test-dependencies don't include test-only dependencies"))
  51. (display (G_ "
  52. -V, --version display version information and exit"))
  53. (newline)
  54. (show-bug-report-information))
  55. (define %options
  56. ;; Specification of the command-line options.
  57. (cons* (option '(#\h "help") #f #f
  58. (lambda args
  59. (show-help)
  60. (exit 0)))
  61. (option '(#\V "version") #f #f
  62. (lambda args
  63. (show-version-and-exit "guix import stackage")))
  64. (option '(#\t "no-test-dependencies") #f #f
  65. (lambda (opt name arg result)
  66. (alist-cons 'include-test-dependencies? #f
  67. (alist-delete 'include-test-dependencies?
  68. result))))
  69. (option '(#\l "lts-version") #t #f
  70. (lambda (opt name arg result)
  71. (alist-cons 'lts-version arg
  72. (alist-delete 'lts-version
  73. result))))
  74. (option '(#\r "recursive") #f #f
  75. (lambda (opt name arg result)
  76. (alist-cons 'recursive #t result)))
  77. %standard-import-options))
  78. ;;;
  79. ;;; Entry point.
  80. ;;;
  81. (define (guix-import-stackage . args)
  82. (define (parse-options)
  83. ;; Return the alist of option values.
  84. (parse-command-line args %options (list %default-options)
  85. #:build-options? #f))
  86. (define (run-importer package-name opts error-fn)
  87. (let* ((arguments (list
  88. package-name
  89. #:include-test-dependencies?
  90. (assoc-ref opts 'include-test-dependencies?)
  91. #:lts-version (assoc-ref opts 'lts-version)))
  92. (sexp (if (assoc-ref opts 'recursive)
  93. ;; Recursive import
  94. (map (match-lambda
  95. ((and ('package ('name name) . rest) pkg)
  96. `(define-public ,(string->symbol name)
  97. ,pkg))
  98. (_ #f))
  99. (apply stackage-recursive-import arguments))
  100. ;; Single import
  101. (apply stackage->guix-package arguments))))
  102. (unless sexp (error-fn))
  103. sexp))
  104. (let* ((opts (parse-options))
  105. (args (filter-map (match-lambda
  106. (('argument . value)
  107. value)
  108. (_ #f))
  109. (reverse opts))))
  110. (match args
  111. ((package-name)
  112. (with-error-handling
  113. (run-importer package-name opts
  114. (lambda ()
  115. (leave (G_ "failed to download cabal file \
  116. for package '~a'~%")
  117. package-name)))))
  118. (()
  119. (leave (G_ "too few arguments~%")))
  120. ((many ...)
  121. (leave (G_ "too many arguments~%"))))))
  122. ;;; stackage.scm ends here