evaluate.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017, 2018, 2020 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. (n-par-for-each
  71. (/ (current-processor-count) 2)
  72. (lambda (system)
  73. (with-store store
  74. (let ((inferior
  75. (open-inferior (derivation->output-path derivation)))
  76. (channels (map channel-instance->sexp instances)))
  77. (inferior-eval '(use-modules (gnu ci)) inferior)
  78. (let ((jobs
  79. (inferior-eval-with-store
  80. inferior store
  81. `(lambda (store)
  82. (cuirass-jobs store
  83. '((subset . all)
  84. (systems . ,(list system))
  85. (channels . ,channels))))))
  86. (file
  87. (string-append directory "/jobs-" system ".scm")))
  88. (call-with-output-file file
  89. (lambda (port)
  90. (write jobs port)))))))
  91. %cuirass-supported-systems))))))
  92. (x
  93. (format (current-error-port) "Wrong command: ~a~%." x)
  94. (exit 1)))