antioxidant-ci.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ;;; Antioxidant --- Building Rust without cargo
  2. ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
  3. ;;;
  4. ;;; This file is part of Antioxidant.
  5. ;;;
  6. ;;; Antioxidant 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. ;;; Antioxidant 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 Antioxidant. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (antioxidant-ci)
  19. #:use-module ((antioxidant-packages) #:select (vitaminate/auto public-test-package
  20. antioxidant-build-system))
  21. #:use-module ((guix build-system cargo) #:select (cargo-build-system))
  22. #:use-module ((guix profiles) #:select (packages->manifest))
  23. #:use-module ((guix packages) #:select (package? package-direct-inputs))
  24. #:use-module ((gnu packages) #:select (fold-packages))
  25. #:use-module ((rnrs exceptions) #:select (guard))
  26. #:use-module (ice-9 vlist)
  27. #:use-module (srfi srfi-1)
  28. #:use-module ((guix packages) #:select (package-build-system package-name))
  29. #:autoload (guix ui) (warning G_)
  30. #:export (all-packages))
  31. (define (is-leaf-cargo-rust-package? package)
  32. (and (eq? cargo-build-system (package-build-system package))
  33. (not (string-prefix? "rust-" (package-name package)))))
  34. (define (all-packages)
  35. "Return a list of all antioxidated leaf packages (not guaranteed to build yet)"
  36. (define (manually-antioxidated-variant package)
  37. ;; Some leaf package are updated or patched. In that case, vitaminate/auto
  38. ;; will _not_ choose the updated or patched version. However, a ‘manually’
  39. ;; antioxidated will be defined in (antioxidant-packages).
  40. (and=> (module-variable
  41. (resolve-interface '(antioxidant-packages))
  42. (string->symbol (string-append "antioxidated-" (package-name package))))
  43. variable-ref))
  44. (define (add foo list)
  45. (guard (c ((eq? (exception-kind c) 'antioxidant-cycle)
  46. (warning (G_ "skipping ~a for now because of cycle~%") (package-name foo))
  47. list)
  48. ((eq? (exception-kind c) 'keyword-argument-error)
  49. (warning (G_ "skipping ~a for now because of ~a~%") (package-name foo) c)
  50. list))
  51. (cons (or (manually-antioxidated-variant foo)
  52. (public-test-package (vitaminate/auto foo))) list)))
  53. (fold-packages add '() #:select? is-leaf-cargo-rust-package?))
  54. (define (package-closure/vhash todo seen descend?)
  55. ;; Compute the closure, depth-first
  56. ;; todo: list of packages
  57. ;; seen: vhash -> #true of packages
  58. (define (only-package input)
  59. (second input))
  60. (define (proc new-package seen)
  61. (cond ((vhash-assq new-package seen) ; already visited
  62. seen)
  63. ((descend? new-package)
  64. (package-closure/vhash
  65. (map only-package (package-direct-inputs new-package))
  66. (vhash-consq new-package #true seen)
  67. descend?))
  68. (#true
  69. (vhash-consq new-package #true seen))))
  70. (fold proc seen todo))
  71. (define (rusty-package-closure packages)
  72. (define (vhash->key-list vhash)
  73. (define (cons-it key _ rest)
  74. (cons key rest))
  75. (vhash-fold cons-it '() vhash))
  76. (define (descend? package)
  77. (and (package? package) ; could be an <origin>
  78. (or (string-prefix? "antioxidated-" (package-name package))
  79. (string-prefix? "rust-" (package-name package))
  80. (eq? (package-build-system package) antioxidant-build-system))))
  81. (vhash->key-list (package-closure/vhash packages vlist-null descend?)))
  82. ;; The idea is to build all packages in (all-packages) by the CI infrastructure.
  83. ;; Apparently returning a manifest is convenient for the CI infrastructure, see
  84. ;; see <https://github.com/emixa-d/antioxidant-fallback/pull/1>.
  85. ;;
  86. ;; By using rusty-package-closure, the intermediate packages are shown as well.
  87. (packages->manifest (rusty-package-closure (all-packages)))