From 23b8236e0a66fb09810e8422bedf02f7192a53e4 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 29 Jun 2021 01:27:16 +0100 Subject: [PATCH] fix(native_comp): patch Emacs.pdmp for customized native-lisp paths In my initial testing without full native-comp AoT, Emacs seemed to somehow launch fine. But with a AoT build it complains that it can't find *.eln files in the original paths that contained dots. But since we have to customize those folder names removing the dots to make Apple's codesign happy, we also need to update Emacs.pdmp too. --- build-emacs-for-macos | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/build-emacs-for-macos b/build-emacs-for-macos index 7d6fcac..bad506f 100755 --- a/build-emacs-for-macos +++ b/build-emacs-for-macos @@ -454,6 +454,13 @@ class Build parent = File.dirname(parent) end + eln_parts = eln_dir.match( + %r{/(\d+\.\d+\.\d+)/native-lisp/(\d+\.\d+\.\d+-\w+)(?:/.+)?$}i + ) + if eln_parts + patch_dump_native_lisp_paths(app, eln_parts[1], eln_parts[2]) + end + # Find native-lisp directory again after it has been renamed. source = Dir['MacOS/libexec/emacs/**/eln-cache', 'MacOS/lib/emacs/**/native-lisp'].first @@ -468,6 +475,29 @@ class Build end end + def patch_dump_native_lisp_paths(app, emacs_version, eln_version) + sanitized_emacs_version = emacs_version.gsub('.', '-') + sanitized_eln_version = eln_version.gsub('.', '-') + + contents_dir = File.join(app, 'Contents') + FileUtils.cd(contents_dir) do + filename = Dir['MacOS/Emacs.pdmp', 'MacOS/libexec/Emacs.pdmp'].first + err "no Emacs.pdmp file found in #{app}" unless filename + info 'patching Emacs.pdmp to point at new native-lisp paths' + + content = File.read(filename, mode: 'rb').gsub( + "lib/emacs/#{emacs_version}/native-lisp/#{eln_version}/", + "lib/emacs/#{sanitized_emacs_version}/" \ + "native-lisp/#{sanitized_eln_version}/" + ).gsub( + "../native-lisp/#{eln_version}/", + "../native-lisp/#{sanitized_eln_version}/" + ) + + File.open(filename, 'w') { |f| f.write(content) } + end + end + def add_cli_helper(app) source = File.join(__dir__, 'helper', 'emacs-cli.bash') target = File.join(app, 'Contents', 'MacOS', 'bin', 'emacs')