Subject: Re: bug#49271: 28.0.50: native-comp: Signing macOS self-contained .app bundle fails due to new *.eln location

From: Alan Third <[email-masked]>
Date: Thu, 1 Jul 2021 19:45:46 +0100

On Thu, Jul 01, 2021 at 10:13:04AM +0300, Eli Zaretskii wrote:
> It should work, although I'd prefer writing such code the other way
> around: first create an uninitialized Lisp string (with
> make_uninit_multibyte_string or make_uninit_string), then copy the
> bytes while making the conversions.  The reason for this preference is
> that you could then make sure the produced string has the same
> multibyte-ness as the original, whereas the way you did it relies on
> whatever build_string decides, which is not necessarily the same.

Thanks. I think the attached is doing what you suggested.
-- 
Alan Third
>From 8de89ce0d2ae7f84ab2df025ae405b15994dfdb6 Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Wed, 30 Jun 2021 19:58:13 +0100
Subject: [PATCH v2] Fix NS self contained eln location (bug#49271)

* Makefile.in:
* configure.ac: Change eln file install location to
Contents/Frameworks.
* src/comp.c (hash_native_abi): Replace dots with underscores in the
eln install location as the macOS code-signing tool won't sign the
files if the parent directories have dots.
---
 Makefile.in  |  2 +-
 configure.ac |  4 ++--
 src/comp.c   | 35 ++++++++++++++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 8fccdf7580..8c14c5cc7d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -333,7 +333,7 @@ BIN_DESTDIR=
 ELN_DESTDIR = $(DESTDIR)${libdir}/emacs/${version}/
 else
 BIN_DESTDIR='${ns_appbindir}/'
-ELN_DESTDIR = ${ns_applibdir}/emacs/${version}/
+ELN_DESTDIR = ${ns_applibdir}/
 endif
 
 all: ${SUBDIR} info
diff --git a/configure.ac b/configure.ac
index 6e2cda947a..c924634d5b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1895,7 +1895,7 @@ AC_DEFUN
      ns_appdir=`pwd`/nextstep/Emacs.app
      ns_appbindir=${ns_appdir}/Contents/MacOS
      ns_applibexecdir=${ns_appdir}/Contents/MacOS/libexec
-     ns_applibdir=${ns_appdir}/Contents/MacOS/lib
+     ns_applibdir=${ns_appdir}/Contents/Frameworks
      ns_appresdir=${ns_appdir}/Contents/Resources
      ns_appsrc=Cocoa/Emacs.base
      ns_fontfile=macfont.o
@@ -1954,7 +1954,7 @@ AC_DEFUN
      ns_appdir=`pwd`/nextstep/Emacs.app
      ns_appbindir=${ns_appdir}
      ns_applibexecdir=${ns_appdir}/libexec
-     ns_applibdir=${ns_appdir}/lib
+     ns_applibdir=${ns_appdir}/Frameworks
      ns_appresdir=${ns_appdir}/Resources
      ns_appsrc=GNUstep/Emacs.base
      ns_fontfile=nsfont.o
diff --git a/src/comp.c b/src/comp.c
index ea05952627..c45f9e3a7f 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -744,8 +744,41 @@ hash_native_abi (void)
 			Vsystem_configuration_options),
 	       Fmapconcat (intern_c_string ("comp--subr-signature"),
 			   Vcomp_subr_list, build_string (""))));
+
+  Lisp_Object version = Vemacs_version;
+
+#ifdef NS_SELF_CONTAINED
+  /* MacOS self contained app bundles do not like having dots in the
+     directory names under the Contents/Frameworks directory, so
+     convert them to underscores.  */
+  unsigned char *to;
+  const unsigned char *from = SDATA (Vemacs_version);
+
+  int multibyte = STRING_MULTIBYTE (Vemacs_version);
+
+  version = multibyte
+    ? make_uninit_multibyte_string (SCHARS (Vemacs_version),
+				    SBYTES (Vemacs_version))
+    : make_uninit_string (SBYTES (Vemacs_version));
+
+  to = SDATA (version);
+
+  while (from < SDATA (Vemacs_version) + SBYTES (Vemacs_version))
+    {
+      int c = multibyte ? string_char_advance (&from) : *from++;
+
+      if (c == '.')
+	c = '_';
+
+      if (multibyte)
+	to += CHAR_STRING (c, to);
+      else
+	*to++ = c;
+    }
+#endif
+
   Vcomp_native_version_dir =
-    concat3 (Vemacs_version, build_string ("-"), Vcomp_abi_hash);
+    concat3 (version, build_string ("-"), Vcomp_abi_hash);
 }
 
 static void
-- 
2.29.2