205 lines
6.6 KiB
Ruby
205 lines
6.6 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.28.tar.gz"
|
|
sha256 "6dd0303998e70066d36905bd8fef1c01228ea182dbfbabc6c22ebacdbf8b5941"
|
|
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_monterey: "5f6efe3a8985554faf3c5a2f74e1029971d7fbebb13922aae117cffd7bdeba58"
|
|
sha256 arm64_big_sur: "e78bcb9a6be7a0a386c297a25f982435da3989a0adfd929c1c703d71da120822"
|
|
sha256 monterey: "723dee93398d4790ba6f547fc7072afa328ac7e6bb50448c096af77bcbfa141c"
|
|
sha256 big_sur: "fcd71d1bba2787a0e388c29eaf20d33611bb2d24c49ad0c9a0ac4d333111f33d"
|
|
sha256 catalina: "07394d1ce62dabc5c59ec024e76b92dfce271d13dc6b92be4b17a6153a60929e"
|
|
sha256 x86_64_linux: "c2509cef499a74def6de7c22af9f26c6a6291fb037c5e2c78c9ef1779d3d84aa"
|
|
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 "zstd"
|
|
|
|
uses_from_macos "curl"
|
|
uses_from_macos "cyrus-sasl"
|
|
uses_from_macos "libedit"
|
|
uses_from_macos "zlib"
|
|
|
|
on_linux do
|
|
depends_on "patchelf" => :build
|
|
depends_on "gcc" # for C++17
|
|
|
|
ignore_missing_libraries "metadata_cache.so"
|
|
end
|
|
|
|
conflicts_with "mariadb", "percona-server",
|
|
because: "mysql, mariadb, and percona install the same binaries"
|
|
|
|
fails_with gcc: "5"
|
|
|
|
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
|
|
]
|
|
|
|
# Their CMake macros check for `pkg-config` only on Linux and FreeBSD,
|
|
# so let's set `MY_PKG_CONFIG_EXECUTABLE` and `PKG_CONFIG_*` to make
|
|
# sure `pkg-config` is found and used.
|
|
if OS.mac?
|
|
args += %W[
|
|
-DMY_PKG_CONFIG_EXECUTABLE=pkg-config
|
|
-DPKG_CONFIG_FOUND=TRUE
|
|
-DPKG_CONFIG_VERSION_STRING=#{Formula["pkg-config"].version}
|
|
-DPKG_CONFIG_EXECUTABLE=#{Formula["pkg-config"].opt_bin}/pkg-config
|
|
]
|
|
|
|
if ENV["HOMEBREW_SDKROOT"].present?
|
|
args << "-DPKG_CONFIG_ARGN=--define-variable=homebrew_sdkroot=#{ENV["HOMEBREW_SDKROOT"]}"
|
|
end
|
|
end
|
|
|
|
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 libssl copies as the binaries use the keg anyway and they create problems for other applications
|
|
# Reported upstream at https://bugs.mysql.com/bug.php?id=103227
|
|
rm_rf lib/"libssl.dylib"
|
|
rm_rf lib/"libssl.1.1.dylib"
|
|
rm_rf lib/"libcrypto.1.1.dylib"
|
|
rm_rf lib/"libcrypto.dylib"
|
|
rm_rf lib/"plugin/libcrypto.1.1.dylib"
|
|
rm_rf lib/"plugin/libssl.1.1.dylib"
|
|
|
|
# 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 -uroot
|
|
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
|