compile-all.scm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
  3. ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  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. (use-modules (ice-9 match)
  20. (ice-9 threads)
  21. (srfi srfi-1)
  22. (guix build compile)
  23. (guix build utils))
  24. (define host (getenv "host"))
  25. (define srcdir (getenv "srcdir"))
  26. (define (relative-file file)
  27. (if (string-prefix? (string-append srcdir "/") file)
  28. (string-drop file (+ 1 (string-length srcdir)))
  29. file))
  30. (define (file-mtime<? f1 f2)
  31. (< (stat:mtime (stat f1))
  32. (stat:mtime (stat f2))))
  33. (define (scm->go file)
  34. (let* ((relative (relative-file file))
  35. (without-extension (string-drop-right relative 4)))
  36. (string-append without-extension ".go")))
  37. (define (file-needs-compilation? file)
  38. (let ((go (scm->go file)))
  39. (or (not (file-exists? go))
  40. (file-mtime<? go file))))
  41. (define* (parallel-job-count #:optional (flags (getenv "MAKEFLAGS")))
  42. "Return the number of parallel jobs as determined by FLAGS, the flags passed
  43. to 'make'."
  44. (match flags
  45. (#f (current-processor-count))
  46. (flags
  47. (let ((initial-flags (string-tokenize flags)))
  48. (let loop ((flags initial-flags))
  49. (match flags
  50. (()
  51. ;; Note: GNU make prior to version 4.2 would hide "-j" flags from
  52. ;; $MAKEFLAGS. Thus, check for a "--jobserver" flag here and
  53. ;; assume we're using all cores if specified.
  54. (if (any (lambda (flag)
  55. (string-prefix? "--jobserver" flag))
  56. initial-flags)
  57. (current-processor-count) ;GNU make < 4.2
  58. 1)) ;sequential make
  59. (("-j" (= string->number count) _ ...)
  60. (if (integer? count)
  61. count
  62. (current-processor-count)))
  63. ((head tail ...)
  64. (if (string-prefix? "-j" head)
  65. (match (string-drop head 2)
  66. (""
  67. (current-processor-count))
  68. ((= string->number count)
  69. (if (integer? count)
  70. count
  71. (current-processor-count))))
  72. (loop tail)))))))))
  73. ;; Install a SIGINT handler to give unwind handlers in 'compile-file' an
  74. ;; opportunity to run upon SIGINT and to remove temporary output files.
  75. (sigaction SIGINT
  76. (lambda args
  77. (exit 1)))
  78. (match (command-line)
  79. ((_ . files)
  80. (compile-files srcdir (getcwd)
  81. (filter file-needs-compilation? files)
  82. #:workers (parallel-job-count)
  83. #:host host
  84. #:report-load (lambda (file total completed)
  85. (when file
  86. (format #t " LOAD ~a~%" file)
  87. (force-output)))
  88. #:report-compilation (lambda (file total completed)
  89. (when file
  90. (format #t " GUILEC ~a~%"
  91. (scm->go file))
  92. (force-output))))))