diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 3b07e0a71a..2cdc2f83aa 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -87,7 +87,11 @@ module SharedEnvExtension # Is the formula struggling to find the pkgconfig file? Point it to it. # This is done automatically for `keg_only` formulae. #
ENV.prepend_path "PKG_CONFIG_PATH", "#{Formula["glib"].opt_lib}/pkgconfig"
+ # Prepending a system path such as /usr/bin is a no-op so that requirements
+ # don't accidentally override superenv shims or formulae's `bin` directories
+ # (e.g. ENV.prepend_path "PATH", which("emacs").dirname)
def prepend_path(key, path)
+ return if %w[/usr/bin /bin /usr/sbin /sbin].include? path.to_s
prepend key, path, File::PATH_SEPARATOR if File.directory? path
end
diff --git a/Library/Homebrew/test/ENV_spec.rb b/Library/Homebrew/test/ENV_spec.rb
index 7b50ca1d4a..07f6cdb6b0 100644
--- a/Library/Homebrew/test/ENV_spec.rb
+++ b/Library/Homebrew/test/ENV_spec.rb
@@ -115,11 +115,11 @@ shared_examples EnvActivation do
describe "#prepend_path" do
it "prepends to a path" do
- subject.prepend_path "FOO", "/usr/bin"
- expect(subject["FOO"]).to eq("/usr/bin")
+ subject.prepend_path "FOO", "/usr/libexec"
+ expect(subject["FOO"]).to eq("/usr/libexec")
- subject.prepend_path "FOO", "/bin"
- expect(subject["FOO"]).to eq("/bin#{File::PATH_SEPARATOR}/usr/bin")
+ subject.prepend_path "FOO", "/usr"
+ expect(subject["FOO"]).to eq("/usr#{File::PATH_SEPARATOR}/usr/libexec")
end
end