189 lines
5.9 KiB
Ruby
189 lines
5.9 KiB
Ruby
class MysqlAT57 < Formula
|
|
desc "Open source relational database management system"
|
|
homepage "https://dev.mysql.com/doc/refman/5.7/en/"
|
|
url "https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.23.tar.gz"
|
|
sha256 "d05700ec5c1c6dae9311059dc1713206c29597f09dbd237bf0679b3c6438e87a"
|
|
|
|
bottle do
|
|
sha256 "0339c1c680d6ee38a066db6db8565eafa07d5e3e54d4bf1ee147c99e04c2ab51" => :mojave
|
|
sha256 "3a61ff9bfcac9cf5170b44442387be162938181c42e1fe5e5e1e303cf18b23b3" => :high_sierra
|
|
sha256 "27e355c8666977e4dccac2a97b73a871fdb1b5f0c23afa87131a590165f3dc16" => :sierra
|
|
sha256 "43098b0f5bee7c28dfe7dce503944b012beaae11cef769ea734b2c6f0598fa69" => :el_capitan
|
|
end
|
|
|
|
keg_only :versioned_formula
|
|
|
|
option "with-debug", "Build with debug support"
|
|
option "with-embedded", "Build the embedded server"
|
|
option "with-local-infile", "Build with local infile loading support"
|
|
option "with-memcached", "Build with InnoDB Memcached plugin"
|
|
option "with-test", "Build with unit tests"
|
|
|
|
deprecated_option "enable-debug" => "with-debug"
|
|
deprecated_option "enable-local-infile" => "with-local-infile"
|
|
deprecated_option "enable-memcached" => "with-memcached"
|
|
deprecated_option "with-tests" => "with-test"
|
|
|
|
depends_on "cmake" => :build
|
|
# https://github.com/Homebrew/homebrew-core/issues/1475
|
|
# Needs at least Clang 3.3, which shipped alongside Lion.
|
|
# Note: MySQL themselves don't support anything below El Capitan.
|
|
depends_on :macos => :lion
|
|
depends_on "openssl"
|
|
|
|
def datadir
|
|
var/"mysql"
|
|
end
|
|
|
|
def install
|
|
# -DINSTALL_* are relative to `CMAKE_INSTALL_PREFIX` (`prefix`)
|
|
args = %W[
|
|
-DCOMPILATION_COMMENT=Homebrew
|
|
-DDEFAULT_CHARSET=utf8
|
|
-DDEFAULT_COLLATION=utf8_general_ci
|
|
-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_BOOST=boost
|
|
-DWITH_EDITLINE=system
|
|
-DWITH_SSL=yes
|
|
]
|
|
|
|
# To enable unit testing at build, we need to download the unit testing suite
|
|
if build.with? "test"
|
|
args << "-DENABLE_DOWNLOADS=ON"
|
|
else
|
|
args << "-DWITH_UNIT_TESTS=OFF"
|
|
end
|
|
|
|
# Build with debug support
|
|
args << "-DWITH_DEBUG=1" if build.with? "debug"
|
|
|
|
# Build the embedded server
|
|
args << "-DWITH_EMBEDDED_SERVER=ON" if build.with? "embedded"
|
|
|
|
# Build with local infile loading support
|
|
args << "-DENABLED_LOCAL_INFILE=1" if build.with? "local-infile"
|
|
|
|
# Build with InnoDB Memcached plugin
|
|
args << "-DWITH_INNODB_MEMCACHED=ON" if build.with? "memcached"
|
|
|
|
# To enable unit testing at build, we need to download the unit testing suite
|
|
if build.with? "test"
|
|
args << "-DENABLE_DOWNLOADS=ON"
|
|
else
|
|
args << "-DWITH_UNIT_TESTS=OFF"
|
|
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 the tests directory if they are not built.
|
|
rm_rf prefix/"mysql-test" if build.without? "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
|
|
EOS
|
|
etc.install "my.cnf"
|
|
end
|
|
|
|
def post_install
|
|
# Make sure the datadir exists
|
|
datadir.mkpath
|
|
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
|
|
|
|
plist_options :manual => "#{HOMEBREW_PREFIX}/opt/mysql@5.7/bin/mysql.server start"
|
|
|
|
def plist; <<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>KeepAlive</key>
|
|
<true/>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>#{opt_bin}/mysqld_safe</string>
|
|
<string>--datadir=#{datadir}</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
<key>WorkingDirectory</key>
|
|
<string>#{datadir}</string>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
begin
|
|
# Expects datadir to be a completely clean dir, which testpath isn't.
|
|
dir = Dir.mktmpdir
|
|
system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
|
|
"--basedir=#{prefix}", "--datadir=#{dir}", "--tmpdir=#{dir}"
|
|
|
|
pid = fork do
|
|
exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}"
|
|
end
|
|
sleep 2
|
|
|
|
output = shell_output("curl 127.0.0.1:3306")
|
|
output.force_encoding("ASCII-8BIT") if output.respond_to?(:force_encoding)
|
|
assert_match version.to_s, output
|
|
ensure
|
|
Process.kill(9, pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|
|
end
|