Merge pull request #4557 from MikeMcQuaid/no-link-caveats-output
link: when refusing to link display keg only caveats instead.
This commit is contained in:
commit
5d4adead0b
@ -30,6 +30,64 @@ class Caveats
|
||||
|
||||
delegate [:empty?, :to_s] => :caveats
|
||||
|
||||
def keg_only_text(skip_reason: false)
|
||||
return unless f.keg_only?
|
||||
|
||||
s = if skip_reason
|
||||
""
|
||||
else
|
||||
<<~EOS
|
||||
#{f.name} is keg-only, which means it was not symlinked into #{HOMEBREW_PREFIX},
|
||||
because #{f.keg_only_reason.to_s.chomp}.
|
||||
EOS
|
||||
end
|
||||
|
||||
if f.bin.directory? || f.sbin.directory?
|
||||
s << <<~EOS
|
||||
|
||||
If you need to have #{f.name} first in your PATH run:
|
||||
EOS
|
||||
if f.bin.directory?
|
||||
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_bin.to_s)}\n"
|
||||
end
|
||||
if f.sbin.directory?
|
||||
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_sbin.to_s)}\n"
|
||||
end
|
||||
end
|
||||
|
||||
if f.lib.directory? || f.include.directory?
|
||||
s << <<~EOS
|
||||
|
||||
For compilers to find #{f.name} you may need to set:
|
||||
EOS
|
||||
|
||||
if f.lib.directory?
|
||||
s << " #{Utils::Shell.export_value("LDFLAGS", "-L#{f.opt_lib}")}\n"
|
||||
end
|
||||
|
||||
if f.include.directory?
|
||||
s << " #{Utils::Shell.export_value("CPPFLAGS", "-I#{f.opt_include}")}\n"
|
||||
end
|
||||
|
||||
if which("pkg-config", ENV["HOMEBREW_PATH"]) &&
|
||||
((f.lib/"pkgconfig").directory? || (f.share/"pkgconfig").directory?)
|
||||
s << <<~EOS
|
||||
|
||||
For pkg-config to find #{f.name} you may need to set:
|
||||
EOS
|
||||
|
||||
if (f.lib/"pkgconfig").directory?
|
||||
s << " #{Utils::Shell.export_value("PKG_CONFIG_PATH", "#{f.opt_lib}/pkgconfig")}\n"
|
||||
end
|
||||
|
||||
if (f.share/"pkgconfig").directory?
|
||||
s << " #{Utils::Shell.export_value("PKG_CONFIG_PATH", "#{f.opt_share}/pkgconfig")}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
s << "\n"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def keg
|
||||
@ -42,37 +100,6 @@ class Caveats
|
||||
end.compact.first
|
||||
end
|
||||
|
||||
def keg_only_text
|
||||
return unless f.keg_only?
|
||||
|
||||
s = <<~EOS
|
||||
This formula is keg-only, which means it was not symlinked into #{HOMEBREW_PREFIX},
|
||||
because #{f.keg_only_reason.to_s.chomp}.
|
||||
EOS
|
||||
if f.bin.directory? || f.sbin.directory?
|
||||
s << "\nIf you need to have this software first in your PATH run:\n"
|
||||
if f.bin.directory?
|
||||
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_bin.to_s)}\n"
|
||||
end
|
||||
if f.sbin.directory?
|
||||
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_sbin.to_s)}\n"
|
||||
end
|
||||
end
|
||||
|
||||
if f.lib.directory? || f.include.directory?
|
||||
s << "\nFor compilers to find this software you may need to set:\n"
|
||||
s << " LDFLAGS: -L#{f.opt_lib}\n" if f.lib.directory?
|
||||
s << " CPPFLAGS: -I#{f.opt_include}\n" if f.include.directory?
|
||||
if which("pkg-config", ENV["HOMEBREW_PATH"]) &&
|
||||
((f.lib/"pkgconfig").directory? || (f.share/"pkgconfig").directory?)
|
||||
s << "For pkg-config to find this software you may need to set:\n"
|
||||
s << " PKG_CONFIG_PATH: #{f.opt_lib}/pkgconfig\n" if (f.lib/"pkgconfig").directory?
|
||||
s << " PKG_CONFIG_PATH: #{f.opt_share}/pkgconfig\n" if (f.share/"pkgconfig").directory?
|
||||
end
|
||||
end
|
||||
s << "\n"
|
||||
end
|
||||
|
||||
def function_completion_caveats(shell)
|
||||
return unless keg
|
||||
return unless which(shell.to_s, ENV["HOMEBREW_PATH"])
|
||||
|
||||
@ -37,7 +37,9 @@ module Homebrew
|
||||
if shell.nil?
|
||||
dump_build_env ENV
|
||||
else
|
||||
env_keys.each { |key| puts Utils::Shell.export_value(shell, key, ENV[key]) }
|
||||
env_keys.each do |key|
|
||||
puts Utils::Shell.export_value(key, ENV[key], shell)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#: If `--force` (or `-f`) is passed, Homebrew will allow keg-only formulae to be linked.
|
||||
|
||||
require "ostruct"
|
||||
require "caveats"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
@ -52,14 +53,16 @@ module Homebrew
|
||||
|
||||
if keg_only
|
||||
if HOMEBREW_PREFIX.to_s == "/usr/local"
|
||||
if keg.to_formula.keg_only_reason.reason == :provided_by_macos &&
|
||||
f = keg.to_formula
|
||||
caveats = Caveats.new(f)
|
||||
|
||||
if f.keg_only_reason.reason == :provided_by_macos &&
|
||||
(MacOS.version >= :mojave ||
|
||||
MacOS::Xcode.version >= "10.0" ||
|
||||
MacOS::CLT.version >= "10.0")
|
||||
opoo <<~EOS
|
||||
Refusing to link macOS-provided software: #{keg.name}
|
||||
Instead, pass the full include/library paths to your compiler e.g.:
|
||||
-I#{HOMEBREW_PREFIX}/opt/#{keg.name}/include -L#{HOMEBREW_PREFIX}/opt/#{keg.name}/lib
|
||||
#{caveats.keg_only_text(skip_reason: true).strip}
|
||||
EOS
|
||||
next
|
||||
end
|
||||
@ -69,8 +72,7 @@ module Homebrew
|
||||
Refusing to link: #{keg.name}
|
||||
Linking keg-only #{keg.name} means you may end up linking against the insecure,
|
||||
deprecated system OpenSSL while using the headers from Homebrew's #{keg.name}.
|
||||
Instead, pass the full include/library paths to your compiler e.g.:
|
||||
-I#{HOMEBREW_PREFIX}/opt/#{keg.name}/include -L#{HOMEBREW_PREFIX}/opt/#{keg.name}/lib
|
||||
#{caveats.keg_only_text(skip_reason: true).strip}
|
||||
EOS
|
||||
next
|
||||
end
|
||||
|
||||
@ -21,7 +21,7 @@ module Utils
|
||||
end
|
||||
|
||||
# quote values. quoting keys is overkill
|
||||
def export_value(shell, key, value)
|
||||
def export_value(key, value, shell = preferred)
|
||||
case shell
|
||||
when :bash, :ksh, :sh, :zsh
|
||||
"export #{key}=\"#{sh_quote(value)}\""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user