202 lines
6.6 KiB
Ruby
202 lines
6.6 KiB
Ruby
class PostgresqlAT12 < Formula
|
|
desc "Object-relational database system"
|
|
homepage "https://www.postgresql.org/"
|
|
url "https://ftp.postgresql.org/pub/source/v12.8/postgresql-12.8.tar.bz2"
|
|
sha256 "e26401e090c34ccb15ffb33a111f340833833535a7b7c5cd11cd88ab57d9c62a"
|
|
license "PostgreSQL"
|
|
|
|
livecheck do
|
|
url "https://ftp.postgresql.org/pub/source/"
|
|
regex(%r{href=["']?v?(12(?:\.\d+)+)/?["' >]}i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 arm64_monterey: "cfcf7be1657b3bf094d8d013cae4e36c7eb584e4af02ac01804de5406a57e665"
|
|
sha256 arm64_big_sur: "a494078486e4cd7669947928da386f1a28a7a30af2c912d58bf5100c35cd99cc"
|
|
sha256 monterey: "aad9b71006368d01c3df14f740d39efd896812e53ba4ece466abaacb5252b335"
|
|
sha256 big_sur: "a774bc0a57c5352c656601267c0b14e8050375eed5fd7f1f10ba63e2b32b73cc"
|
|
sha256 catalina: "415ceeef4d4c3fe947ae7e2e6052afeaef5bf1030bba4eec266862426d0100b2"
|
|
sha256 mojave: "dd4acba981cefba1e0afed9523787b5a865e9e617b227f3e3b74a35b649ba643"
|
|
sha256 x86_64_linux: "4bb4bf85f10336e20ce903f91125ce24efe7dd25b8c9d6e444cd3de156ed3581"
|
|
end
|
|
|
|
keg_only :versioned_formula
|
|
|
|
# https://www.postgresql.org/support/versioning/
|
|
deprecate! date: "2024-11-14", because: :unsupported
|
|
|
|
depends_on "pkg-config" => :build
|
|
depends_on "icu4c"
|
|
|
|
# GSSAPI provided by Kerberos.framework crashes when forked.
|
|
# See https://github.com/Homebrew/homebrew-core/issues/47494.
|
|
depends_on "krb5"
|
|
|
|
depends_on "openssl@1.1"
|
|
depends_on "readline"
|
|
|
|
uses_from_macos "libxml2"
|
|
uses_from_macos "libxslt"
|
|
uses_from_macos "openldap"
|
|
uses_from_macos "perl"
|
|
|
|
on_linux do
|
|
depends_on "linux-pam"
|
|
depends_on "util-linux"
|
|
end
|
|
|
|
def install
|
|
ENV.prepend "LDFLAGS", "-L#{Formula["openssl@1.1"].opt_lib} -L#{Formula["readline"].opt_lib}"
|
|
ENV.prepend "CPPFLAGS", "-I#{Formula["openssl@1.1"].opt_include} -I#{Formula["readline"].opt_include}"
|
|
|
|
args = %W[
|
|
--disable-debug
|
|
--prefix=#{prefix}
|
|
--datadir=#{opt_pkgshare}
|
|
--libdir=#{opt_lib}
|
|
--includedir=#{opt_include}
|
|
--sysconfdir=#{etc}
|
|
--docdir=#{doc}
|
|
--enable-thread-safety
|
|
--with-gssapi
|
|
--with-icu
|
|
--with-ldap
|
|
--with-libxml
|
|
--with-libxslt
|
|
--with-openssl
|
|
--with-pam
|
|
--with-perl
|
|
--with-uuid=e2fs
|
|
]
|
|
if OS.mac?
|
|
args += %w[
|
|
--with-bonjour
|
|
--with-tcl
|
|
]
|
|
end
|
|
|
|
# PostgreSQL by default uses xcodebuild internally to determine this,
|
|
# which does not work on CLT-only installs.
|
|
args << "PG_SYSROOT=#{MacOS.sdk_path}" if MacOS.sdk_root_needed?
|
|
|
|
system "./configure", *args
|
|
|
|
# Work around busted path magic in Makefile.global.in. This can't be specified
|
|
# in ./configure, but needs to be set here otherwise install prefixes containing
|
|
# the string "postgres" will get an incorrect pkglibdir.
|
|
# See https://github.com/Homebrew/homebrew-core/issues/62930#issuecomment-709411789
|
|
system "make", "pkglibdir=#{lib}/postgresql"
|
|
system "make", "install-world", "datadir=#{pkgshare}",
|
|
"libdir=#{lib}",
|
|
"pkglibdir=#{lib}/postgresql",
|
|
"includedir=#{include}",
|
|
"pkgincludedir=#{include}/postgresql",
|
|
"includedir_server=#{include}/postgresql/server",
|
|
"includedir_internal=#{include}/postgresql/internal"
|
|
|
|
if OS.linux?
|
|
inreplace lib/"postgresql/pgxs/src/Makefile.global",
|
|
"LD = #{HOMEBREW_PREFIX}/Homebrew/Library/Homebrew/shims/linux/super/ld",
|
|
"LD = #{HOMEBREW_PREFIX}/bin/ld"
|
|
end
|
|
end
|
|
|
|
def post_install
|
|
(var/"log").mkpath
|
|
postgresql_datadir.mkpath
|
|
|
|
# Don't initialize database, it clashes when testing other PostgreSQL versions.
|
|
return if ENV["HOMEBREW_GITHUB_ACTIONS"]
|
|
|
|
system "#{bin}/initdb", "--locale=C", "-E", "UTF-8", postgresql_datadir unless pg_version_exists?
|
|
end
|
|
|
|
def postgresql_datadir
|
|
var/name
|
|
end
|
|
|
|
def postgresql_log_path
|
|
var/"log/#{name}.log"
|
|
end
|
|
|
|
def pg_version_exists?
|
|
(postgresql_datadir/"PG_VERSION").exist?
|
|
end
|
|
|
|
def old_postgres_data_dir
|
|
var/"postgres"
|
|
end
|
|
|
|
def postgresql_formula_present?
|
|
Formula["postgresql"].any_version_installed?
|
|
end
|
|
|
|
# Figure out what version of PostgreSQL the old data dir is
|
|
# using
|
|
def old_postgresql_datadir_version
|
|
pg_version = old_postgres_data_dir/"PG_VERSION"
|
|
pg_version.exist? && pg_version.read.chomp
|
|
end
|
|
|
|
def caveats
|
|
caveats = ""
|
|
|
|
# Extract the version from the formula name
|
|
pg_formula_version = name.split("@", 2).last
|
|
# ... and check it against the old data dir postgres version number
|
|
# to see if we need to print a warning re: data dir
|
|
if old_postgresql_datadir_version == pg_formula_version
|
|
caveats += if postgresql_formula_present?
|
|
# Both PostgreSQL and PostgreSQL@12 are installed
|
|
<<~EOS
|
|
Previous versions of this formula used the same data directory as
|
|
the regular PostgreSQL formula. This causes a conflict if you
|
|
try to use both at the same time.
|
|
|
|
In order to avoid this conflict, you should make sure that the
|
|
#{name} data directory is located at:
|
|
#{postgresql_datadir}
|
|
|
|
EOS
|
|
else
|
|
# Only PostgreSQL@12 is installed, not PostgreSQL
|
|
<<~EOS
|
|
Previous versions of #{name} used the same data directory as
|
|
the postgresql formula. This will cause a conflict if you
|
|
try to use both at the same time.
|
|
|
|
You can migrate to a versioned data directory by running:
|
|
mv -v "#{old_postgres_data_dir}" "#{postgresql_datadir}"
|
|
|
|
(Make sure PostgreSQL is stopped before executing this command)
|
|
|
|
EOS
|
|
end
|
|
end
|
|
|
|
caveats += <<~EOS
|
|
This formula has created a default database cluster with:
|
|
initdb --locale=C -E UTF-8 #{postgresql_datadir}
|
|
For more details, read:
|
|
https://www.postgresql.org/docs/#{version.major}/app-initdb.html
|
|
EOS
|
|
|
|
caveats
|
|
end
|
|
|
|
service do
|
|
run [opt_bin/"postgres", "-D", var/"postgresql@12"]
|
|
keep_alive true
|
|
log_path var/"log/postgresql@12.log"
|
|
error_log_path var/"log/postgresql@12.log"
|
|
working_dir HOMEBREW_PREFIX
|
|
end
|
|
|
|
test do
|
|
system "#{bin}/initdb", testpath/"test" unless ENV["HOMEBREW_GITHUB_ACTIONS"]
|
|
assert_equal opt_pkgshare.to_s, shell_output("#{bin}/pg_config --sharedir").chomp
|
|
assert_equal opt_lib.to_s, shell_output("#{bin}/pg_config --libdir").chomp
|
|
assert_equal "#{lib}/postgresql", shell_output("#{bin}/pg_config --pkglibdir").chomp
|
|
end
|
|
end
|