-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# Postgis formula which depends on an alternate PostgreSQL version. | ||
# | ||
# Generated with: | ||
# brew tap --force homebrew/homebrew-core | ||
# brew extract homebrew/homebrew-core/postgis MercuryTechnologies/homebrew-tap | ||
class Postgis < Formula | ||
desc "Adds support for geographic objects to PostgreSQL" | ||
homepage "https://postgis.net/" | ||
url "https://download.osgeo.org/postgis/source/postgis-3.4.2.tar.gz" | ||
sha256 "c8c874c00ba4a984a87030af6bf9544821502060ad473d5c96f1d4d0835c5892" | ||
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 | ||
|
||
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 "icu4c" | ||
depends_on "json-c" # for GeoJSON and raster handling | ||
depends_on "pcre2" | ||
depends_on "postgresql@16" | ||
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" # C++17 | ||
|
||
def postgresql | ||
Formula["postgresql@16"] | ||
end | ||
|
||
def install | ||
# Work around an Xcode 15 linker issue which causes linkage against LLVM's | ||
# libunwind due to it being present in a library search path. | ||
if DevelopmentTools.clang_build_version >= 1500 | ||
recursive_dependencies | ||
.select { |d| d.name.match?(/^llvm(@\d+)?$/) } | ||
.map { |llvm_dep| llvm_dep.to_formula.opt_lib } | ||
.each { |llvm_lib| ENV.remove "HOMEBREW_LIBRARY_PATHS", llvm_lib } | ||
end | ||
|
||
ENV.deparallelize | ||
|
||
# C++17 is required. | ||
ENV.append "CXXFLAGS", "-std=c++17" | ||
|
||
# Workaround for: Built-in generator --c_out specifies a maximum edition | ||
# PROTO3 which is not the protoc maximum 2023. | ||
# Remove when fixed in `protobuf-c`: | ||
# https://github.com/protobuf-c/protobuf-c/pull/711 | ||
ENV["PROTOCC"] = Formula["protobuf"].opt_bin/"protoc" | ||
|
||
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? | ||
# Pretend to install into HOMEBREW_PREFIX to allow PGXS to find PostgreSQL binaries | ||
system "./configure", *args, *std_configure_args(prefix: HOMEBREW_PREFIX) | ||
system "make" | ||
# Override the hardcoded install paths set by the PGXS makefiles | ||
system "make", "install", "bindir=#{bin}", | ||
"docdir=#{doc}", | ||
"mandir=#{man}", | ||
"pkglibdir=#{lib/postgresql.name}", | ||
"datadir=#{share/postgresql.name}", | ||
"PG_SHAREDIR=#{share/postgresql.name}" | ||
|
||
# Extension scripts | ||
bin.install %w[ | ||
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 |