Function: native--compile-async
native--compile-async is a byte-compiled function defined in
comp.el.gz.
Signature
(native--compile-async FILES &optional RECURSIVELY LOAD SELECTOR)
Documentation
Compile FILES asynchronously.
FILES is one filename or a list of filenames or directories.
If optional argument RECURSIVELY is non-nil, recurse into subdirectories of given directories.
If optional argument LOAD is non-nil, request to load the file after compiling.
The optional argument SELECTOR has the following valid values:
nil -- Select all files. a string -- A regular expression selecting files with matching names. a function -- A function selecting files with matching names.
The variable native-comp-async-jobs-number specifies the number
of (commands) to run simultaneously.
LOAD can also be the symbol late. This is used internally if
the byte code has already been loaded when this function is
called. It means that we request the special kind of load
necessary in that situation, called "late" loading.
During a "late" load, instead of executing all top-level forms of the original files, only function definitions are loaded (paying attention to have these effective only if the bytecode definition was not changed in the meantime).
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/comp.el.gz
(defun native--compile-async (files &optional recursively load selector)
;; BEWARE, this function is also called directly from C.
"Compile FILES asynchronously.
FILES is one filename or a list of filenames or directories.
If optional argument RECURSIVELY is non-nil, recurse into
subdirectories of given directories.
If optional argument LOAD is non-nil, request to load the file
after compiling.
The optional argument SELECTOR has the following valid values:
nil -- Select all files.
a string -- A regular expression selecting files with matching names.
a function -- A function selecting files with matching names.
The variable `native-comp-async-jobs-number' specifies the number
of (commands) to run simultaneously.
LOAD can also be the symbol `late'. This is used internally if
the byte code has already been loaded when this function is
called. It means that we request the special kind of load
necessary in that situation, called \"late\" loading.
During a \"late\" load, instead of executing all top-level forms
of the original files, only function definitions are
loaded (paying attention to have these effective only if the
bytecode definition was not changed in the meantime)."
(comp-ensure-native-compiler)
(unless (member load '(nil t late))
(error "LOAD must be nil, t or 'late"))
(unless (listp files)
(setf files (list files)))
(let ((added-something nil)
file-list)
(dolist (file-or-dir files)
(cond ((file-directory-p file-or-dir)
(dolist (file (if recursively
(directory-files-recursively
file-or-dir comp-valid-source-re)
(directory-files file-or-dir
t comp-valid-source-re)))
(push file file-list)))
((file-exists-p file-or-dir) (push file-or-dir file-list))
(t (signal 'native-compiler-error
(list "Not a file nor directory" file-or-dir)))))
(dolist (file file-list)
(if-let ((entry (cl-find file comp-files-queue :key #'car :test #'string=)))
;; Most likely the byte-compiler has requested a deferred
;; compilation, so update `comp-files-queue' to reflect that.
(unless (or (null load)
(eq load (cdr entry)))
(setf comp-files-queue
(cl-substitute (cons file load) (car entry) comp-files-queue
:key #'car :test #'string=)))
(unless (native-compile-async-skip-p file load selector)
(let* ((out-filename (comp-el-to-eln-filename file))
(out-dir (file-name-directory out-filename)))
(unless (file-exists-p out-dir)
(make-directory out-dir t))
(if (file-writable-p out-filename)
(setf comp-files-queue
(append comp-files-queue `((,file . ,load)))
added-something t)
(display-warning 'comp
(format "No write access for %s skipping."
out-filename)))))))
;; Perhaps nothing passed `native-compile-async-skip-p'?
(when (and added-something
;; Don't start if there's one already running.
(zerop (comp-async-runnings)))
(comp-run-async-workers))))