Merge pull request #11129 from SMillerDev/feature/audit/service_command
This commit is contained in:
commit
afa99b4963
@ -275,12 +275,22 @@ module FormulaCellarChecks
|
|||||||
"Python formulae that are keg-only should not create `pip3` and `wheel3` symlinks."
|
"Python formulae that are keg-only should not create `pip3` and `wheel3` symlinks."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_service_command(formula)
|
||||||
|
return unless formula.prefix.directory?
|
||||||
|
return unless formula.service?
|
||||||
|
|
||||||
|
return "Service command blank" if formula.service.command.blank?
|
||||||
|
|
||||||
|
"Service command does not exist" unless File.exist?(formula.service.command.first)
|
||||||
|
end
|
||||||
|
|
||||||
def audit_installed
|
def audit_installed
|
||||||
@new_formula ||= false
|
@new_formula ||= false
|
||||||
|
|
||||||
problem_if_output(check_manpages)
|
problem_if_output(check_manpages)
|
||||||
problem_if_output(check_infopages)
|
problem_if_output(check_infopages)
|
||||||
problem_if_output(check_jars)
|
problem_if_output(check_jars)
|
||||||
|
problem_if_output(check_service_command(formula))
|
||||||
problem_if_output(check_non_libraries) if @new_formula
|
problem_if_output(check_non_libraries) if @new_formula
|
||||||
problem_if_output(check_non_executables(formula.bin))
|
problem_if_output(check_non_executables(formula.bin))
|
||||||
problem_if_output(check_generic_executables(formula.bin))
|
problem_if_output(check_generic_executables(formula.bin))
|
||||||
|
|||||||
@ -118,19 +118,23 @@ module Homebrew
|
|||||||
"#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
|
"#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[String]) }
|
||||||
|
def command
|
||||||
|
instance_eval(&@service_block)
|
||||||
|
@run.select { |i| i.is_a?(Pathname) }
|
||||||
|
.map(&:to_s)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a `String` plist.
|
# Returns a `String` plist.
|
||||||
# @return [String]
|
# @return [String]
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def to_plist
|
def to_plist
|
||||||
instance_eval(&@service_block)
|
instance_eval(&@service_block)
|
||||||
|
|
||||||
clean_command = @run.select { |i| i.is_a?(Pathname) }
|
|
||||||
.map(&:to_s)
|
|
||||||
|
|
||||||
base = {
|
base = {
|
||||||
Label: @formula.plist_name,
|
Label: @formula.plist_name,
|
||||||
RunAtLoad: @run_type == RUN_TYPE_IMMEDIATE,
|
RunAtLoad: @run_type == RUN_TYPE_IMMEDIATE,
|
||||||
ProgramArguments: clean_command,
|
ProgramArguments: command.join,
|
||||||
}
|
}
|
||||||
|
|
||||||
base[:KeepAlive] = @keep_alive if @keep_alive == true
|
base[:KeepAlive] = @keep_alive if @keep_alive == true
|
||||||
@ -148,16 +152,13 @@ module Homebrew
|
|||||||
def to_systemd_unit
|
def to_systemd_unit
|
||||||
instance_eval(&@service_block)
|
instance_eval(&@service_block)
|
||||||
|
|
||||||
clean_command = @run.select { |i| i.is_a?(Pathname) }
|
|
||||||
.map(&:to_s)
|
|
||||||
|
|
||||||
unit = <<~EOS
|
unit = <<~EOS
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Homebrew generated unit for #{@formula.name}
|
Description=Homebrew generated unit for #{@formula.name}
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=#{clean_command.join}
|
ExecStart=#{command.join}
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
options = []
|
options = []
|
||||||
|
|||||||
@ -488,6 +488,67 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#check_service_command" do
|
||||||
|
specify "Not installed" do
|
||||||
|
fa = formula_auditor "foo", <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
homepage "https://brew.sh"
|
||||||
|
|
||||||
|
service do
|
||||||
|
run []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
expect(fa.check_service_command(fa.formula)).to match nil
|
||||||
|
end
|
||||||
|
|
||||||
|
specify "No service" do
|
||||||
|
fa = formula_auditor "foo", <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
homepage "https://brew.sh"
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
mkdir_p fa.formula.prefix
|
||||||
|
expect(fa.check_service_command(fa.formula)).to match nil
|
||||||
|
end
|
||||||
|
|
||||||
|
specify "No command" do
|
||||||
|
fa = formula_auditor "foo", <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
homepage "https://brew.sh"
|
||||||
|
|
||||||
|
service do
|
||||||
|
run []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
mkdir_p fa.formula.prefix
|
||||||
|
expect(fa.check_service_command(fa.formula)).to match "Service command blank"
|
||||||
|
end
|
||||||
|
|
||||||
|
specify "Invalid command" do
|
||||||
|
fa = formula_auditor "foo", <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
homepage "https://brew.sh"
|
||||||
|
|
||||||
|
service do
|
||||||
|
run [HOMEBREW_PREFIX/"bin/something"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
mkdir_p fa.formula.prefix
|
||||||
|
expect(fa.check_service_command(fa.formula)).to match "Service command does not exist"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#audit_github_repository" do
|
describe "#audit_github_repository" do
|
||||||
specify "#audit_github_repository when HOMEBREW_NO_GITHUB_API is set" do
|
specify "#audit_github_repository when HOMEBREW_NO_GITHUB_API is set" do
|
||||||
ENV["HOMEBREW_NO_GITHUB_API"] = "1"
|
ENV["HOMEBREW_NO_GITHUB_API"] = "1"
|
||||||
|
|||||||
@ -123,4 +123,16 @@ describe Homebrew::Service do
|
|||||||
expect(unit).not_to include("Environment=\"PATH=#{std_path}\"")
|
expect(unit).not_to include("Environment=\"PATH=#{std_path}\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#command" do
|
||||||
|
it "returns @run data" do
|
||||||
|
f.class.service do
|
||||||
|
run opt_bin/"beanstalkd"
|
||||||
|
run_type :immediate
|
||||||
|
end
|
||||||
|
|
||||||
|
command = f.service.command
|
||||||
|
expect(command).to eq(["#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd"])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user