homebrew-core/Formula/postgis.rb

162 lines
6.6 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.1.tar.gz"
sha256 "91be800a72d748c5a3a4a00d82ac1de42023e29da61ece6ebf9c77fe228fcb1a"
license "GPL-2.0-or-later"
livecheck do
url "https://download.osgeo.org/postgis/source/"
regex(/href=.*?postgis[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "e5fe038b3276ddbb67285898680fa9a7bab57fba06b5cbfaf2c28e7bed391f78"
sha256 cellar: :any, arm64_big_sur: "903d9ca3d4780d54181571548448f3af022790ee4a554da016baaa3dbbecfad8"
sha256 cellar: :any, monterey: "2235e4b21b778a1797edca8ff4d8c72f013767006fba4b2ec7ed0593d83be291"
sha256 cellar: :any, big_sur: "494dfca989d2a769b535c945315c972fbb46201e27511598fc720cd1223faeae"
sha256 cellar: :any, catalina: "de4bdee3a14da6c61eef5c9e79faf386e00fb4843a75c450b209568d1bd3cdf1"
sha256 cellar: :any_skip_relocation, x86_64_linux: "e1530e5686190eb9d4a012ed6cdd7f2d6dae3798d3a528cb1d21f04e2c701f6f"
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