aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrea Corallo2021-04-04 17:10:08 +0200
committerAndrea Corallo2021-04-04 22:41:17 +0200
commit6f8ec1449197f1fcd730df91dddf6f7750284593 (patch)
treee297436a8b3d8eb2f2dba954180a5f8eec97fc5e /src
parent978afd788fd0496540f715b83f18ed390ca8d5a4 (diff)
downloademacs-6f8ec1449197f1fcd730df91dddf6f7750284593.tar.gz
emacs-6f8ec1449197f1fcd730df91dddf6f7750284593.zip
Output native compiled preloaded files into the 'preloaded' subfolder
* src/comp.c (fixup_eln_load_path): Account the fact that the file can be dumped in the 'preloaded' subfolder. * lisp/loadup.el: Likewise. * src/lread.c (maybe_swap_for_eln1): New function. (maybe_swap_for_eln): Handle 'preloaded' subfolder. * src/Makefile.in (LISP_PRELOADED): Export preloaded files.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in1
-rw-r--r--src/comp.c29
-rw-r--r--src/lread.c73
3 files changed, 70 insertions, 33 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index c6b1f556440..b8bad73b006 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -500,6 +500,7 @@ shortlisp := $(filter-out ${shortlisp_filter},${shortlisp})
500## the critical path (relevant in parallel compilations). 500## the critical path (relevant in parallel compilations).
501## We don't really need to sort, but may as well use it to remove duplicates. 501## We don't really need to sort, but may as well use it to remove duplicates.
502shortlisp := loaddefs.el loadup.el $(sort ${shortlisp}) 502shortlisp := loaddefs.el loadup.el $(sort ${shortlisp})
503export LISP_PRELOADED = ${shortlisp}
503lisp = $(addprefix ${lispsource}/,${shortlisp}) 504lisp = $(addprefix ${lispsource}/,${shortlisp})
504 505
505## Construct full set of libraries to be linked. 506## Construct full set of libraries to be linked.
diff --git a/src/comp.c b/src/comp.c
index 67c8e39315b..9bad9b9667f 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -4091,6 +4091,7 @@ for new compilations.
4091If BASE-DIR is nil use the first entry in `comp-eln-load-path'. */) 4091If BASE-DIR is nil use the first entry in `comp-eln-load-path'. */)
4092 (Lisp_Object filename, Lisp_Object base_dir) 4092 (Lisp_Object filename, Lisp_Object base_dir)
4093{ 4093{
4094 Lisp_Object source_filename = filename;
4094 filename = Fcomp_el_to_eln_rel_filename (filename); 4095 filename = Fcomp_el_to_eln_rel_filename (filename);
4095 4096
4096 /* If base_dir was not specified search inside Vcomp_eln_load_path 4097 /* If base_dir was not specified search inside Vcomp_eln_load_path
@@ -4129,9 +4130,18 @@ If BASE-DIR is nil use the first entry in `comp-eln-load-path'. */)
4129 if (!file_name_absolute_p (SSDATA (base_dir))) 4130 if (!file_name_absolute_p (SSDATA (base_dir)))
4130 base_dir = Fexpand_file_name (base_dir, Vinvocation_directory); 4131 base_dir = Fexpand_file_name (base_dir, Vinvocation_directory);
4131 4132
4132 return Fexpand_file_name (filename, 4133 /* In case the file being compiled is found in 'LISP_PRELOADED'
4133 Fexpand_file_name (Vcomp_native_version_dir, 4134 target for output the 'preloaded' subfolder. */
4134 base_dir)); 4135 Lisp_Object lisp_preloaded =
4136 Fgetenv_internal (build_string ("LISP_PRELOADED"), Qnil);
4137 base_dir = Fexpand_file_name (Vcomp_native_version_dir, base_dir);
4138 if (!NILP (lisp_preloaded)
4139 && !NILP (Fmember (CALL1I (file-name-base, source_filename),
4140 Fmapcar (intern_c_string ("file-name-base"),
4141 CALL1I (split-string, lisp_preloaded)))))
4142 base_dir = Fexpand_file_name (build_string ("preloaded"), base_dir);
4143
4144 return Fexpand_file_name (filename, base_dir);
4135} 4145}
4136 4146
4137DEFUN ("comp--install-trampoline", Fcomp__install_trampoline, 4147DEFUN ("comp--install-trampoline", Fcomp__install_trampoline,
@@ -4750,10 +4760,15 @@ fixup_eln_load_path (Lisp_Object directory)
4750 Lisp_Object eln_cache_sys = 4760 Lisp_Object eln_cache_sys =
4751 Ffile_name_directory (concat2 (Vinvocation_directory, 4761 Ffile_name_directory (concat2 (Vinvocation_directory,
4752 directory)); 4762 directory));
4753 /* One directory up... */ 4763 bool preloaded =
4754 eln_cache_sys = 4764 !NILP (Fequal (Fsubstring (eln_cache_sys, make_fixnum (-10),
4755 Ffile_name_directory (Fsubstring (eln_cache_sys, Qnil, 4765 make_fixnum (-1)),
4756 make_fixnum (-1))); 4766 build_string ("preloaded")));
4767 /* One or two directories up... */
4768 for (int i = 0; i < (preloaded ? 2 : 1); i++)
4769 eln_cache_sys =
4770 Ffile_name_directory (Fsubstring (eln_cache_sys, Qnil,
4771 make_fixnum (-1)));
4757 Fsetcar (last_cell, eln_cache_sys); 4772 Fsetcar (last_cell, eln_cache_sys);
4758} 4773}
4759 4774
diff --git a/src/lread.c b/src/lread.c
index 156df73de82..e53e1f65ab9 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1645,6 +1645,40 @@ directories, make sure the PREDICATE function returns `dir-ok' for them. */)
1645 return file; 1645 return file;
1646} 1646}
1647 1647
1648#ifdef HAVE_NATIVE_COMP
1649static bool
1650maybe_swap_for_eln1 (Lisp_Object src_name, Lisp_Object eln_name,
1651 Lisp_Object *filename, int *fd, struct timespec mtime)
1652{
1653 struct stat eln_st;
1654 int eln_fd = emacs_open (SSDATA (ENCODE_FILE (eln_name)), O_RDONLY, 0);
1655
1656 if (eln_fd > 0)
1657 {
1658 if (fstat (eln_fd, &eln_st) || S_ISDIR (eln_st.st_mode))
1659 emacs_close (eln_fd);
1660 else
1661 {
1662 struct timespec eln_mtime = get_stat_mtime (&eln_st);
1663 if (timespec_cmp (eln_mtime, mtime) >= 0)
1664 {
1665 emacs_close (*fd);
1666 *fd = eln_fd;
1667 *filename = eln_name;
1668 /* Store the eln -> el relation. */
1669 Fputhash (Ffile_name_nondirectory (eln_name),
1670 src_name, Vcomp_eln_to_el_h);
1671 return true;
1672 }
1673 else
1674 emacs_close (eln_fd);
1675 }
1676 }
1677
1678 return false;
1679}
1680#endif
1681
1648/* Look for a suitable .eln file to be loaded in place of FILENAME. 1682/* Look for a suitable .eln file to be loaded in place of FILENAME.
1649 If found replace the content of FILENAME and FD. */ 1683 If found replace the content of FILENAME and FD. */
1650 1684
@@ -1653,7 +1687,6 @@ maybe_swap_for_eln (bool no_native, Lisp_Object *filename, int *fd,
1653 struct timespec mtime) 1687 struct timespec mtime)
1654{ 1688{
1655#ifdef HAVE_NATIVE_COMP 1689#ifdef HAVE_NATIVE_COMP
1656 struct stat eln_st;
1657 1690
1658 if (no_native 1691 if (no_native
1659 || load_no_native) 1692 || load_no_native)
@@ -1687,36 +1720,24 @@ maybe_swap_for_eln (bool no_native, Lisp_Object *filename, int *fd,
1687 } 1720 }
1688 Lisp_Object eln_rel_name = Fcomp_el_to_eln_rel_filename (src_name); 1721 Lisp_Object eln_rel_name = Fcomp_el_to_eln_rel_filename (src_name);
1689 1722
1723 Lisp_Object dir = Qnil;
1690 FOR_EACH_TAIL_SAFE (eln_path_tail) 1724 FOR_EACH_TAIL_SAFE (eln_path_tail)
1691 { 1725 {
1726 dir = XCAR (eln_path_tail);
1692 Lisp_Object eln_name = 1727 Lisp_Object eln_name =
1693 Fexpand_file_name (eln_rel_name, 1728 Fexpand_file_name (eln_rel_name,
1694 Fexpand_file_name (Vcomp_native_version_dir, 1729 Fexpand_file_name (Vcomp_native_version_dir, dir));
1695 XCAR (eln_path_tail))); 1730 if (maybe_swap_for_eln1 (src_name, eln_name, filename, fd, mtime))
1696 int eln_fd = emacs_open (SSDATA (ENCODE_FILE (eln_name)), O_RDONLY, 0); 1731 return;
1697
1698 if (eln_fd > 0)
1699 {
1700 if (fstat (eln_fd, &eln_st) || S_ISDIR (eln_st.st_mode))
1701 emacs_close (eln_fd);
1702 else
1703 {
1704 struct timespec eln_mtime = get_stat_mtime (&eln_st);
1705 if (timespec_cmp (eln_mtime, mtime) >= 0)
1706 {
1707 *filename = eln_name;
1708 emacs_close (*fd);
1709 *fd = eln_fd;
1710 /* Store the eln -> el relation. */
1711 Fputhash (Ffile_name_nondirectory (eln_name),
1712 src_name, Vcomp_eln_to_el_h);
1713 return;
1714 }
1715 else
1716 emacs_close (eln_fd);
1717 }
1718 }
1719 } 1732 }
1733
1734 /* Look also in preloaded subfolder of the last entry in
1735 `comp-eln-load-path'. */
1736 dir = Fexpand_file_name (build_string ("preloaded"),
1737 Fexpand_file_name (Vcomp_native_version_dir,
1738 dir));
1739 maybe_swap_for_eln1 (src_name, Fexpand_file_name (eln_rel_name, dir),
1740 filename, fd, mtime);
1720#endif 1741#endif
1721} 1742}
1722 1743