egg.scm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
  3. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  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 egg)
  20. #:use-module (guix ui)
  21. #:use-module (guix utils)
  22. #:use-module (guix scripts)
  23. #:use-module (guix import egg)
  24. #:use-module (guix scripts import)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-11)
  27. #:use-module (srfi srfi-37)
  28. #:use-module (srfi srfi-71)
  29. #:use-module (ice-9 match)
  30. #:use-module (ice-9 format)
  31. #:export (guix-import-egg))
  32. ;;;
  33. ;;; Command-line options.
  34. ;;;
  35. (define %default-options
  36. '())
  37. (define (show-help)
  38. (display (G_ "Usage: guix import egg PACKAGE-NAME
  39. Import and convert the egg package for PACKAGE-NAME.\n"))
  40. (display (G_ "
  41. -h, --help display this help and exit"))
  42. (display (G_ "
  43. -r, --recursive import packages recursively"))
  44. (display (G_ "
  45. -V, --version display version information and exit"))
  46. (newline)
  47. (show-bug-report-information))
  48. (define %options
  49. ;; Specification of the command-line options.
  50. (cons* (option '(#\h "help") #f #f
  51. (lambda args
  52. (show-help)
  53. (exit 0)))
  54. (option '(#\V "version") #f #f
  55. (lambda args
  56. (show-version-and-exit "guix import egg")))
  57. (option '(#\r "recursive") #f #f
  58. (lambda (opt name arg result)
  59. (alist-cons 'recursive #t result)))
  60. %standard-import-options))
  61. ;;;
  62. ;;; Entry point.
  63. ;;;
  64. (define (guix-import-egg . args)
  65. (define (parse-options)
  66. ;; Return the alist of option values.
  67. (parse-command-line args %options (list %default-options)
  68. #:build-options? #f))
  69. (let* ((opts (parse-options))
  70. (repo (and=> (assoc-ref opts 'repo) string->symbol))
  71. (args (filter-map (match-lambda
  72. (('argument . value)
  73. value)
  74. (_ #f))
  75. (reverse opts))))
  76. (match args
  77. ((spec)
  78. (let ((name version (package-name->name+version spec)))
  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. (egg-recursive-import name version))
  87. ;; Single import
  88. (let ((sexp (egg->guix-package name version)))
  89. (unless sexp
  90. (leave (G_ "failed to download meta-data for package '~a'~%")
  91. (if version
  92. (string-append name "@" version)
  93. name)))
  94. sexp))))
  95. (()
  96. (leave (G_ "too few arguments~%")))
  97. ((many ...)
  98. (leave (G_ "too many arguments~%"))))))