164 lines
6.9 KiB
Ruby
164 lines
6.9 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"
|
|
|
|
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: "246e2d58020634e82f3d52ac473e7568d4d84fa181c14294dd64e293990613d6"
|
|
sha256 cellar: :any, arm64_monterey: "f947a00f2ee58d15d756e4ca72ebaaf0061a82279331244fdc93f7ece2b28d51"
|
|
sha256 cellar: :any, arm64_big_sur: "fd00013b91f5a629436a4b2ba81eadac1a1379e94a68497d6d2295188dd4ac90"
|
|
sha256 cellar: :any, ventura: "bae7340c92e6cd78a484f2803d59b993f416dd9dc481283f21b697b4bc69b684"
|
|
sha256 cellar: :any, monterey: "b333da13061506a1750b18e586d830c143fc5568da5d7a953256ff85d01fee89"
|
|
sha256 cellar: :any, big_sur: "8f90f76a0e17d5aea52ac26f85a0d15aee83d39dd3a0560cf16d076e0fd1766d"
|
|
sha256 cellar: :any, catalina: "95bdd63e81578f93b16f9ef9bfae27904603576b9dffa7b433d97c90c7edd2ac"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "77dd4622cb34e1e98b2502e48b36571f4e41fd1be9f7e1885cfbc01ae4f55c15"
|
|
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
|