Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions Formula/cockroach@23.2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Auto-generated file, DO NOT EDIT
# Source: release/cockroach-tmpl.rb

class CockroachAT232 < Formula
desc "Distributed SQL database"
homepage "https://www.cockroachlabs.com"
version "23.2.29"
on_macos do
on_intel do
url "https://binaries.cockroachdb.com/cockroach-v23.2.29.darwin-10.9-amd64.tgz"
sha256 "c387993346379f88ec5a9ef51fdac335bd03677837a90ff2550f8ae1329e5c78"
end
on_arm do
url "https://binaries.cockroachdb.com/cockroach-v23.2.29.darwin-11.0-arm64.tgz"
sha256 "7bc65d2ff81d0bc39047adedfc4bc9c1430ece0eb56f97d04598bf84308244d3"
end
end
on_linux do
depends_on "patchelf" => :install
on_intel do
url "https://binaries.cockroachdb.com/cockroach-v23.2.29.linux-amd64.tgz"
sha256 "589a462f182ad348ef78783383b7610535df9ecf666a9b329b700a135fd06244"
end
end

def libgeos_supported?
!(OS.mac? && Hardware::CPU.arm?)
end

# Extract the libgeos library name from libgeos_c dependencies
def detect_libgeos_name(libgeos_c_path)
if OS.mac?
# Use otool to inspect the dylib dependencies
output = `otool -L "#{libgeos_c_path}"`.lines
# Find the line with @rpath/libgeos.*.dylib
geos_line = output.find { |line| line.include?("@rpath/libgeos.") && !line.include?("libgeos_c") }
if geos_line
# Extract just the library name (e.g., "@rpath/libgeos.3.13.1.dylib")
geos_line.strip.split[0]
else
raise "Could not detect libgeos dependency in #{libgeos_c_path}"
end
else
# Use patchelf to inspect the shared library dependencies
output = `patchelf --print-needed "#{libgeos_c_path}" 2>&1`
# Find the line with libgeos.so* (but not libgeos_c)
geos_line = output.lines.find { |line| line.strip.start_with?("libgeos.so") && !line.include?("libgeos_c") }
if geos_line
# Extract just the library name (e.g., "libgeos.so" or "libgeos.so.3.11.2")
geos_line.strip
else
raise "Could not detect libgeos dependency in #{libgeos_c_path}. Output: #{output}"
end
end
end

def install
bin.install "cockroach"
prefix.install "LICENSE" if File.exist?("LICENSE")
prefix.install "LICENSE.txt" if File.exist?("LICENSE.txt")
prefix.install "THIRD-PARTY-NOTICES.txt"
if OS.mac? && libgeos_supported?
# Detect the libgeos version dynamically before modifying the library
libgeos_name = detect_libgeos_name("lib/libgeos_c.dylib")

lib.mkpath
mkdir "#{lib}/cockroach"
lib.install "lib/libgeos.dylib" => "cockroach/libgeos.dylib"
lib.install "lib/libgeos_c.dylib" => "cockroach/libgeos_c.dylib"

# Brew sets rpaths appropriately, but only if the rpaths are set
# to not include "@rpath". As such, use the #{lib} location for the
# rpaths.
system "install_name_tool", "-id",
"#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib"
system "install_name_tool", "-id",
"#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib"
system "install_name_tool", "-change",
libgeos_name, "#{lib}/cockroach/libgeos.dylib",
"#{lib}/cockroach/libgeos_c.dylib"
end

if OS.linux?
lib.mkpath
mkdir "#{lib}/cockroach"
lib.install "lib/libgeos.so" => "cockroach/libgeos.so"
lib.install "lib/libgeos_c.so" => "cockroach/libgeos_c.so"

# Detect the libgeos version dynamically before modifying the library
libgeos_name = detect_libgeos_name("#{lib}/cockroach/libgeos_c.so")

system "patchelf", "--set-rpath", "#{lib}/cockroach/", "#{lib}/cockroach/libgeos.so"
system "patchelf", "--set-rpath", "#{lib}/cockroach/", "#{lib}/cockroach/libgeos_c.so"
system "patchelf", "--set-soname", "libgeos.so", "#{lib}/cockroach/libgeos.so"
system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so"
end

system bin/"cockroach", "gen", "man", "--path=#{man1}"

bash_completion.mkpath
system bin/"cockroach", "gen", "autocomplete", "bash", "--out=#{bash_completion}/cockroach"

zsh_completion.mkpath
system bin/"cockroach", "gen", "autocomplete", "zsh", "--out=#{zsh_completion}/_cockroach"
end

service do
args = [
"start-single-node",
"--store=#{var}/cockroach",
"--http-port=26256",
"--insecure",
"--host=localhost",
]
# We cannot use custom function in the service block, so we need to
# check the condition here.
args << "--spatial-libs=#{opt_bin}/../lib/cockroach" if !(OS.mac? && Hardware::CPU.arm?)
run [opt_bin/"cockroach"] + args
working_dir var
keep_alive true
log_path var/"log/cockroach.log"
error_log_path var/"log/cockroach.err"
end

test do
begin
args = [
"start-single-node",
"--insecure",
"--background",
"--listen-addr=127.0.0.1:0",
"--http-addr=127.0.0.1:0",
"--listening-url-file=listen_url_fifo",
]
args << "--spatial-libs=#{opt_bin}/../lib/cockroach" if libgeos_supported?
# Redirect stdout and stderr to a file, or else `brew test --verbose`
# will hang forever as it waits for stdout and stderr to close.
pid = fork do
exec "#{bin}/cockroach " + args.join(" ") + " &> start.out"
end
sleep 20

# TODO(bdarnell): remove the X from this variable and the --url flags after
# https://github.com/cockroachdb/cockroach/issues/40747 is fixed.
ENV["XCOCKROACH_URL"] = File.read("listen_url_fifo").strip
pipe_output("#{bin}/cockroach sql --url=$XCOCKROACH_URL", <<~EOS)
CREATE DATABASE bank;
CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);
INSERT INTO bank.accounts VALUES (1, 1000.50);
EOS
output = pipe_output("#{bin}/cockroach sql --url=$XCOCKROACH_URL --format=csv",
"SELECT * FROM bank.accounts;")
assert_equal <<~EOS, output
id,balance
1,1000.50
EOS
if libgeos_supported?
output = pipe_output("#{bin}/cockroach sql --url=$XCOCKROACH_URL --format=csv",
"SELECT ST_IsValid(ST_MakePoint(1, 1)) is_valid;")
assert_equal <<~EOS, output
is_valid
t
EOS
end
rescue => e
# If an error occurs, attempt to print out any messages from the
# server.
begin
$stderr.puts "server messages:", File.read("start.out")
rescue
$stderr.puts "unable to load messages from start.out"
end
raise e
ensure
Process.kill("SIGINT", pid)
Process.wait(pid)
end
end
end
Loading