|
| 1 | +class PostgresqlAT17 < Formula |
| 2 | + desc "Object-relational database system" |
| 3 | + homepage "https://www.postgresql.org/" |
| 4 | + url "https://ftp.postgresql.org/pub/source/v17.0/postgresql-17.0.tar.bz2" |
| 5 | + sha256 "7e276131c0fdd6b62588dbad9b3bb24b8c3498d5009328dba59af16e819109de" |
| 6 | + license "PostgreSQL" |
| 7 | + |
| 8 | + livecheck do |
| 9 | + url "https://ftp.postgresql.org/pub/source/" |
| 10 | + regex(%r{href=["']?v?(17(?:\.\d+)+)/?["' >]}i) |
| 11 | + end |
| 12 | + |
| 13 | + bottle do |
| 14 | + sha256 arm64_sequoia: "7345b4a703b655b5ef7bcb37a3dbc90b5406e4d06e7c4b8d30f8bd43f8499974" |
| 15 | + sha256 arm64_sonoma: "34876e4d4b26909d79f757d60f7cb34c6e2531c03120f103f5063a6cf62facd3" |
| 16 | + sha256 arm64_ventura: "f2facfda470d494aea051eb64ba54c60171e5866fa032ef7c3fba3b488a69f13" |
| 17 | + sha256 sonoma: "a5258e4c8218b8ba6d91bb368581548042dc618e07a788e19d0fdf6b7297d7fd" |
| 18 | + sha256 ventura: "e25fa2f7a5dc496172f262913071f1a85ce03711b1edfd41a8e9f4a38d2c0b2e" |
| 19 | + sha256 x86_64_linux: "3a5e1daf6f1cef652cb39b869e0d8490c3bf29fcadc1869fbe7c92a7f37d6810" |
| 20 | + end |
| 21 | + |
| 22 | + keg_only :versioned_formula |
| 23 | + |
| 24 | + # https://www.postgresql.org/support/versioning/ |
| 25 | + deprecate! date: "2029-11-08", because: :unsupported |
| 26 | + |
| 27 | + depends_on "docbook" => :build |
| 28 | + depends_on "docbook-xsl" => :build |
| 29 | + depends_on "gettext" => :build |
| 30 | + depends_on "pkg-config" => :build |
| 31 | + depends_on "icu4c" |
| 32 | + # GSSAPI provided by Kerberos.framework crashes when forked. |
| 33 | + # See https://github.com/Homebrew/homebrew-core/issues/47494. |
| 34 | + depends_on "krb5" |
| 35 | + depends_on "lz4" |
| 36 | + depends_on "openssl@3" |
| 37 | + depends_on "readline" |
| 38 | + depends_on "zstd" |
| 39 | + |
| 40 | + uses_from_macos "bison" => :build |
| 41 | + uses_from_macos "flex" => :build |
| 42 | + uses_from_macos "libxml2" |
| 43 | + uses_from_macos "libxslt" |
| 44 | + uses_from_macos "openldap" |
| 45 | + uses_from_macos "perl" |
| 46 | + uses_from_macos "zlib" |
| 47 | + |
| 48 | + on_macos do |
| 49 | + depends_on "gettext" |
| 50 | + end |
| 51 | + |
| 52 | + on_linux do |
| 53 | + depends_on "linux-pam" |
| 54 | + depends_on "util-linux" |
| 55 | + end |
| 56 | + |
| 57 | + def install |
| 58 | + # Modify Makefile to link macOS binaries using Cellar path. Otherwise, binaries are linked |
| 59 | + # using #{HOMEBREW_PREFIX}/lib path set during ./configure, which will cause audit failures |
| 60 | + # for broken linkage as the paths are not created until post-install step. |
| 61 | + inreplace "src/Makefile.shlib", "-install_name '$(libdir)/", "-install_name '#{lib}/postgresql/" |
| 62 | + |
| 63 | + ENV["XML_CATALOG_FILES"] = etc/"xml/catalog" |
| 64 | + ENV.delete "PKG_CONFIG_LIBDIR" |
| 65 | + ENV.prepend "LDFLAGS", "-L#{Formula["openssl@3"].opt_lib} -L#{Formula["readline"].opt_lib}" |
| 66 | + ENV.prepend "CPPFLAGS", "-I#{Formula["openssl@3"].opt_include} -I#{Formula["readline"].opt_include}" |
| 67 | + |
| 68 | + # Fix 'libintl.h' file not found for extensions |
| 69 | + if OS.mac? |
| 70 | + ENV.prepend "LDFLAGS", "-L#{Formula["gettext"].opt_lib}" |
| 71 | + ENV.prepend "CPPFLAGS", "-I#{Formula["gettext"].opt_include}" |
| 72 | + end |
| 73 | + |
| 74 | + args = std_configure_args + %W[ |
| 75 | + --datadir=#{HOMEBREW_PREFIX}/share/#{name} |
| 76 | + --libdir=#{HOMEBREW_PREFIX}/lib/#{name} |
| 77 | + --includedir=#{HOMEBREW_PREFIX}/include/#{name} |
| 78 | + --sysconfdir=#{etc} |
| 79 | + --docdir=#{doc} |
| 80 | + --enable-nls |
| 81 | + --enable-thread-safety |
| 82 | + --with-gssapi |
| 83 | + --with-icu |
| 84 | + --with-ldap |
| 85 | + --with-libxml |
| 86 | + --with-libxslt |
| 87 | + --with-lz4 |
| 88 | + --with-zstd |
| 89 | + --with-openssl |
| 90 | + --with-pam |
| 91 | + --with-perl |
| 92 | + --with-uuid=e2fs |
| 93 | + --with-extra-version=\ (#{tap.user}) |
| 94 | + ] |
| 95 | + args += %w[--with-bonjour --with-tcl] if OS.mac? |
| 96 | + |
| 97 | + # PostgreSQL by default uses xcodebuild internally to determine this, |
| 98 | + # which does not work on CLT-only installs. |
| 99 | + args << "PG_SYSROOT=#{MacOS.sdk_path}" if OS.mac? && MacOS.sdk_root_needed? |
| 100 | + |
| 101 | + system "./configure", *args |
| 102 | + system "make" |
| 103 | + # We use an unversioned `postgresql` subdirectory rather than `#{name}` so that the |
| 104 | + # post-installed symlinks can use non-conflicting `#{name}` and be retained on `brew unlink`. |
| 105 | + # Removing symlinks may break PostgreSQL as its binaries expect paths from ./configure step. |
| 106 | + system "make", "install-world", "datadir=#{share}/postgresql", |
| 107 | + "libdir=#{lib}/postgresql", |
| 108 | + "includedir=#{include}/postgresql" |
| 109 | + |
| 110 | + # Modify the Makefile back so dependents pick up common path |
| 111 | + makefile = lib/"postgresql/pgxs/src/Makefile.shlib" |
| 112 | + inreplace makefile, "-install_name '#{lib}/postgresql/", "-install_name '$(libdir)/" |
| 113 | + end |
| 114 | + |
| 115 | + def post_install |
| 116 | + (var/"log").mkpath |
| 117 | + postgresql_datadir.mkpath |
| 118 | + |
| 119 | + # Manually link files from keg to non-conflicting versioned directories in HOMEBREW_PREFIX. |
| 120 | + %w[include lib share].each do |dir| |
| 121 | + dst_dir = HOMEBREW_PREFIX/dir/name |
| 122 | + src_dir = prefix/dir/"postgresql" |
| 123 | + src_dir.find do |src| |
| 124 | + dst = dst_dir/src.relative_path_from(src_dir) |
| 125 | + |
| 126 | + # Retain existing real directories for extensions if directory structure matches |
| 127 | + next if dst.directory? && !dst.symlink? && src.directory? && !src.symlink? |
| 128 | + |
| 129 | + rm_r(dst) if dst.exist? || dst.symlink? |
| 130 | + if src.symlink? || src.file? |
| 131 | + Find.prune if src.basename.to_s == ".DS_Store" |
| 132 | + dst.parent.install_symlink src |
| 133 | + elsif src.directory? |
| 134 | + dst.mkpath |
| 135 | + end |
| 136 | + end |
| 137 | + end |
| 138 | + |
| 139 | + # Also link versioned executables |
| 140 | + bin.each_child { |f| (HOMEBREW_PREFIX/"bin").install_symlink f => "#{f.basename}-#{version.major}" } |
| 141 | + |
| 142 | + # Don't initialize database, it clashes when testing other PostgreSQL versions. |
| 143 | + return if ENV["HOMEBREW_GITHUB_ACTIONS"] |
| 144 | + |
| 145 | + system bin/"initdb", "--locale=C", "-E", "UTF-8", postgresql_datadir unless pg_version_exists? |
| 146 | + end |
| 147 | + |
| 148 | + def postgresql_datadir |
| 149 | + var/name |
| 150 | + end |
| 151 | + |
| 152 | + def postgresql_log_path |
| 153 | + var/"log/#{name}.log" |
| 154 | + end |
| 155 | + |
| 156 | + def pg_version_exists? |
| 157 | + (postgresql_datadir/"PG_VERSION").exist? |
| 158 | + end |
| 159 | + |
| 160 | + def caveats |
| 161 | + <<~EOS |
| 162 | + This formula has created a default database cluster with: |
| 163 | + initdb --locale=C -E UTF-8 #{postgresql_datadir} |
| 164 | + For more details, read: |
| 165 | + https://www.postgresql.org/docs/#{version.major}/app-initdb.html |
| 166 | + EOS |
| 167 | + end |
| 168 | + |
| 169 | + service do |
| 170 | + run [opt_bin/"postgres", "-D", f.postgresql_datadir] |
| 171 | + environment_variables LC_ALL: "C" |
| 172 | + keep_alive true |
| 173 | + log_path f.postgresql_log_path |
| 174 | + error_log_path f.postgresql_log_path |
| 175 | + working_dir HOMEBREW_PREFIX |
| 176 | + end |
| 177 | + |
| 178 | + test do |
| 179 | + system bin/"initdb", testpath/"test" unless ENV["HOMEBREW_GITHUB_ACTIONS"] |
| 180 | + [bin/"pg_config", HOMEBREW_PREFIX/"bin/pg_config-#{version.major}"].each do |pg_config| |
| 181 | + assert_equal "#{HOMEBREW_PREFIX}/share/#{name}", shell_output("#{pg_config} --sharedir").chomp |
| 182 | + assert_equal "#{HOMEBREW_PREFIX}/lib/#{name}", shell_output("#{pg_config} --libdir").chomp |
| 183 | + assert_equal "#{HOMEBREW_PREFIX}/lib/#{name}", shell_output("#{pg_config} --pkglibdir").chomp |
| 184 | + assert_equal "#{HOMEBREW_PREFIX}/include/#{name}", shell_output("#{pg_config} --pkgincludedir").chomp |
| 185 | + assert_equal "#{HOMEBREW_PREFIX}/include/#{name}/server", shell_output("#{pg_config} --includedir-server").chomp |
| 186 | + assert_match "-I#{Formula["gettext"].opt_include}", shell_output("#{pg_config} --cppflags") if OS.mac? |
| 187 | + end |
| 188 | + end |
| 189 | +end |
0 commit comments