Fix formulae method loading
Co-authored-by: nandahkrishna <me@nandahkrishna.com>
This commit is contained in:
parent
4427fa283f
commit
b927ecfd85
@ -392,11 +392,6 @@ class Formula
|
|||||||
# @see .livecheckable?
|
# @see .livecheckable?
|
||||||
delegate livecheckable?: :"self.class"
|
delegate livecheckable?: :"self.class"
|
||||||
|
|
||||||
# The service specification for the software.
|
|
||||||
# @!method service
|
|
||||||
# @see .service=
|
|
||||||
delegate service: :"self.class"
|
|
||||||
|
|
||||||
# Is a service specification defined for the software?
|
# Is a service specification defined for the software?
|
||||||
# @!method service?
|
# @!method service?
|
||||||
# @see .service?
|
# @see .service?
|
||||||
@ -973,6 +968,13 @@ class Formula
|
|||||||
prefix/"#{plist_name}.plist"
|
prefix/"#{plist_name}.plist"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The service specification of the software.
|
||||||
|
def service
|
||||||
|
return Homebrew::Service.new(self, &self.class.service) if service?
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
delegate plist_manual: :"self.class"
|
delegate plist_manual: :"self.class"
|
||||||
|
|
||||||
@ -2397,7 +2399,7 @@ class Formula
|
|||||||
# It returns true when a service block is present in the {Formula} and
|
# It returns true when a service block is present in the {Formula} and
|
||||||
# false otherwise, and is used by service.
|
# false otherwise, and is used by service.
|
||||||
def service?
|
def service?
|
||||||
@service.present?
|
@service_block.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
# The `:startup` attribute set by {.plist_options}.
|
# The `:startup` attribute set by {.plist_options}.
|
||||||
@ -2874,10 +2876,9 @@ class Formula
|
|||||||
# run [opt_bin/"foo"]
|
# run [opt_bin/"foo"]
|
||||||
# end</pre>
|
# end</pre>
|
||||||
def service(&block)
|
def service(&block)
|
||||||
@service ||= Homebrew::Service.new(self)
|
return @service_block unless block
|
||||||
return @service unless block
|
|
||||||
|
|
||||||
@service.instance_eval(&block)
|
@service_block = block
|
||||||
end
|
end
|
||||||
|
|
||||||
# Defines whether the {Formula}'s bottle can be used on the given Homebrew
|
# Defines whether the {Formula}'s bottle can be used on the given Homebrew
|
||||||
|
|||||||
@ -7,16 +7,18 @@ module Homebrew
|
|||||||
# also return the related instance variable when no argument is provided.
|
# also return the related instance variable when no argument is provided.
|
||||||
class Service
|
class Service
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
extend Forwardable
|
||||||
|
|
||||||
RUN_TYPE_IMMEDIATE = "immediate"
|
RUN_TYPE_IMMEDIATE = "immediate"
|
||||||
RUN_TYPE_INTERVAL = "interval"
|
RUN_TYPE_INTERVAL = "interval"
|
||||||
RUN_TYPE_CRON = "cron"
|
RUN_TYPE_CRON = "cron"
|
||||||
|
|
||||||
# sig { params(formula: Formula).void }
|
# sig { params(formula: Formula).void }
|
||||||
def initialize(formula)
|
def initialize(formula, &block)
|
||||||
@formula = formula
|
@formula = formula
|
||||||
@run_type = RUN_TYPE_IMMEDIATE
|
@run_type = RUN_TYPE_IMMEDIATE
|
||||||
@environment_variables = {}
|
@environment_variables = {}
|
||||||
|
@service_block = block
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(command: T.nilable(T.any(T::Array[String], String, Pathname))).returns(T.nilable(Array)) }
|
sig { params(command: T.nilable(T.any(T::Array[String], String, Pathname))).returns(T.nilable(Array)) }
|
||||||
@ -109,47 +111,14 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The directory where the formula's variable files should be installed.
|
delegate [ # rubocop:disable Layout/HashAlignment
|
||||||
# This directory is not inside the `HOMEBREW_CELLAR` so it persists
|
:bin,
|
||||||
# across upgrades.
|
:var,
|
||||||
sig { returns(Pathname) }
|
:etc,
|
||||||
def var
|
:opt_bin,
|
||||||
HOMEBREW_PREFIX/"var"
|
:opt_sbin,
|
||||||
end
|
:opt_prefix,
|
||||||
|
] => :@formula
|
||||||
# The directory where the formula's configuration files should be installed.
|
|
||||||
# Anything using `etc.install` will not overwrite other files on e.g. upgrades
|
|
||||||
# but will write a new file named `*.default`.
|
|
||||||
# This directory is not inside the `HOMEBREW_CELLAR` so it persists
|
|
||||||
# across upgrades.
|
|
||||||
sig { returns(Pathname) }
|
|
||||||
def etc
|
|
||||||
HOMEBREW_PREFIX/"etc"
|
|
||||||
end
|
|
||||||
|
|
||||||
# The directory where the formula's binaries should be installed.
|
|
||||||
# This is symlinked into `HOMEBREW_PREFIX` after installation or with
|
|
||||||
# `brew link` for formulae that are not keg-only.
|
|
||||||
sig { returns(Pathname) }
|
|
||||||
def opt_bin
|
|
||||||
opt_prefix/"bin"
|
|
||||||
end
|
|
||||||
|
|
||||||
# The directory where the formula's binaries should be installed.
|
|
||||||
# This is symlinked into `HOMEBREW_PREFIX` after installation or with
|
|
||||||
# `brew link` for formulae that are not keg-only.
|
|
||||||
sig { returns(Pathname) }
|
|
||||||
def opt_sbin
|
|
||||||
opt_prefix/"sbin"
|
|
||||||
end
|
|
||||||
|
|
||||||
# A stable path for this formula, when installed. Contains the formula name
|
|
||||||
# but no version number. Only the active version will be linked here if
|
|
||||||
# multiple versions are installed.
|
|
||||||
sig { returns(Pathname) }
|
|
||||||
def opt_prefix
|
|
||||||
HOMEBREW_PREFIX/"opt/#{@formula.name}"
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def std_service_path_env
|
def std_service_path_env
|
||||||
@ -160,6 +129,8 @@ module Homebrew
|
|||||||
# @return [String]
|
# @return [String]
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def to_plist
|
def to_plist
|
||||||
|
instance_eval(&@service_block)
|
||||||
|
|
||||||
clean_command = @run.select { |i| i.is_a?(Pathname) }
|
clean_command = @run.select { |i| i.is_a?(Pathname) }
|
||||||
.map(&:to_s)
|
.map(&:to_s)
|
||||||
|
|
||||||
|
|||||||
@ -704,7 +704,9 @@ describe Formula do
|
|||||||
specify "#service" do
|
specify "#service" do
|
||||||
f = formula do
|
f = formula do
|
||||||
url "https://brew.sh/test-1.0.tbz"
|
url "https://brew.sh/test-1.0.tbz"
|
||||||
service do
|
end
|
||||||
|
|
||||||
|
f.class.service do
|
||||||
run [opt_bin/"beanstalkd"]
|
run [opt_bin/"beanstalkd"]
|
||||||
run_type :immediate
|
run_type :immediate
|
||||||
error_log_path var/"log/beanstalkd.error.log"
|
error_log_path var/"log/beanstalkd.error.log"
|
||||||
@ -712,14 +714,7 @@ describe Formula do
|
|||||||
working_dir var
|
working_dir var
|
||||||
keep_alive true
|
keep_alive true
|
||||||
end
|
end
|
||||||
end
|
expect(f.service).not_to eq(nil)
|
||||||
|
|
||||||
expect(f.service.run).to eq([HOMEBREW_PREFIX/"opt/bin/beanstalkd"])
|
|
||||||
expect(f.service.error_log_path).to eq("#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log")
|
|
||||||
expect(f.service.log_path).to eq("#{HOMEBREW_PREFIX}/var/log/beanstalkd.log")
|
|
||||||
expect(f.service.working_dir).to eq("#{HOMEBREW_PREFIX}/var")
|
|
||||||
expect(f.service.keep_alive).to eq(true)
|
|
||||||
expect(f.service.run_type).to eq("immediate")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
specify "service uses simple run" do
|
specify "service uses simple run" do
|
||||||
@ -730,7 +725,7 @@ describe Formula do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(f.service.run).to eq([HOMEBREW_PREFIX/"opt/bin/beanstalkd"])
|
expect(f.service).not_to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
specify "dependencies" do
|
specify "dependencies" do
|
||||||
|
|||||||
@ -15,12 +15,10 @@ describe Homebrew::Service do
|
|||||||
let(:spec) { :stable }
|
let(:spec) { :stable }
|
||||||
let(:f) { klass.new(name, path, spec) }
|
let(:f) { klass.new(name, path, spec) }
|
||||||
|
|
||||||
let(:service) { described_class.new(f) }
|
|
||||||
|
|
||||||
describe "#to_plist" do
|
describe "#to_plist" do
|
||||||
it "returns valid plist" do
|
it "returns valid plist" do
|
||||||
service.instance_eval do
|
f.class.service do
|
||||||
run [opt_bin/"beanstalkd"]
|
run opt_bin/"beanstalkd"
|
||||||
run_type :immediate
|
run_type :immediate
|
||||||
environment_variables PATH: std_service_path_env
|
environment_variables PATH: std_service_path_env
|
||||||
error_log_path var/"log/beanstalkd.error.log"
|
error_log_path var/"log/beanstalkd.error.log"
|
||||||
@ -29,7 +27,7 @@ describe Homebrew::Service do
|
|||||||
keep_alive true
|
keep_alive true
|
||||||
end
|
end
|
||||||
|
|
||||||
plist = service.to_plist
|
plist = f.service.to_plist
|
||||||
expect(plist).to include("<key>Label</key>")
|
expect(plist).to include("<key>Label</key>")
|
||||||
expect(plist).to include("<string>homebrew.mxcl.#{name}</string>")
|
expect(plist).to include("<string>homebrew.mxcl.#{name}</string>")
|
||||||
expect(plist).to include("<key>KeepAlive</key>")
|
expect(plist).to include("<key>KeepAlive</key>")
|
||||||
@ -48,12 +46,12 @@ describe Homebrew::Service do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns valid partial plist" do
|
it "returns valid partial plist" do
|
||||||
service.instance_eval do
|
f.class.service do
|
||||||
run ["#{HOMEBREW_PREFIX}/bin/beanstalkd"]
|
run bin/"beanstalkd"
|
||||||
run_type :immediate
|
run_type :immediate
|
||||||
end
|
end
|
||||||
|
|
||||||
plist = service.to_plist
|
plist = f.service.to_plist
|
||||||
expect(plist).to include("<string>homebrew.mxcl.#{name}</string>")
|
expect(plist).to include("<string>homebrew.mxcl.#{name}</string>")
|
||||||
expect(plist).to include("<key>Label</key>")
|
expect(plist).to include("<key>Label</key>")
|
||||||
expect(plist).not_to include("<key>KeepAlive</key>")
|
expect(plist).not_to include("<key>KeepAlive</key>")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user