fix(codesign): prevent "bundle format unrecognized" error from codesign

Apple's codesign CLI toolthrows a "bundle format unrecognized" error if
there are any folders within the application that contain two dots in
their name.

Hence we need to get rid of the one instance of that we end up with from
GCC, and update the native-comp patch accordingly.

As of writing, this means renaming:
Emacs.app/Contents/MacOS/lib/gcc/11/gcc/x86_64-apple-darwin20/11.1.0

To:
Emacs.app/Contents/MacOS/lib/gcc/11/gcc/x86_64-apple-darwin20/11
This commit is contained in:
2021-05-20 01:50:56 +01:00
parent bb45cda023
commit 7259111478
2 changed files with 32 additions and 10 deletions

View File

@@ -713,7 +713,9 @@ class GccLibEmbedder < AbstractEmbedder
FileUtils.mkdir_p(File.dirname(target_dir))
FileUtils.cp_r(source_dir, target_dir)
FileUtils.rm(Dir[File.join(target_dir, '**/.DS_Store')], force: true)
FileUtils.rm(Dir[File.join(target_dir, '**', '.DS_Store')], force: true)
FileUtils.chmod_R('u+w', target_dir)
FileUtils.mv(source_darwin_dir, target_darwin_dir)
end
private
@@ -726,9 +728,21 @@ class GccLibEmbedder < AbstractEmbedder
File.join(invocation_dir, gcc_info.relative_lib_dir)
end
def source_darwin_dir
File.join(invocation_dir, gcc_info.relative_darwin_lib_dir)
end
def target_darwin_dir
File.join(invocation_dir, gcc_info.sanitized_relative_darwin_lib_dir)
end
def source_dir
gcc_info.lib_dir
end
def relative_dir(path, root)
Pathname.new(path).relative_path_from(Pathname.new(root)).to_s
end
end
class GccInfo
@@ -768,6 +782,17 @@ class GccInfo
@relative_darwin_lib_dir ||= relative_dir(darwin_lib_dir, root_dir)
end
# Sanitize folder name with full "MAJOR.MINOR.PATCH" version number to just
# the MAJOR version. Apple's codesign CLI tool throws a "bundle format
# unrecognized" error if there are any folders with two dots in their name
# within the Emacs.app application bundle.
def sanitized_relative_darwin_lib_dir
@sanitized_relative_darwin_lib_dir ||= File.join(
File.dirname(relative_darwin_lib_dir),
File.basename(relative_darwin_lib_dir).split('.').first
)
end
def libgccjit_root_dir
@libgccjit_root_dir ||= `brew --prefix libgccjit`.chomp
end
@@ -812,10 +837,7 @@ class GccInfo
private
def relative_dir(path, root)
root += '/' unless root[-1] == '/'
return if path[0..root.size - 1] != root
path[root.size..-1]
Pathname.new(path).relative_path_from(Pathname.new(root)).to_s
end
end

View File

@@ -1,10 +1,10 @@
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 4036080976..2ff8dbd74c 100644
index 8c638312b0..87af889ef4 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -4079,6 +4079,52 @@ of (commands) to run simultaneously."
@@ -4215,6 +4215,52 @@ native-compile-async
(let ((load (not (not load))))
(native--compile-async paths recursively load selector)))
(native--compile-async files recursively load selector)))
+;;;###autoload
+(defun native-compile-setup-environment-variables (&rest _args)
@@ -19,7 +19,7 @@ index 4036080976..2ff8dbd74c 100644
+ "<%= relative_lib_dir %>"
+ invocation-directory))
+ (darwin-dir (expand-file-name
+ "<%= relative_darwin_lib_dir %>"
+ "<%= sanitized_relative_darwin_lib_dir %>"
+ invocation-directory))
+ (lib-paths (list)))
+
@@ -54,4 +54,4 @@ index 4036080976..2ff8dbd74c 100644
+
(provide 'comp)
;;; comp.el ends here
;; LocalWords: limplified limplified limplification limplify Limple LIMPLE libgccjit elc eln