evaluate.in 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  2. # -*- scheme -*-
  3. # @configure_input@
  4. GUILE_LOAD_PATH="$1${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
  5. export GUILE_LOAD_PATH
  6. exec ${GUILE:-@GUILE@} --no-auto-compile -e main -s "$0" "$@"
  7. !#
  8. ;;;; evaluate -- convert a specification to a job list
  9. ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
  10. ;;; Copyright © 2016, 2017 Mathieu Lirzin <mthl@gnu.org>
  11. ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
  12. ;;;
  13. ;;; This file is part of Cuirass.
  14. ;;;
  15. ;;; Cuirass is free software: you can redistribute it and/or modify
  16. ;;; it under the terms of the GNU General Public License as published by
  17. ;;; the Free Software Foundation, either version 3 of the License, or
  18. ;;; (at your option) any later version.
  19. ;;;
  20. ;;; Cuirass is distributed in the hope that it will be useful,
  21. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. ;;; GNU General Public License for more details.
  24. ;;;
  25. ;;; You should have received a copy of the GNU General Public License
  26. ;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
  27. (use-modules (cuirass)
  28. (cuirass utils)
  29. (ice-9 match)
  30. (ice-9 pretty-print)
  31. (guix store))
  32. (define* (main #:optional (args (command-line)))
  33. (match args
  34. ((command load-path guix-package-path cachedir specstr database)
  35. ;; Load FILE, a Scheme file that defines Hydra jobs.
  36. (let ((%user-module (make-fresh-user-module))
  37. (spec (with-input-from-string specstr read))
  38. (stdout (current-output-port))
  39. (stderr (current-error-port)))
  40. (save-module-excursion
  41. (λ ()
  42. (set-current-module %user-module)
  43. (with-directory-excursion
  44. (string-append cachedir "/" (assq-ref spec #:name))
  45. (primitive-load (assq-ref spec #:file)))))
  46. (with-store store
  47. (unless (assoc-ref spec #:use-substitutes?)
  48. ;; Make sure we don't resort to substitutes.
  49. (set-build-options store #:use-substitutes? #f #:substitute-urls '()))
  50. ;; Grafts can trigger early builds. We do not want that to happen
  51. ;; during evaluation, so use a sledgehammer to catch such problems.
  52. (set! build-things
  53. (λ (store . args)
  54. (display "error: trying to build things during evaluation!~%"
  55. stderr)
  56. (simple-format stderr "'build-things' arguments: ~S~%" args)
  57. (exit 1)))
  58. (parameterize ((%package-database database)
  59. (%use-substitutes? (assoc-ref spec #:use-substitutes?)))
  60. (unless (string-null? guix-package-path)
  61. (set-guix-package-path! guix-package-path))
  62. ;; Call the entry point of FILE and print the resulting job sexp.
  63. (let* ((proc-name (assq-ref spec #:proc))
  64. (proc (module-ref %user-module proc-name))
  65. (thunks (proc store (assq-ref spec #:arguments)))
  66. (db (db-open))
  67. (commit (assq-ref spec #:current-commit))
  68. (eval `((#:specification . ,(assq-ref spec #:name))
  69. (#:revision . ,commit)))
  70. (eval-id (db-add-evaluation db eval)))
  71. (pretty-print
  72. (map (λ (thunk)
  73. (let* ((job (call-with-time-display thunk))
  74. ;; Keep track of SPEC id in the returned jobs.
  75. (job* (acons #:eval-id eval-id job)))
  76. (db-add-derivation db job*)
  77. job*))
  78. thunks)
  79. stdout)
  80. (db-close db))))))
  81. ((command _ ...)
  82. (simple-format (current-error-port) "Usage: ~A FILE
  83. Evaluate the Hydra jobs defined in FILE.~%"
  84. command)
  85. (exit 1))))