(when (subr-native-elisp-p f)
(puthash (subr-native-comp-unit f) nil h)))))
(maphash (lambda (cu _)
- (native-comp-unit-set-file
- cu
- (cons
- ;; Relative filename from the installed binary.
- (file-relative-name (concat eln-dest-dir
- (file-name-nondirectory
- (native-comp-unit-file cu)))
- bin-dest-dir)
- ;; Relative filename from the built uninstalled binary.
- (file-relative-name (native-comp-unit-file cu)
- invocation-directory))))
+ (let* ((file (native-comp-unit-file cu))
+ (preloaded (equal (substring (file-name-directory file)
+ -10 -1)
+ "preloaded"))
+ (eln-dest-dir-eff (if preloaded
+ (expand-file-name "preloaded"
+ eln-dest-dir)
+ eln-dest-dir)))
+ (native-comp-unit-set-file
+ cu
+ (cons
+ ;; Relative filename from the installed binary.
+ (file-relative-name (expand-file-name
+ (file-name-nondirectory
+ file)
+ eln-dest-dir-eff)
+ bin-dest-dir)
+ ;; Relative filename from the built uninstalled binary.
+ (file-relative-name file invocation-directory)))))
h))))
(when (hash-table-p purify-flag)
## the critical path (relevant in parallel compilations).
## We don't really need to sort, but may as well use it to remove duplicates.
shortlisp := loaddefs.el loadup.el $(sort ${shortlisp})
+export LISP_PRELOADED = ${shortlisp}
lisp = $(addprefix ${lispsource}/,${shortlisp})
## Construct full set of libraries to be linked.
If BASE-DIR is nil use the first entry in `comp-eln-load-path'. */)
(Lisp_Object filename, Lisp_Object base_dir)
{
+ Lisp_Object source_filename = filename;
filename = Fcomp_el_to_eln_rel_filename (filename);
/* If base_dir was not specified search inside Vcomp_eln_load_path
if (!file_name_absolute_p (SSDATA (base_dir)))
base_dir = Fexpand_file_name (base_dir, Vinvocation_directory);
- return Fexpand_file_name (filename,
- Fexpand_file_name (Vcomp_native_version_dir,
- base_dir));
+ /* In case the file being compiled is found in 'LISP_PRELOADED'
+ target for output the 'preloaded' subfolder. */
+ Lisp_Object lisp_preloaded =
+ Fgetenv_internal (build_string ("LISP_PRELOADED"), Qnil);
+ base_dir = Fexpand_file_name (Vcomp_native_version_dir, base_dir);
+ if (!NILP (lisp_preloaded)
+ && !NILP (Fmember (CALL1I (file-name-base, source_filename),
+ Fmapcar (intern_c_string ("file-name-base"),
+ CALL1I (split-string, lisp_preloaded)))))
+ base_dir = Fexpand_file_name (build_string ("preloaded"), base_dir);
+
+ return Fexpand_file_name (filename, base_dir);
}
DEFUN ("comp--install-trampoline", Fcomp__install_trampoline,
Lisp_Object eln_cache_sys =
Ffile_name_directory (concat2 (Vinvocation_directory,
directory));
- /* One directory up... */
- eln_cache_sys =
- Ffile_name_directory (Fsubstring (eln_cache_sys, Qnil,
- make_fixnum (-1)));
+ bool preloaded =
+ !NILP (Fequal (Fsubstring (eln_cache_sys, make_fixnum (-10),
+ make_fixnum (-1)),
+ build_string ("preloaded")));
+ /* One or two directories up... */
+ for (int i = 0; i < (preloaded ? 2 : 1); i++)
+ eln_cache_sys =
+ Ffile_name_directory (Fsubstring (eln_cache_sys, Qnil,
+ make_fixnum (-1)));
Fsetcar (last_cell, eln_cache_sys);
}
return file;
}
+#ifdef HAVE_NATIVE_COMP
+static bool
+maybe_swap_for_eln1 (Lisp_Object src_name, Lisp_Object eln_name,
+ Lisp_Object *filename, int *fd, struct timespec mtime)
+{
+ struct stat eln_st;
+ int eln_fd = emacs_open (SSDATA (ENCODE_FILE (eln_name)), O_RDONLY, 0);
+
+ if (eln_fd > 0)
+ {
+ if (fstat (eln_fd, &eln_st) || S_ISDIR (eln_st.st_mode))
+ emacs_close (eln_fd);
+ else
+ {
+ struct timespec eln_mtime = get_stat_mtime (&eln_st);
+ if (timespec_cmp (eln_mtime, mtime) >= 0)
+ {
+ emacs_close (*fd);
+ *fd = eln_fd;
+ *filename = eln_name;
+ /* Store the eln -> el relation. */
+ Fputhash (Ffile_name_nondirectory (eln_name),
+ src_name, Vcomp_eln_to_el_h);
+ return true;
+ }
+ else
+ emacs_close (eln_fd);
+ }
+ }
+
+ return false;
+}
+#endif
+
/* Look for a suitable .eln file to be loaded in place of FILENAME.
If found replace the content of FILENAME and FD. */
struct timespec mtime)
{
#ifdef HAVE_NATIVE_COMP
- struct stat eln_st;
if (no_native
|| load_no_native)
}
Lisp_Object eln_rel_name = Fcomp_el_to_eln_rel_filename (src_name);
+ Lisp_Object dir = Qnil;
FOR_EACH_TAIL_SAFE (eln_path_tail)
{
+ dir = XCAR (eln_path_tail);
Lisp_Object eln_name =
Fexpand_file_name (eln_rel_name,
- Fexpand_file_name (Vcomp_native_version_dir,
- XCAR (eln_path_tail)));
- int eln_fd = emacs_open (SSDATA (ENCODE_FILE (eln_name)), O_RDONLY, 0);
-
- if (eln_fd > 0)
- {
- if (fstat (eln_fd, &eln_st) || S_ISDIR (eln_st.st_mode))
- emacs_close (eln_fd);
- else
- {
- struct timespec eln_mtime = get_stat_mtime (&eln_st);
- if (timespec_cmp (eln_mtime, mtime) >= 0)
- {
- *filename = eln_name;
- emacs_close (*fd);
- *fd = eln_fd;
- /* Store the eln -> el relation. */
- Fputhash (Ffile_name_nondirectory (eln_name),
- src_name, Vcomp_eln_to_el_h);
- return;
- }
- else
- emacs_close (eln_fd);
- }
- }
+ Fexpand_file_name (Vcomp_native_version_dir, dir));
+ if (maybe_swap_for_eln1 (src_name, eln_name, filename, fd, mtime))
+ return;
}
+
+ /* Look also in preloaded subfolder of the last entry in
+ `comp-eln-load-path'. */
+ dir = Fexpand_file_name (build_string ("preloaded"),
+ Fexpand_file_name (Vcomp_native_version_dir,
+ dir));
+ maybe_swap_for_eln1 (src_name, Fexpand_file_name (eln_rel_name, dir),
+ filename, fd, mtime);
#endif
}