164 lines
6.8 KiB
Ruby
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 1
|
|
|
|
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: "e392847c4a6f953f0b8a463a5ab0e90867027f2979b02b9c73237d13565887fd"
|
|
sha256 cellar: :any, arm64_monterey: "878abb2fd55536b49567a32ee20a2cedfee0c848665e802b0bec16219199295f"
|
|
sha256 cellar: :any, arm64_big_sur: "4fd2bc0ef5f2b012f42fa85d42ff275fdefd72a7e7eb4e9fce7e0601f765a5f1"
|
|
sha256 cellar: :any, ventura: "2c0e3d3daf6ec112336bc161209f3558242f4d61bbeb1dc6159d5138ecde5660"
|
|
sha256 cellar: :any, monterey: "e54e26eeeea6ca539902adf62462f4c761373e329a2d9afe88afcebfc55e5128"
|
|
sha256 cellar: :any, big_sur: "f75a88d60aea77a0b9676759c20167fe9ae70f6d971dccb3582e97d9f8674233"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "f1f1ae0e738b09b6220dbbe02dfee56a5325afe9259b15026046bdc00bb16709"
|
|
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
|