Subject: 29.0.60; [PATCH] src/comp.c: New variable `comp-el-to-eln-strip-prefix` for `comp-el-to-eln-rel-filename`

From: lin Sun <[email-masked]>
Date: Mon, 3 Apr 2023 00:53:18 +0000

Hi Eli,

Apologize for my wrong comment.
You're right, the patch will allow to relocate/copy an elisp source folder from
/home/userA/.emacs.d/epla/**.el to
/home/userB/.emacs.d/epla/**.el.
So the patch should be the
"0002-New-variable-comp-el-to-eln-strip-prefix-for-comp-el.patch"
attached in this email.

And agree with you, it's dangerous when this variable is configured
with an arbitrary value.
So please feel free to close this ticket. Thanks

Best regards
Lin
From 78cfbda547678a1c655c8c3c06059b6d16696380 Mon Sep 17 00:00:00 2001
From: Lin Sun <[email-masked]>
Date: Sun, 2 Apr 2023 00:00:09 +0000
Subject: [PATCH] New variable `comp-el-to-eln-strip-prefix` for
 `comp-el-to-eln-rel-filename`

* src/comp.c: define the variable `comp-el-to-eln-strip-prefix`
* emacs-lisp/comp.el: forward the variable to native compile workers
---
 lisp/emacs-lisp/comp.el |  1 +
 src/comp.c              | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index e97832455b9..6c9ccb247ca 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -3996,6 +3996,7 @@ comp-run-async-workers
                                              native-comp-driver-options
                                              load-path
                                              backtrace-line-length
+                                             comp-el-to-eln-strip-prefix
                                              ;; package-load-list
                                              ;; package-user-dir
                                              ;; package-directory-list
diff --git a/src/comp.c b/src/comp.c
index 3f72d088a66..d464616ff3e 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -4400,7 +4400,11 @@ DEFUN ("comp-el-to-eln-rel-filename", Fcomp_el_to_eln_rel_filename,
 and Emacs must have been compiled with zlib; the file will be
 uncompressed on the fly to hash its contents.
 Value includes the original base name, followed by 2 hash values,
-one for the file name and another for its contents, followed by .eln.  */)
+one for the file name and another for its contents, followed by .eln.
+
+The file part hash value is generated from the absolute file path, however,
+the absolute path can be stripped with `comp-el-to-eln-strip-prefix' to left
+the significant part for hashing.  */)
   (Lisp_Object filename)
 {
   CHECK_STRING (filename);
@@ -4462,7 +4466,7 @@ DEFUN ("comp-el-to-eln-rel-filename", Fcomp_el_to_eln_rel_filename,
       loadsearch_re_list = list2 (sys_re, Fregexp_quote (dump_load_search));
     }
 
-  Lisp_Object lds_re_tail = loadsearch_re_list;
+  Lisp_Object lds_re_tail = CALLN (Fappend, Vcomp_el_to_eln_strip_prefix, loadsearch_re_list);
   FOR_EACH_TAIL (lds_re_tail)
     {
       Lisp_Object match_idx =
@@ -5864,6 +5868,15 @@ syms_of_comp (void)
      dump reload.  */
   Vnative_comp_eln_load_path = Fcons (build_string ("../native-lisp/"), Qnil);
 
+  DEFVAR_LISP ("comp-el-to-eln-strip-prefix", Vcomp_el_to_eln_strip_prefix,
+    doc: /* List of regex to strip the path prefix in the function
+`comp-el-to-eln-rel-filename'.
+
+When the `comp-el-to-eln-rel-filename' try to convert an <absolute-path>.el
+to eln file name, it will remove the matched prefix on this list and hash
+the rest part to be middle of eln file name, this will allow to relocate the
+*.el source file without rebuild the relative *.eln files.  */);
+
   DEFVAR_LISP ("native-comp-enable-subr-trampolines",
 	       Vnative_comp_enable_subr_trampolines,
     doc: /* If non-nil, enable generation of trampolines for calling primitives.
-- 
2.20.5