diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..710c4d8 --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +common --noenable_bzlmod diff --git a/Formula/cockroach.rb b/Formula/cockroach.rb index 75b0031..46df175 100644 --- a/Formula/cockroach.rb +++ b/Formula/cockroach.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}" diff --git a/Formula/cockroach@24.1.rb b/Formula/cockroach@24.1.rb index 3e3411e..22aa436 100644 --- a/Formula/cockroach@24.1.rb +++ b/Formula/cockroach@24.1.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}" diff --git a/Formula/cockroach@24.3.rb b/Formula/cockroach@24.3.rb index 46bd129..a144793 100644 --- a/Formula/cockroach@24.3.rb +++ b/Formula/cockroach@24.3.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}" diff --git a/Formula/cockroach@25.1.rb b/Formula/cockroach@25.1.rb index 721ecc7..edff5ca 100644 --- a/Formula/cockroach@25.1.rb +++ b/Formula/cockroach@25.1.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}" diff --git a/Formula/cockroach@25.2.rb b/Formula/cockroach@25.2.rb index 40560c2..aa02661 100644 --- a/Formula/cockroach@25.2.rb +++ b/Formula/cockroach@25.2.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}" diff --git a/Formula/cockroach@25.3.rb b/Formula/cockroach@25.3.rb index 46aced2..7625644 100644 --- a/Formula/cockroach@25.3.rb +++ b/Formula/cockroach@25.3.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}" diff --git a/Formula/cockroach@25.4.rb b/Formula/cockroach@25.4.rb index 25acf2c..636ba73 100644 --- a/Formula/cockroach@25.4.rb +++ b/Formula/cockroach@25.4.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}" diff --git a/release/cockroach-tmpl.rb b/release/cockroach-tmpl.rb index 9f26fe9..351564d 100644 --- a/release/cockroach-tmpl.rb +++ b/release/cockroach-tmpl.rb @@ -27,12 +27,42 @@ 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" @@ -45,19 +75,9 @@ def install "#{lib}/cockroach/libgeos.dylib", "#{lib}/cockroach/libgeos.dylib" system "install_name_tool", "-id", "#{lib}/cockroach/libgeos_c.1.dylib", "#{lib}/cockroach/libgeos_c.dylib" - if version < Version.new("23.2.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.8.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - elsif version < Version.new("25.4.0") - system "install_name_tool", "-change", - "@rpath/libgeos.3.11.2.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - else - system "install_name_tool", "-change", - "@rpath/libgeos.3.13.1.dylib", "#{lib}/cockroach/libgeos.dylib", - "#{lib}/cockroach/libgeos_c.dylib" - end + system "install_name_tool", "-change", + libgeos_name, "#{lib}/cockroach/libgeos.dylib", + "#{lib}/cockroach/libgeos_c.dylib" end if OS.linux? @@ -65,14 +85,14 @@ def install 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" - if version < Version.new("23.2.0") - system "patchelf", "--replace-needed", "libgeos.so.3.8.1", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - else - system "patchelf", "--replace-needed", "libgeos.so.3.11.2", "libgeos.so", "#{lib}/cockroach/libgeos_c.so" - end + system "patchelf", "--replace-needed", libgeos_name, "libgeos.so", "#{lib}/cockroach/libgeos_c.so" end system bin/"cockroach", "gen", "man", "--path=#{man1}"