The idea here is to test the new service name DSL on the two formulae in homebrew/core that will need it right away. The xinit
and dbus
packages previously redefined the Formula#plist_name
method which worked previously but now doesn't work at all with the API. To improve the situation and make it easier to serialize we're in the process of adding a new DSL.
service do
plist_name "name"
service_name "name"
end
More info:
First, we need to update the xinit
and dbus
formulae.
diff --git a/Formula/dbus.rb b/Formula/dbus.rb
index 5981a313b88..75e04f03532 100644
--- a/Formula/dbus.rb
+++ b/Formula/dbus.rb
@@ -72,15 +72,15 @@ class Dbus < Formula
system "make", "install"
end
- def plist_name
- "org.freedesktop.dbus-session"
- end
-
def post_install
# Generate D-Bus's UUID for this machine
system "#{bin}/dbus-uuidgen", "--ensure=#{var}/lib/dbus/machine-id"
end
+ service do
+ plist_name "org.freedesktop.dbus-session"
+ end
+
test do
system "#{bin}/dbus-daemon", "--version"
end
diff --git a/Formula/xinit.rb b/Formula/xinit.rb
index aa7c8dabe58..0abfbae811f 100644
--- a/Formula/xinit.rb
+++ b/Formula/xinit.rb
@@ -92,10 +92,6 @@ class Xinit < Formula
"bindir=#{bin}", "install"
end
- def plist_name
- "homebrew.mxcl.startx"
- end
-
def caveats
<<~EOS
To start privileged xinit now and restart at login:
@@ -103,6 +99,10 @@ class Xinit < Formula
EOS
end
+ service do
+ plist_name "homebrew.mxcl.startx"
+ end
+
test do
(testpath/"test.c").write <<~EOS
#include <assert.h>
Then, we need to check my PR branch and run the brew generate-formula-api
command to generate the JSON for all formulae (this isn't strictly necessary but it's easier than fiddling around with a script to only generate things for these two packages).
Finally, you can load the package from the JSON file directly using the following script.
# Test loading formulae with the new service name DSL from the API JSON.
require "pathname"
require "json"
require "formula"
NAMES = %w[dbus xinit].freeze
puts ">>> Faking Formula API"
API_JSON = NAMES.to_h do |name|
puts "- Adding #{name}"
path = Pathname.new("~/Desktop/#{name}.json").expand_path
content = path.read
json = JSON.parse(content)
name = json.delete("name")
[name, json]
end
puts
module Homebrew
module API
module Formula
def self.all_formulae
API_JSON
end
end
end
end
puts ">>> Loading Formulae"
NAMES.each_with_index do |name, idx|
puts "#{idx}. Loading #{name}"
formula = Formulary::FormulaAPILoader
.new(name)
.get_formula(:stable)
puts "- plist_name : #{formula.plist_name}"
puts "- service#serialize :"
pp formula.service.serialize
puts
end
The results are not that surprising but important nonetheless. The old code doesn't play well with this change so we'll have to wait a bit before applying this change to packages.
/u/l/Homebrew (master|✔) $ brew ruby '/Users/kevinrobell/Desktop/service-name-dsl-load-test.rb'
>>> Faking Formula API
- Adding dbus
- Adding xinit
>>> Loading Formulae
0. Loading dbus
/usr/local/Homebrew/Library/Homebrew/service.rb:571:in `deserialize': Unexpected run command: (ArgumentError)
from /usr/local/Homebrew/Library/Homebrew/formulary.rb:260:in `block in load_formula_from_api'
from /usr/local/Homebrew/Library/Homebrew/formulary.rb:149:in `initialize'
from /usr/local/Homebrew/Library/Homebrew/formulary.rb:149:in `new'
from /usr/local/Homebrew/Library/Homebrew/formulary.rb:149:in `load_formula_from_api'
from /usr/local/Homebrew/Library/Homebrew/formulary.rb:632:in `load_from_api'
from /usr/local/Homebrew/Library/Homebrew/formulary.rb:623:in `klass'
from /usr/local/Homebrew/Library/Homebrew/formulary.rb:403:in `get_formula'
from /Users/kevinrobell/Desktop/service-name-dsl-load-test.rb:37:in `block in <main>'
from /Users/kevinrobell/Desktop/service-name-dsl-load-test.rb:32:in `each'
from /Users/kevinrobell/Desktop/service-name-dsl-load-test.rb:32:in `each_with_index'
from /Users/kevinrobell/Desktop/service-name-dsl-load-test.rb:32:in `<main>'
/u/l/Homebrew (master|✔) [1]$ git checkout custom-service-name
Switched to branch 'custom-service-name'
/u/l/Homebrew (custom-service-name|✔) $ brew ruby '/Users/kevinrobell/Desktop/service-name-dsl-load-test.rb'
>>> Faking Formula API
- Adding dbus
- Adding xinit
>>> Loading Formulae
0. Loading dbus
- plist_name : org.freedesktop.dbus-session
- service#serialize :
{:plist_name=>"org.freedesktop.dbus-session"}
1. Loading xinit
- plist_name : homebrew.mxcl.startx
- service#serialize :
{:plist_name=>"homebrew.mxcl.startx"}
Then, we need to check my PR branch and run the brew generate-formula-api
command to generate the JSON for all formulae (this isn't strictly necessary but it's easier than fiddling around with a script to only generate things for these two packages).