diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 75f0044047..607e1463df 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -152,13 +152,19 @@ class Caveats end def plist_caveats - return unless f.plist_manual + return if !f.plist_manual && !f.service? + + command = if f.service? + f.service.command.join(" ") + else + f.plist_manual + end # Default to brew services not being supported. macOS overrides this behavior. <<~EOS #{Formatter.warning("Warning:")} #{f.name} provides a launchd plist which can only be used on macOS! You can manually execute the service instead with: - #{f.plist_manual} + #{command} EOS end diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 6de89386a5..97392b4be8 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -6,44 +6,50 @@ class Caveats def plist_caveats s = [] - if f.plist || keg&.plist_installed? - plist_domain = f.plist_path.basename(".plist") + return if !f.plist && !f.service? && !keg&.plist_installed? - # we readlink because this path probably doesn't exist since caveats - # occurs before the link step of installation - # Yosemite security measures mildly tighter rules: - # https://github.com/Homebrew/legacy-homebrew/issues/33815 - if !plist_path.file? || !plist_path.symlink? - if f.plist_startup - s << "To have launchd start #{f.full_name} now and restart at startup:" - s << " sudo brew services start #{f.full_name}" - else - s << "To have launchd start #{f.full_name} now and restart at login:" - s << " brew services start #{f.full_name}" - end - # For startup plists, we cannot tell whether it's running on launchd, - # as it requires for `sudo launchctl list` to get real result. - elsif f.plist_startup - s << "To restart #{f.full_name} after an upgrade:" - s << " sudo brew services restart #{f.full_name}" - elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null" - s << "To restart #{f.full_name} after an upgrade:" - s << " brew services restart #{f.full_name}" + plist_domain = f.plist_path.basename(".plist") + + # we readlink because this path probably doesn't exist since caveats + # occurs before the link step of installation + # Yosemite security measures mildly tighter rules: + # https://github.com/Homebrew/legacy-homebrew/issues/33815 + if f.plist && (!plist_path.file? || !plist_path.symlink?) + if f.plist_startup + s << "To have launchd start #{f.full_name} now and restart at startup:" + s << " sudo brew services start #{f.full_name}" else - s << "To start #{f.full_name}:" + s << "To have launchd start #{f.full_name} now and restart at login:" s << " brew services start #{f.full_name}" end + # For startup plists, we cannot tell whether it's running on launchd, + # as it requires for `sudo launchctl list` to get real result. + elsif f.plist_startup + s << "To restart #{f.full_name} after an upgrade:" + s << " sudo brew services restart #{f.full_name}" + elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null" + s << "To restart #{f.full_name} after an upgrade:" + s << " brew services restart #{f.full_name}" + else + s << "To start #{f.full_name}:" + s << " brew services start #{f.full_name}" + end - if f.plist_manual - s << "Or, if you don't want/need a background service you can just run:" - s << " #{f.plist_manual}" + if f.plist_manual || f.service? + command = if f.service? + f.service.command.join(" ") + else + f.plist_manual end - # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default - # check if this is being run under `tmux` to avoid failing - if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") - s << "" << "WARNING: brew services will fail when run under tmux." - end + s << "Or, if you don't want/need a background service you can just run:" + s << " #{command}" + end + + # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default + # check if this is being run under `tmux` to avoid failing + if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") + s << "" << "WARNING: brew services will fail when run under tmux." end "#{s.join("\n")}\n" unless s.empty? end diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index 15cb29d4f8..7b4c32d463 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -114,6 +114,20 @@ describe Caveats do expect(caveats).to include(f.plist_manual) end + it "gives information about service" do + f = formula do + url "foo-1.0" + service do + run [bin/"php", "test"] + end + end + caveats = described_class.new(f).caveats + + expect(f.service?).to eq(true) + expect(caveats).to include("#{f.bin}/php test") + expect(caveats).to include("background service") + end + it "warns about brew failing under tmux" do f = formula do url "foo-1.0"