Skip to content

Commit

Permalink
feat: roll back to superenv yet keep path injection
Browse files Browse the repository at this point in the history
It turns out all these tricks we are doing with path are not needed as there is a way to access original path via
`ORIGINAL_PATHS` variable. This means that we can keep the stable super env while still injecting path.
  • Loading branch information
d12frosted committed Aug 25, 2024
1 parent 0aeb4b2 commit a5ccb0d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 138 deletions.
18 changes: 0 additions & 18 deletions Formula/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class EmacsPlusAT28 < EmacsBase
mirror "https://ftpmirror.gnu.org/emacs/emacs-28.2.tar.xz"
sha256 "ee21182233ef3232dc97b486af2d86e14042dbb65bbc535df562c3a858232488"

on_macos do
env :std
end

desc "GNU Emacs text editor"
homepage "https://www.gnu.org/software/emacs/"

Expand Down Expand Up @@ -102,22 +98,11 @@ class EmacsPlusAT28 < EmacsBase
local_patch "fix-window-role", sha: "1f8423ea7e6e66c9ac6dd8e37b119972daa1264de00172a24a79a710efcb8130"
local_patch "system-appearance", sha: "d6ee159839b38b6af539d7b9bdff231263e451c1fd42eec0d125318c9db8cd92"

#
# Initialize
#
def initialize(*args, **kwargs, &block)
a = super
expand_env
a
end

#
# Install
#

def install
expand_env

args = %W[
--disable-dependency-tracking
--disable-silent-rules
Expand Down Expand Up @@ -167,9 +152,6 @@ def install
args << "--without-pop" if build.with? "mailutils"
args << "--with-xwidgets" if build.with? "xwidgets"

ENV.prepend_path "PATH", Formula["gnu-sed"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["gnu-tar"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["grep"].opt_libexec/"gnubin"
system "./autogen.sh"

if (build.with? "cocoa") && (build.without? "x11")
Expand Down
18 changes: 0 additions & 18 deletions Formula/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class EmacsPlusAT29 < EmacsBase
mirror "https://ftpmirror.gnu.org/emacs/emacs-29.4.tar.xz"
sha256 "ba897946f94c36600a7e7bb3501d27aa4112d791bfe1445c61ed28550daca235"

on_macos do
env :std
end

desc "GNU Emacs text editor"
homepage "https://www.gnu.org/software/emacs/"

Expand Down Expand Up @@ -97,22 +93,11 @@ class EmacsPlusAT29 < EmacsBase
local_patch "poll", sha: "052eacac5b7bd86b466f9a3d18bff9357f2b97517f463a09e4c51255bdb14648" if build.with? "poll"
local_patch "round-undecorated-frame", sha: "7451f80f559840e54e6a052e55d1100778abc55f98f1d0c038a24e25773f2874"

#
# Initialize
#
def initialize(*args, **kwargs, &block)
a = super
expand_env
a
end

#
# Install
#

def install
expand_env

args = %W[
--disable-dependency-tracking
--disable-silent-rules
Expand Down Expand Up @@ -163,9 +148,6 @@ def install
args << "--without-pop" if build.with? "mailutils"
args << "--with-xwidgets" if build.with? "xwidgets"

ENV.prepend_path "PATH", Formula["gnu-sed"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["gnu-tar"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["grep"].opt_libexec/"gnubin"
system "./autogen.sh"

if (build.with? "cocoa") && (build.without? "x11")
Expand Down
28 changes: 1 addition & 27 deletions Formula/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class EmacsPlusAT30 < EmacsBase

# Opt-out
option "without-cocoa", "Build a non-Cocoa version of Emacs"
option "without-path-injection", "Build without path injection in isolated environment"

# Opt-in
option "with-ctags", "Don't remove the ctags executable that Emacs provides"
Expand Down Expand Up @@ -73,14 +72,6 @@ class EmacsPlusAT30 < EmacsBase
end
end

#
# Environment
#

on_macos do
env :std if build.with? "path-injection"
end

#
# URL
#
Expand All @@ -107,25 +98,11 @@ class EmacsPlusAT30 < EmacsBase
local_patch "poll", sha: "59e876f82e6fd8e4583bc2456339eda4f989c86b1e16a02b0726702e95f60825" if build.with? "poll"
local_patch "round-undecorated-frame", sha: "7451f80f559840e54e6a052e55d1100778abc55f98f1d0c038a24e25773f2874"

#
# Initialize
#
def initialize(*args, **kwargs, &block)
a = super
print_env if verbose?
expand_env if build.with? "path-injection"
print_env if verbose?
a
end

#
# Install
#

def install
expand_env if build.with? "path-injection"
print_env if verbose?

args = %W[
--disable-dependency-tracking
--disable-silent-rules
Expand Down Expand Up @@ -186,9 +163,6 @@ def install
args << "--without-pop" if build.with? "mailutils"
args << "--with-xwidgets" if build.with? "xwidgets"

ENV.prepend_path "PATH", Formula["gnu-sed"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["gnu-tar"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["grep"].opt_libexec/"gnubin"
system "./autogen.sh"

if (build.with? "cocoa") && (build.without? "x11")
Expand Down Expand Up @@ -228,7 +202,7 @@ def install
(prefix/"Emacs.app/Contents").install "native-lisp" if build.with? "native-comp"

# inject PATH to Info.plist
inject_path if build.with? "path-injection"
inject_path

# inject description for protected resources usage
inject_protected_resources_usage_desc
Expand Down
30 changes: 1 addition & 29 deletions Formula/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class EmacsPlusAT31 < EmacsBase

# Opt-out
option "without-cocoa", "Build a non-Cocoa version of Emacs"
option "without-path-injection", "Build without path injection in isolated environment"

# Opt-in
option "with-ctags", "Don't remove the ctags executable that Emacs provides"
Expand Down Expand Up @@ -73,14 +72,6 @@ class EmacsPlusAT31 < EmacsBase
end
end

#
# Environment
#

on_macos do
env :std if build.with? "path-injection"
end

#
# URL
#
Expand All @@ -107,25 +98,11 @@ class EmacsPlusAT31 < EmacsBase
local_patch "poll", sha: "59e876f82e6fd8e4583bc2456339eda4f989c86b1e16a02b0726702e95f60825" if build.with? "poll"
local_patch "round-undecorated-frame", sha: "7451f80f559840e54e6a052e55d1100778abc55f98f1d0c038a24e25773f2874"

#
# Initialize
#
def initialize(*args, **kwargs, &block)
a = super
print_env if verbose?
expand_env if build.with? "path-injection"
print_env if verbose?
a
end

#
# Install
#

def install
expand_env if build.with? "path-injection"
print_env if verbose?

args = %W[
--disable-dependency-tracking
--disable-silent-rules
Expand Down Expand Up @@ -157,8 +134,6 @@ def install
ENV.append "LDFLAGS", "-I#{Formula["libgccjit"].include}"
end

print_env if verbose?

args <<
if build.with? "dbus"
"--with-dbus"
Expand Down Expand Up @@ -188,9 +163,6 @@ def install
args << "--without-pop" if build.with? "mailutils"
args << "--with-xwidgets" if build.with? "xwidgets"

ENV.prepend_path "PATH", Formula["gnu-sed"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["gnu-tar"].opt_libexec/"gnubin"
ENV.prepend_path "PATH", Formula["grep"].opt_libexec/"gnubin"
system "./autogen.sh"

if (build.with? "cocoa") && (build.without? "x11")
Expand Down Expand Up @@ -230,7 +202,7 @@ def install
(prefix/"Emacs.app/Contents").install "native-lisp" if build.with? "native-comp"

# inject PATH to Info.plist
inject_path if build.with? "path-injection"
inject_path

# inject description for protected resources usage
inject_protected_resources_usage_desc
Expand Down
68 changes: 22 additions & 46 deletions Library/EmacsBase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,7 @@ def inject_path
ohai "Injecting PATH value to Emacs.app/Contents/Info.plist"
app = "#{prefix}/Emacs.app"
plist = "#{app}/Contents/Info.plist"
path_full = PATH.new(ENV['PATH'])

if verbose?
puts "Full PATH, including entries required for build: #{path_full}"
end

# drop shared shims
shared_idx = path_full.find_index { |x|
x.end_with? "/Library/Homebrew/shims/shared"
}
if shared_idx
path = PATH.new(path_full.drop(shared_idx + 1))
end

# drop super shims
super_idx = path_full.find_index { |x|
x.end_with? "/Library/Homebrew/shims/mac/super"
}
if super_idx
path = PATH.new(path_full.drop(super_idx + 1))
end
path = PATH.new(ORIGINAL_PATHS)

puts "Patching plist at #{plist} with following PATH value:"
path.each_entry { |x|
Expand All @@ -68,32 +48,28 @@ def inject_path
system "touch '#{app}'"
end

def expand_env
# Expand PATH to include all dependencies and Superenv.bin as
# dependencies can override standard tools.
path = PATH.new()
on_macos do
path.append("#{ENV['HOMEBREW_PREFIX']}/Library/Homebrew/shims/mac/super")
end
# path.append(deps.map { |dep| dep.to_formula.libexec/"gnubin" })
path.append(deps.map { |dep| dep.to_formula.opt_bin })
path.append(ENV['PATH'])
ENV['PATH'] = path.existing

if verbose?
print_env
system "which", "tar"
system "which", "ls"
system "which", "grep"
end
end

def print_env
path = PATH.new()
path.append(ENV['PATH'])
puts "PATH value is"
path.each_entry { |x|
puts " - #{x}"
ohai "Environment"
["CC",
"CXX",
"OBJC",
"OBJCXX",
"CFLAGS",
"CXXFLAGS",
"CPPFLAGS",
"LDFLAGS",
"SDKROOT",
"MAKEFLAGS",
"CMAKE_PREFIX_PATH",
"CMAKE_FRAMEWORK_PATH",
"PKG_CONFIG_PATH",
"PKG_CONFIG_LIBDIR",
"HOMEBREW_GIT",
"ACLOCAL_PATH",
"PATH",
"CPATH",
].each { |key|
puts "#{key}: #{ENV[key]}"
}
end

Expand Down

0 comments on commit a5ccb0d

Please sign in to comment.