homebrew-core/Formula/tile38.rb

92 lines
2.8 KiB
Ruby

class Tile38 < Formula
desc "In-memory geolocation data store, spatial index, and realtime geofence"
homepage "https://tile38.com/"
url "https://github.com/tidwall/tile38.git",
tag: "1.22.6",
revision: "d211858db62a3e13768879b3954648b2147759fe"
license "MIT"
head "https://github.com/tidwall/tile38.git"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "1f387e3ffa1428b4b1c2804a7d52a34932062e1b7464587bf2a47ed0c9e52d6a"
sha256 cellar: :any_skip_relocation, big_sur: "675b17af3d429dca6462194f62007c1544c0a4782fd22d54440f11e13f24c825"
sha256 cellar: :any_skip_relocation, catalina: "9972d32b249e738605729640cd449e998a7de599685887d41277b913eaa14d3f"
sha256 cellar: :any_skip_relocation, mojave: "711814efd1b7a8f0ec7673910e6ecb37b6a6f5dadff3e2b88468e0f8def8a7aa"
end
depends_on "go" => :build
def datadir
var/"tile38/data"
end
def install
ldflags = %W[
-s -w
-X github.com/tidwall/tile38/core.Version=#{version}
-X github.com/tidwall/tile38/core.GitSHA=#{Utils.git_short_head}
]
system "go", "build", "-o", bin/"tile38-server", "-ldflags", ldflags.join(" "), "./cmd/tile38-server"
system "go", "build", "-o", bin/"tile38-cli", "-ldflags", ldflags.join(" "), "./cmd/tile38-cli"
end
def post_install
# Make sure the data directory exists
datadir.mkpath
end
def caveats
<<~EOS
To connect: tile38-cli
EOS
end
plist_options manual: "tile38-server -d #{HOMEBREW_PREFIX}/var/tile38/data"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/tile38-server</string>
<string>-d</string>
<string>#{datadir}</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/tile38.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/tile38.log</string>
</dict>
</plist>
EOS
end
test do
pid = fork do
exec "#{bin}/tile38-server", "-q"
end
sleep 2
# remove `$408` in the first line output
json_output = shell_output("#{bin}/tile38-cli server").lines[1]
tile38_server = JSON.parse(json_output)
assert_equal tile38_server["ok"], true
ensure
Process.kill("HUP", pid)
end
end