From 869b0ea519ce1d18303d62c75a136a09a30361a8 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 26 Jul 2021 09:08:26 +0200 Subject: [PATCH] Formula: use opt_prefix for service helpers --- Library/Homebrew/formula.rb | 4 +- .../Homebrew/test/formula_installer_spec.rb | 8 +-- Library/Homebrew/test/formula_spec.rb | 65 ++++++++++++------- 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index a368b9a532..c656b39e46 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -986,13 +986,13 @@ class Formula # The generated launchd {.plist} file path. sig { returns(Pathname) } def plist_path - prefix/"#{plist_name}.plist" + opt_prefix/"#{plist_name}.plist" end # The generated systemd {.service} file path. sig { returns(Pathname) } def systemd_service_path - prefix/"#{service_name}.service" + opt_prefix/"#{service_name}.service" end # The service specification of the software. diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index 9ac8e38925..e3179214f7 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -223,7 +223,7 @@ describe FormulaInstaller do it "works if plist is set" do formula = Testball.new path = formula.plist_path - formula.prefix.mkpath + formula.opt_prefix.mkpath expect(formula).to receive(:plist).twice.and_return("PLIST") expect(formula).to receive(:plist_path).and_call_original @@ -241,7 +241,7 @@ describe FormulaInstaller do plist_path = formula.plist_path service_path = formula.systemd_service_path service = Homebrew::Service.new(formula) - formula.prefix.mkpath + formula.opt_prefix.mkpath expect(formula).to receive(:plist).and_return(nil) expect(formula).to receive(:service?).exactly(3).and_return(true) @@ -264,7 +264,7 @@ describe FormulaInstaller do it "returns without definition" do formula = Testball.new path = formula.plist_path - formula.prefix.mkpath + formula.opt_prefix.mkpath expect(formula).to receive(:plist).and_return(nil) expect(formula).to receive(:service?).exactly(3).and_return(nil) @@ -282,7 +282,7 @@ describe FormulaInstaller do it "errors with duplicate definition" do formula = Testball.new path = formula.plist_path - formula.prefix.mkpath + formula.opt_prefix.mkpath expect(formula).to receive(:plist).and_return("plist") expect(formula).to receive(:service?).and_return(true) diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 63140706bd..3d3a2734ce 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -701,31 +701,52 @@ describe Formula do end end - specify "#service" do - f = formula do - url "https://brew.sh/test-1.0.tbz" - end - - f.class.service do - run [opt_bin/"beanstalkd"] - run_type :immediate - error_log_path var/"log/beanstalkd.error.log" - log_path var/"log/beanstalkd.log" - working_dir var - keep_alive true - end - expect(f.service).not_to eq(nil) - end - - specify "service uses simple run" do - f = formula do - url "https://brew.sh/test-1.0.tbz" - service do - run opt_bin/"beanstalkd" + describe "#service" do + specify "no service defined" do + f = formula do + url "https://brew.sh/test-1.0.tbz" end + + expect(f.service).to eq(nil) end - expect(f.service).not_to eq(nil) + specify "service complicated" do + f = formula do + url "https://brew.sh/test-1.0.tbz" + end + + f.class.service do + run [opt_bin/"beanstalkd"] + run_type :immediate + error_log_path var/"log/beanstalkd.error.log" + log_path var/"log/beanstalkd.log" + working_dir var + keep_alive true + end + expect(f.service).not_to eq(nil) + end + + specify "service uses simple run" do + f = formula do + url "https://brew.sh/test-1.0.tbz" + service do + run opt_bin/"beanstalkd" + end + end + + expect(f.service).not_to eq(nil) + end + + specify "service helpers return data" do + f = formula do + url "https://brew.sh/test-1.0.tbz" + end + + expect(f.plist_name).to eq("homebrew.mxcl.formula_name") + expect(f.service_name).to eq("homebrew.formula_name") + expect(f.plist_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.mxcl.formula_name.plist") + expect(f.systemd_service_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.formula_name.service") + end end specify "dependencies" do