188 lines
6.2 KiB
Ruby
188 lines
6.2 KiB
Ruby
class Mysql < Formula
|
|
desc "Open source relational database management system"
|
|
homepage "https://dev.mysql.com/doc/refman/8.0/en/"
|
|
url "https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-boost-8.0.31.tar.gz"
|
|
sha256 "7867f3fd8ca423d283a6162c819c766863ecffbf9b59b4756dc7bb81184c1d6a"
|
|
license "GPL-2.0-only" => { with: "Universal-FOSS-exception-1.0" }
|
|
|
|
livecheck do
|
|
url "https://dev.mysql.com/downloads/mysql/?tpl=files&os=src"
|
|
regex(/href=.*?mysql[._-](?:boost[._-])?v?(\d+(?:\.\d+)+)\.t/i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 arm64_ventura: "73a817585b4aa253b0984698b6e2d2fde197332d3de144855d4489969f94fb9f"
|
|
sha256 arm64_monterey: "3b17e7d3888bf63e7d778e1d38ad363efb92a1a593ee279ce18b3105e3d2e4aa"
|
|
sha256 arm64_big_sur: "8fc37f512c9754ecaaacd84503790bddec4ea50f4454cc3335a789d18b452598"
|
|
sha256 ventura: "060ac12104e90e62049852f99226424c570624217be883a9115ee7fd388b7290"
|
|
sha256 monterey: "92eef344bc3a1687c0463234bad3ac0741d032dd572bb51afecdb1aa8afe3792"
|
|
sha256 big_sur: "021f60febd7740d5b1f64b9309a8f3fefc88a0c5ff9f5c97bfb4a3a145124bef"
|
|
sha256 catalina: "dac28aca0e336686b213582cb72602da5cef8ab84c55d52728103e82f3c2d630"
|
|
sha256 x86_64_linux: "08493b15c16627f848e755eba7a99a8ac0ff5d8a0793b0db4f2c182019d98f92"
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "pkg-config" => :build
|
|
depends_on "icu4c"
|
|
depends_on "libevent"
|
|
depends_on "libfido2"
|
|
depends_on "lz4"
|
|
depends_on "openssl@1.1"
|
|
depends_on "protobuf"
|
|
depends_on "zlib" # Zlib 1.2.12+
|
|
depends_on "zstd"
|
|
|
|
uses_from_macos "curl"
|
|
uses_from_macos "cyrus-sasl"
|
|
uses_from_macos "libedit"
|
|
|
|
on_linux do
|
|
depends_on "patchelf" => :build
|
|
depends_on "libtirpc"
|
|
end
|
|
|
|
conflicts_with "mariadb", "percona-server",
|
|
because: "mysql, mariadb, and percona install the same binaries"
|
|
|
|
fails_with gcc: "5" # for C++17
|
|
|
|
# Patch out check for Homebrew `boost`.
|
|
# This should not be necessary when building inside `brew`.
|
|
# https://github.com/Homebrew/homebrew-test-bot/pull/820
|
|
patch do
|
|
url "https://raw.githubusercontent.com/Homebrew/formula-patches/030f7433e89376ffcff836bb68b3903ab90f9cdc/mysql/boost-check.patch"
|
|
sha256 "af27e4b82c84f958f91404a9661e999ccd1742f57853978d8baec2f993b51153"
|
|
end
|
|
|
|
def datadir
|
|
var/"mysql"
|
|
end
|
|
|
|
def install
|
|
if OS.linux?
|
|
# Fix libmysqlgcs.a(gcs_logging.cc.o): relocation R_X86_64_32
|
|
# against `_ZN17Gcs_debug_options12m_debug_noneB5cxx11E' can not be used when making
|
|
# a shared object; recompile with -fPIC
|
|
ENV.append_to_cflags "-fPIC"
|
|
|
|
# Disable ABI checking
|
|
inreplace "cmake/abi_check.cmake", "RUN_ABI_CHECK 1", "RUN_ABI_CHECK 0"
|
|
end
|
|
|
|
# -DINSTALL_* are relative to `CMAKE_INSTALL_PREFIX` (`prefix`)
|
|
args = %W[
|
|
-DFORCE_INSOURCE_BUILD=1
|
|
-DCOMPILATION_COMMENT=Homebrew
|
|
-DINSTALL_DOCDIR=share/doc/#{name}
|
|
-DINSTALL_INCLUDEDIR=include/mysql
|
|
-DINSTALL_INFODIR=share/info
|
|
-DINSTALL_MANDIR=share/man
|
|
-DINSTALL_MYSQLSHAREDIR=share/mysql
|
|
-DINSTALL_PLUGINDIR=lib/plugin
|
|
-DMYSQL_DATADIR=#{datadir}
|
|
-DSYSCONFDIR=#{etc}
|
|
-DWITH_SYSTEM_LIBS=ON
|
|
-DWITH_BOOST=boost
|
|
-DWITH_EDITLINE=system
|
|
-DWITH_FIDO=system
|
|
-DWITH_ICU=system
|
|
-DWITH_LIBEVENT=system
|
|
-DWITH_LZ4=system
|
|
-DWITH_PROTOBUF=system
|
|
-DWITH_SSL=system
|
|
-DWITH_ZLIB=system
|
|
-DWITH_ZSTD=system
|
|
-DWITH_UNIT_TESTS=OFF
|
|
-DENABLED_LOCAL_INFILE=1
|
|
-DWITH_INNODB_MEMCACHED=ON
|
|
]
|
|
|
|
system "cmake", ".", *std_cmake_args, *args
|
|
system "make"
|
|
system "make", "install"
|
|
|
|
(prefix/"mysql-test").cd do
|
|
system "./mysql-test-run.pl", "status", "--vardir=#{Dir.mktmpdir}"
|
|
end
|
|
|
|
# Remove the tests directory
|
|
rm_rf prefix/"mysql-test"
|
|
|
|
# Don't create databases inside of the prefix!
|
|
# See: https://github.com/Homebrew/homebrew/issues/4975
|
|
rm_rf prefix/"data"
|
|
|
|
# Fix up the control script and link into bin.
|
|
inreplace "#{prefix}/support-files/mysql.server",
|
|
/^(PATH=".*)(")/,
|
|
"\\1:#{HOMEBREW_PREFIX}/bin\\2"
|
|
bin.install_symlink prefix/"support-files/mysql.server"
|
|
|
|
# Install my.cnf that binds to 127.0.0.1 by default
|
|
(buildpath/"my.cnf").write <<~EOS
|
|
# Default Homebrew MySQL server config
|
|
[mysqld]
|
|
# Only allow connections from localhost
|
|
bind-address = 127.0.0.1
|
|
mysqlx-bind-address = 127.0.0.1
|
|
EOS
|
|
etc.install "my.cnf"
|
|
end
|
|
|
|
def post_install
|
|
# Make sure the var/mysql directory exists
|
|
(var/"mysql").mkpath
|
|
|
|
# Don't initialize database, it clashes when testing other MySQL-like implementations.
|
|
return if ENV["HOMEBREW_GITHUB_ACTIONS"]
|
|
|
|
unless (datadir/"mysql/general_log.CSM").exist?
|
|
ENV["TMPDIR"] = nil
|
|
system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
|
|
"--basedir=#{prefix}", "--datadir=#{datadir}", "--tmpdir=/tmp"
|
|
end
|
|
end
|
|
|
|
def caveats
|
|
s = <<~EOS
|
|
We've installed your MySQL database without a root password. To secure it run:
|
|
mysql_secure_installation
|
|
|
|
MySQL is configured to only allow connections from localhost by default
|
|
|
|
To connect run:
|
|
mysql -u root
|
|
EOS
|
|
if (my_cnf = ["/etc/my.cnf", "/etc/mysql/my.cnf"].find { |x| File.exist? x })
|
|
s += <<~EOS
|
|
|
|
A "#{my_cnf}" from another install may interfere with a Homebrew-built
|
|
server starting up correctly.
|
|
EOS
|
|
end
|
|
s
|
|
end
|
|
|
|
service do
|
|
run [opt_bin/"mysqld_safe", "--datadir=#{var}/mysql"]
|
|
keep_alive true
|
|
working_dir var/"mysql"
|
|
end
|
|
|
|
test do
|
|
(testpath/"mysql").mkpath
|
|
(testpath/"tmp").mkpath
|
|
system bin/"mysqld", "--no-defaults", "--initialize-insecure", "--user=#{ENV["USER"]}",
|
|
"--basedir=#{prefix}", "--datadir=#{testpath}/mysql", "--tmpdir=#{testpath}/tmp"
|
|
port = free_port
|
|
fork do
|
|
system "#{bin}/mysqld", "--no-defaults", "--user=#{ENV["USER"]}",
|
|
"--datadir=#{testpath}/mysql", "--port=#{port}", "--tmpdir=#{testpath}/tmp"
|
|
end
|
|
sleep 5
|
|
assert_match "information_schema",
|
|
shell_output("#{bin}/mysql --port=#{port} --user=root --password= --execute='show databases;'")
|
|
system "#{bin}/mysqladmin", "--port=#{port}", "--user=root", "--password=", "shutdown"
|
|
end
|
|
end
|