From 35ad6f52c183f2564d3b09263c7982740a733e34 Mon Sep 17 00:00:00 2001 From: Veselin Dobrev Date: Thu, 23 May 2024 18:17:38 -0700 Subject: [PATCH] Better Emacs build on Mac OS (#37294) * [emacs] When installing on Mac OS, build and install the native Emacs.app along with the standard executables. * [emacs] Make the GUI build on Mac optional by adding "gui" variant * Apply reviewer suggestion Co-authored-by: Alec Scott * Add emacs version 29.3 --------- Co-authored-by: Alec Scott --- .../repos/builtin/packages/emacs/package.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/var/spack/repos/builtin/packages/emacs/package.py b/var/spack/repos/builtin/packages/emacs/package.py index 06044750731..7b5c0493d2d 100644 --- a/var/spack/repos/builtin/packages/emacs/package.py +++ b/var/spack/repos/builtin/packages/emacs/package.py @@ -43,6 +43,7 @@ class Emacs(AutotoolsPackage, GNUMirrorPackage): values=("gtk", "athena"), description="Select an X toolkit (gtk, athena)", ) + variant("gui", default=False, description="Enable GUI build on Mac") variant("tls", default=True, description="Build Emacs with gnutls") variant("native", default=False, when="@28:", description="enable native compilation of elisp") variant("treesitter", default=False, when="@29:", description="Build with tree-sitter support") @@ -91,10 +92,13 @@ def configure_args(self): else: args = ["--without-x"] - # On OS X/macOS, do not build "nextstep/Emacs.app", because - # doing so throws an error at build-time if sys.platform == "darwin": - args.append("--without-ns") + if spec.satisfies("+gui"): + # Do not build the self-contained "nextstep/Emacs.app" + args.append("--disable-ns-self-contained") + else: + # Do not build "nextstep/Emacs.app" at all + args.append("--without-ns") args += self.with_or_without("native-compilation", variant="native") args += self.with_or_without("gnutls", variant="tls") @@ -103,6 +107,15 @@ def configure_args(self): return args + @run_after("install") + def move_macos_app(self): + """Move the Emacs.app build on MacOS to /Applications. + From there users can move it or link it in ~/Applications.""" + if sys.platform == "darwin" and "+gui" in self.spec: + apps_dir = join_path(self.prefix, "Applications") + mkdir(apps_dir) + move("nextstep/Emacs.app", apps_dir) + def run_version_check(self, bin): """Runs and checks output of the installed binary.""" exe_path = join_path(self.prefix.bin, bin)