homebrew-core/Formula/clickhouse-odbc.rb

120 lines
4.3 KiB
Ruby

class ClickhouseOdbc < Formula
desc "Official ODBC driver implementation for accessing ClickHouse as a data source"
homepage "https://github.com/ClickHouse/clickhouse-odbc#readme"
url "https://github.com/ClickHouse/clickhouse-odbc.git",
tag: "v1.2.1.20220905",
revision: "fab6efc57d671155c3a386f49884666b2a02c7b7"
license "Apache-2.0"
revision 1
head "https://github.com/ClickHouse/clickhouse-odbc.git", branch: "master"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "412e7143d71c13a01d897b50041f23d161ee02922e6ad441e653a04bce169063"
sha256 cellar: :any, arm64_big_sur: "29ccd9f322a33197921da4a5d082b6cab710e553e1c754728cea52b65785cf58"
sha256 cellar: :any, monterey: "a544237d73cb2f83013993bffd0c6684de6c3f2c69535786ba1aff8d128f8446"
sha256 cellar: :any, big_sur: "1b3125c02a0c768e87d48d6db00d9642b78bb952242a813a4399294fc8ce4412"
sha256 cellar: :any, catalina: "b0ceb7ba01db33e39e9647f38be431f0bc0a46909ff5c52051c25d304552264a"
sha256 cellar: :any_skip_relocation, x86_64_linux: "3bc3f511d6a74ef6a18d1a271c59cf9dc1944e6c07f24a22cc8f47b4e23f62b7"
end
depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on "icu4c"
depends_on "openssl@3"
depends_on "poco"
on_macos do
depends_on "libiodbc"
end
on_linux do
depends_on "unixodbc"
end
fails_with :gcc do
version "6"
end
def install
# Remove bundled libraries excluding required bundled `folly` headers
%w[googletest nanodbc poco ssl].each { |l| (buildpath/"contrib"/l).rmtree }
args = %W[
-DCH_ODBC_PREFER_BUNDLED_THIRD_PARTIES=OFF
-DCH_ODBC_THIRD_PARTY_LINK_STATIC=OFF
-DICU_ROOT=#{Formula["icu4c"].opt_prefix}
-DOPENSSL_ROOT_DIR=#{Formula["openssl@3"].opt_prefix}
]
args += if OS.mac?
["-DODBC_PROVIDER=iODBC", "-DODBC_DIR=#{Formula["libiodbc"].opt_prefix}"]
else
["-DODBC_PROVIDER=UnixODBC", "-DODBC_DIR=#{Formula["unixodbc"].opt_prefix}"]
end
system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
end
test do
(testpath/"my.odbcinst.ini").write <<~EOS
[ODBC Drivers]
ClickHouse ODBC Test Driver A = Installed
ClickHouse ODBC Test Driver W = Installed
[ClickHouse ODBC Test Driver A]
Description = ODBC Driver for ClickHouse (ANSI)
Driver = #{lib/shared_library("libclickhouseodbc")}
Setup = #{lib/shared_library("libclickhouseodbc")}
UsageCount = 1
[ClickHouse ODBC Test Driver W]
Description = ODBC Driver for ClickHouse (Unicode)
Driver = #{lib/shared_library("libclickhouseodbcw")}
Setup = #{lib/shared_library("libclickhouseodbcw")}
UsageCount = 1
EOS
(testpath/"my.odbc.ini").write <<~EOS
[ODBC Data Sources]
ClickHouse ODBC Test DSN A = ClickHouse ODBC Test Driver A
ClickHouse ODBC Test DSN W = ClickHouse ODBC Test Driver W
[ClickHouse ODBC Test DSN A]
Driver = ClickHouse ODBC Test Driver A
Description = DSN for ClickHouse ODBC Test Driver (ANSI)
Url = https://default:password@example.com:8443/query?database=default
[ClickHouse ODBC Test DSN W]
Driver = ClickHouse ODBC Test Driver W
Description = DSN for ClickHouse ODBC Test Driver (Unicode)
Url = https://default:password@example.com:8443/query?database=default
EOS
ENV["ODBCSYSINI"] = testpath
ENV["ODBCINSTINI"] = "my.odbcinst.ini"
ENV["ODBCINI"] = "#{ENV["ODBCSYSINI"]}/my.odbc.ini"
if OS.mac?
ENV["ODBCINSTINI"] = "#{ENV["ODBCSYSINI"]}/#{ENV["ODBCINSTINI"]}"
assert_match "SQL>",
pipe_output("#{Formula["libiodbc"].bin}/iodbctest 'DSN=ClickHouse ODBC Test DSN A'", "exit\n")
assert_match "SQL>",
pipe_output("#{Formula["libiodbc"].bin}/iodbctestw 'DSN=ClickHouse ODBC Test DSN W'", "exit\n")
elsif OS.linux?
assert_match "Connected!",
pipe_output("#{Formula["unixodbc"].bin}/isql 'ClickHouse ODBC Test DSN A'", "quit\n")
assert_match "Connected!",
pipe_output("#{Formula["unixodbc"].bin}/iusql 'ClickHouse ODBC Test DSN W'", "quit\n")
end
end
end