homebrew-core/Formula/clickhouse-odbc.rb

121 lines
4.5 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 3
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_ventura: "9861a2a1c4cfd5e91da5bac18199324b960daaebd6d6c2cd63641a51124fa80e"
sha256 cellar: :any, arm64_monterey: "7db18ffe67c8d28059a4bfd6835f053fd48a6c12a21ad385df2aabf84ab87e60"
sha256 cellar: :any, arm64_big_sur: "8178a93f509e725ba63e318059851183ed8d599c6a9eda6a1918258f63400ab5"
sha256 cellar: :any, ventura: "00c541af823af303db5f25af6eed62ed43410b6f0a8d5459b72dfc33eef408a2"
sha256 cellar: :any, monterey: "ceebc52bec28c344c2b06206ec8763336fb2b7f77224f7aacb183a8f25aee609"
sha256 cellar: :any, big_sur: "6c41f4bd5a0404c135d2fb608e0a8086881cd71fc06ae7af95a1ccb52fe99bb2"
sha256 cellar: :any_skip_relocation, x86_64_linux: "f7ded074aefd6929a7a4660eb4f77175d6cb4cac2691067bfd0b7710b06a15b0"
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