Function: comp-run-async-workers
comp-run-async-workers is a byte-compiled function defined in
comp.el.gz.
Signature
(comp-run-async-workers)
Documentation
Start compiling files from comp-files-queue asynchronously.
When compilation is finished, run native-comp-async-all-done-hook and
display a message.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/comp.el.gz
(defun comp-run-async-workers ()
"Start compiling files from `comp-files-queue' asynchronously.
When compilation is finished, run `native-comp-async-all-done-hook' and
display a message."
(if (or comp-files-queue
(> (comp-async-runnings) 0))
(unless (>= (comp-async-runnings) (comp-effective-async-max-jobs))
(cl-loop
for (source-file . load) = (pop comp-files-queue)
while source-file
do (cl-assert (string-match-p comp-valid-source-re source-file) nil
"`comp-files-queue' should be \".el\" files: %s"
source-file)
when (or native-comp-always-compile
load ; Always compile when the compilation is
; commanded for late load.
;; Skip compilation if `comp-el-to-eln-filename' fails
;; to find a writable directory.
(with-demoted-errors "Async compilation :%S"
(file-newer-than-file-p
source-file (comp-el-to-eln-filename source-file))))
do (let* ((expr `((require 'comp)
,(when (boundp 'backtrace-line-length)
`(setf backtrace-line-length ,backtrace-line-length))
(setf comp-file-preloaded-p ,comp-file-preloaded-p
native-compile-target-directory ,native-compile-target-directory
native-comp-speed ,native-comp-speed
native-comp-debug ,native-comp-debug
native-comp-verbose ,native-comp-verbose
comp-libgccjit-reproducer ,comp-libgccjit-reproducer
comp-async-compilation t
native-comp-eln-load-path ',native-comp-eln-load-path
native-comp-compiler-options
',native-comp-compiler-options
native-comp-driver-options
',native-comp-driver-options
load-path ',load-path
warning-fill-column most-positive-fixnum)
,native-comp-async-env-modifier-form
(message "Compiling %s..." ,source-file)
(comp--native-compile ,source-file ,(and load t))))
(source-file1 source-file) ;; Make the closure works :/
(temp-file (make-temp-file
(concat "emacs-async-comp-"
(file-name-base source-file) "-")
nil ".el"))
(expr-strings (let ((print-length nil)
(print-level nil))
(mapcar #'prin1-to-string expr)))
(_ (progn
(with-temp-file temp-file
(mapc #'insert expr-strings))
(comp-log "\n")
(mapc #'comp-log expr-strings)))
(load1 load)
(process (make-process
:name (concat "Compiling: " source-file)
:buffer (with-current-buffer
(get-buffer-create
comp-async-buffer-name)
(setf buffer-read-only t)
(current-buffer))
:command (list
(expand-file-name invocation-name
invocation-directory)
"--batch" "-l" temp-file)
:sentinel
(lambda (process _event)
(run-hook-with-args
'native-comp-async-cu-done-functions
source-file)
(comp-accept-and-process-async-output process)
(ignore-errors (delete-file temp-file))
(let ((eln-file (comp-el-to-eln-filename
source-file1)))
(when (and load1
(zerop (process-exit-status
process))
(file-exists-p eln-file))
(native-elisp-load eln-file
(eq load1 'late))))
(comp-run-async-workers))
:noquery (not native-comp-async-query-on-exit))))
(puthash source-file process comp-async-compilations))
when (>= (comp-async-runnings) (comp-effective-async-max-jobs))
do (cl-return)))
;; No files left to compile and all processes finished.
(run-hooks 'native-comp-async-all-done-hook)
(with-current-buffer (get-buffer-create comp-async-buffer-name)
(save-excursion
(let ((buffer-read-only nil))
(goto-char (point-max))
(insert "Compilation finished.\n"))))
;; `comp-deferred-pending-h' should be empty at this stage.
;; Reset it anyway.
(clrhash comp-deferred-pending-h)))