evaluate.scm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016-2018, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
  4. ;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
  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. ;;; This program replicates the behavior of Cuirass's 'evaluate' process.
  21. ;;; It displays the evaluated jobs on the standard output.
  22. (use-modules (guix channels)
  23. (guix derivations)
  24. (guix git-download)
  25. (guix inferior)
  26. (guix packages)
  27. (guix store)
  28. (guix ui)
  29. ((guix ui) #:select (build-notifier))
  30. (ice-9 match)
  31. (ice-9 threads))
  32. (define %top-srcdir
  33. (and=> (assq-ref (current-source-location) 'filename)
  34. (lambda (file)
  35. (canonicalize-path
  36. (string-append (dirname file) "/../..")))))
  37. (match (command-line)
  38. ((command directory)
  39. (let ((real-build-things build-things))
  40. (with-store store
  41. ;; Make sure we don't resort to substitutes.
  42. (set-build-options store
  43. #:use-substitutes? #f
  44. #:substitute-urls '())
  45. ;; The evaluation of Guix itself requires building a "trampoline"
  46. ;; program, and possibly everything it depends on. Thus, allow builds
  47. ;; but print a notification.
  48. (with-build-handler (build-notifier #:use-substitutes? #f)
  49. ;; Add %TOP-SRCDIR to the store with a proper Git predicate so we
  50. ;; work from a clean checkout.
  51. (let ((source (add-to-store store "guix-source" #t
  52. "sha256" %top-srcdir
  53. #:select? (git-predicate %top-srcdir))))
  54. (define instances
  55. (list (checkout->channel-instance source)))
  56. (define channels
  57. (map channel-instance-channel instances))
  58. (define derivation
  59. ;; Compute the derivation of Guix for COMMIT.
  60. (run-with-store store
  61. (channel-instances->derivation instances)))
  62. ;; TODO: Remove 'show-what-to-build' call when Cuirass' 'evaluate'
  63. ;; scripts uses 'with-build-handler'.
  64. (show-what-to-build store (list derivation))
  65. (build-derivations store (list derivation))
  66. ;; Evaluate jobs on a per-system basis for two reasons. It speeds
  67. ;; up the evaluation speed as the evaluations can be performed
  68. ;; concurrently. It also decreases the amount of memory needed per
  69. ;; evaluation process.
  70. ;;
  71. ;; Fork inferior processes upfront before we have created any
  72. ;; threads.
  73. (let ((inferiors (map (lambda _
  74. (open-inferior (derivation->output-path derivation)))
  75. %cuirass-supported-systems)))
  76. (n-par-for-each
  77. (min (length %cuirass-supported-systems)
  78. (current-processor-count))
  79. (lambda (system inferior)
  80. (with-store store
  81. (let ((channels (map channel-instance->sexp instances)))
  82. (inferior-eval '(use-modules (gnu ci)) inferior)
  83. (let ((jobs
  84. (inferior-eval-with-store
  85. inferior store
  86. `(lambda (store)
  87. (cuirass-jobs store
  88. '((subset . all)
  89. (systems . ,(list system))
  90. (channels . ,channels))))))
  91. (file
  92. (string-append directory "/jobs-" system ".scm")))
  93. (close-inferior inferior)
  94. (call-with-output-file file
  95. (lambda (port)
  96. (write jobs port)))))))
  97. %cuirass-supported-systems
  98. inferiors)))))))
  99. (x
  100. (format (current-error-port) "Wrong command: ~a~%." x)
  101. (exit 1)))