homebrew-core/Formula/postgis.rb

164 lines
6.8 KiB
Ruby

class Postgis < Formula
desc "Adds support for geographic objects to PostgreSQL"
homepage "https://postgis.net/"
url "https://download.osgeo.org/postgis/source/postgis-3.3.2.tar.gz"
sha256 "9a2a219da005a1730a39d1959a1c7cec619b1efb009b65be80ffc25bad299068"
license "GPL-2.0-or-later"
revision 2
livecheck do
url "https://download.osgeo.org/postgis/source/"
regex(/href=.*?postgis[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 cellar: :any, arm64_ventura: "3cde54b37a9a7c3c7d9aab6f259111465c6388e2cbccc062063e967d3cef9412"
sha256 cellar: :any, arm64_monterey: "aec65ddab5eaacc23dda2ce0907fc3948acf850b4a0dad038ed95cb7d64f2726"
sha256 cellar: :any, arm64_big_sur: "38af4aaa34598c8ec54e61bef27dda8c669276e3e123535bfc269488f54b40a9"
sha256 cellar: :any, ventura: "8cdcaa0e88d765ccc73f589d845dbe80e43f5bf04a47d48b705539c414d83b3b"
sha256 cellar: :any, monterey: "4885236a19f3ce94d92f9f5479d00c5d2dd3b30e356abe15a499ad812674cccf"
sha256 cellar: :any, big_sur: "869fcfdc0e6b24ccd18712cc6a8f34eafc4d74b7d1bf479258c872c7c0d1bd3e"
sha256 cellar: :any_skip_relocation, x86_64_linux: "2fa798268a282ddd7dec8b2dfe090a2e19877c4cfcde31206ee1ac2fa159ba1f"
end
head do
url "https://git.osgeo.org/gitea/postgis/postgis.git", branch: "master"
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
end
depends_on "gpp" => :build
depends_on "pkg-config" => :build
depends_on "gdal" # for GeoJSON and raster handling
depends_on "geos"
depends_on "json-c" # for GeoJSON and raster handling
depends_on "pcre2"
depends_on "postgresql@14"
depends_on "proj"
depends_on "protobuf-c" # for MVT (map vector tiles) support
depends_on "sfcgal" # for advanced 2D/3D functions
fails_with gcc: "5"
def postgresql
Formula["postgresql@14"]
end
def install
ENV.deparallelize
ENV["PG_CONFIG"] = postgresql.opt_bin/"pg_config"
args = [
"--with-projdir=#{Formula["proj"].opt_prefix}",
"--with-jsondir=#{Formula["json-c"].opt_prefix}",
"--with-pgconfig=#{postgresql.opt_bin}/pg_config",
"--with-protobufdir=#{Formula["protobuf-c"].opt_bin}",
# Unfortunately, NLS support causes all kinds of headaches because
# PostGIS gets all of its compiler flags from the PGXS makefiles. This
# makes it nigh impossible to tell the buildsystem where our keg-only
# gettext installations are.
"--disable-nls",
]
system "./autogen.sh" if build.head?
# Fixes config/install-sh: No such file or directory
# This is caused by a misalignment between ./configure in postgres@14 and postgis
mv "build-aux", "config"
inreplace %w[configure utils/Makefile.in] do |s|
s.gsub! "build-aux", "config"
end
system "./configure", *args
system "make"
# Install to a staging directory to circumvent the hardcoded install paths
# set by the PGXS makefiles.
mkdir "stage"
system "make", "install", "DESTDIR=#{buildpath}/stage"
# Some files are stored in the stage directory with the cellar prefix of
# the version of postgresql used to build postgis. Since we copy these
# files into the postgis keg and symlink them to HOMEBREW_PREFIX, postgis
# only needs to be rebuilt when there is a new major version of postgresql.
postgresql_prefix = postgresql.prefix.realpath
postgresql_stage_path = File.join("stage", postgresql_prefix)
bin.install (buildpath/postgresql_stage_path/"bin").children
doc.install (buildpath/postgresql_stage_path/"share/doc").children
stage_path = File.join("stage", HOMEBREW_PREFIX)
lib.install (buildpath/stage_path/"lib").children
share.install (buildpath/stage_path/"share").children
# Extension scripts
bin.install %w[
utils/create_undef.pl
utils/create_upgrade.pl
utils/postgis_restore.pl
utils/profile_intersects.pl
utils/test_estimation.pl
utils/test_geography_estimation.pl
utils/test_geography_joinestimation.pl
utils/test_joinestimation.pl
]
end
test do
pg_version = postgresql.version.major
expected = /'PostGIS built for PostgreSQL % cannot be loaded in PostgreSQL %',\s+#{pg_version}\.\d,/
postgis_version = Formula["postgis"].version.major_minor
assert_match expected, (share/postgresql.name/"contrib/postgis-#{postgis_version}/postgis.sql").read
require "base64"
(testpath/"brew.shp").write ::Base64.decode64 <<~EOS
AAAnCgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoOgDAAALAAAAAAAAAAAAAAAA
AAAAAADwPwAAAAAAABBAAAAAAAAAFEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAEAAAASCwAAAAAAAAAAAPA/AAAAAAAA8D8AAAAAAAAA
AAAAAAAAAAAAAAAAAgAAABILAAAAAAAAAAAACEAAAAAAAADwPwAAAAAAAAAA
AAAAAAAAAAAAAAADAAAAEgsAAAAAAAAAAAAQQAAAAAAAAAhAAAAAAAAAAAAA
AAAAAAAAAAAAAAQAAAASCwAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAA
AAAAAAAAAAAABQAAABILAAAAAAAAAAAAAAAAAAAAAAAUQAAAAAAAACJAAAAA
AAAAAEA=
EOS
(testpath/"brew.dbf").write ::Base64.decode64 <<~EOS
A3IJGgUAAABhAFsAAAAAAAAAAAAAAAAAAAAAAAAAAABGSVJTVF9GTEQAAEMA
AAAAMgAAAAAAAAAAAAAAAAAAAFNFQ09ORF9GTEQAQwAAAAAoAAAAAAAAAAAA
AAAAAAAADSBGaXJzdCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgIFBvaW50ICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgU2Vjb25kICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICBQb2ludCAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgIFRoaXJkICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgUG9pbnQgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICBGb3VydGggICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgIFBvaW50ICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgQXBwZW5kZWQgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICBQb2ludCAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAg
EOS
(testpath/"brew.shx").write ::Base64.decode64 <<~EOS
AAAnCgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARugDAAALAAAAAAAAAAAAAAAA
AAAAAADwPwAAAAAAABBAAAAAAAAAFEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAADIAAAASAAAASAAAABIAAABeAAAAEgAAAHQAAAASAAAA
igAAABI=
EOS
result = shell_output("#{bin}/shp2pgsql #{testpath}/brew.shp")
assert_match "Point", result
assert_match "AddGeometryColumn", result
pg_ctl = postgresql.opt_bin/"pg_ctl"
psql = postgresql.opt_bin/"psql"
port = free_port
system pg_ctl, "initdb", "-D", testpath/"test"
(testpath/"test/postgresql.conf").write <<~EOS, mode: "a+"
shared_preload_libraries = 'postgis-3'
port = #{port}
EOS
system pg_ctl, "start", "-D", testpath/"test", "-l", testpath/"log"
system psql, "-p", port.to_s, "-c", "CREATE EXTENSION \"postgis\";", "postgres"
system pg_ctl, "stop", "-D", testpath/"test"
end
end