From 3ab21cc4124ecfc824565dab057836d4524fddb5 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sat, 1 May 2021 16:05:25 +0200 Subject: [PATCH 1/3] services: replace plist_options :manual with service command --- Library/Homebrew/caveats.rb | 10 +++- Library/Homebrew/extend/os/mac/caveats.rb | 71 +++++++++++++---------- Library/Homebrew/test/caveats_spec.rb | 14 +++++ 3 files changed, 62 insertions(+), 33 deletions(-) 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..04f736df29 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -6,44 +6,53 @@ class Caveats def plist_caveats s = [] - if f.plist || keg&.plist_installed? - plist_domain = f.plist_path.basename(".plist") + if !f.plist && !f.service? && !keg&.plist_installed? + caveat = "#{s.join("\n")}\n" unless s.empty? + return caveat + end - # 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" From 0e27ec707b7c20c7aaa6b27918b597bccd1b93c9 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 2 May 2021 15:25:47 +0200 Subject: [PATCH 2/3] Update Library/Homebrew/extend/os/mac/caveats.rb Co-authored-by: Mike McQuaid --- Library/Homebrew/extend/os/mac/caveats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 04f736df29..84361d5d6d 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -7,7 +7,7 @@ class Caveats def plist_caveats s = [] if !f.plist && !f.service? && !keg&.plist_installed? - caveat = "#{s.join("\n")}\n" unless s.empty? + caveat = "#{s.join("\n")}\n" if s.present? return caveat end From 4c67a8ce27394d05f7436907d7f0afb8f1845189 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 4 May 2021 14:36:00 +0200 Subject: [PATCH 3/3] caveats: simplify non-plist return Co-authored-by: Rylan Polster --- Library/Homebrew/extend/os/mac/caveats.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 84361d5d6d..97392b4be8 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -6,10 +6,7 @@ class Caveats def plist_caveats s = [] - if !f.plist && !f.service? && !keg&.plist_installed? - caveat = "#{s.join("\n")}\n" if s.present? - return caveat - end + return if !f.plist && !f.service? && !keg&.plist_installed? plist_domain = f.plist_path.basename(".plist")