Last active
July 20, 2022 12:32
-
-
Save jec006/014ac76593bfceaebea8ed6e64ab618e to your computer and use it in GitHub Desktop.
Postgis Formula using Postgres 13
This file contains hidden or 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
class Postgis < Formula | |
desc "Adds support for geographic objects to PostgreSQL" | |
homepage "https://postgis.net/" | |
url "https://download.osgeo.org/postgis/source/postgis-3.2.1.tar.gz" | |
sha256 "fbab68dde6ca3934b24ba08c8ab0cff2594f57f93deab41a15c82ae1bb69893e" | |
license "GPL-2.0-or-later" | |
revision 5 | |
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: "1af079e34a2e4a2becfa5eed12e9300f3d320f3155d119671dce965a7a0ce278" | |
sha256 cellar: :any, arm64_big_sur: "77e71bc31a5c2006bb7bb9b0cc2fec2c63eba5ec22a44bf8b4627fe881260571" | |
sha256 cellar: :any, monterey: "05de01ea7cd23c574835ab54be6ae42fd10a0bd597fa52820b91f83e32fc1657" | |
sha256 cellar: :any, big_sur: "37feb757f1256e15df2c4d9f647a42171cec604b56e8398ebe3a7d2fba1d1d2b" | |
sha256 cellar: :any, catalina: "2147c60af3abf6d0a62fbf3c3c2867c92a69d30aa53b4a94a17f214620922c99" | |
sha256 cellar: :any_skip_relocation, x86_64_linux: "5dd2180459ddba0c0656ea9884f2ca77e2ff155246f51f13018dae88215a4618" | |
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@13" | |
depends_on "proj" | |
depends_on "protobuf-c" # for MVT (map vector tiles) support | |
depends_on "sfcgal" # for advanced 2D/3D functions | |
on_linux do | |
depends_on "gcc" | |
end | |
fails_with gcc: "5" | |
def install | |
ENV.deparallelize | |
args = [ | |
"--with-projdir=#{Formula["proj"].opt_prefix}", | |
"--with-jsondir=#{Formula["json-c"].opt_prefix}", | |
"--with-pgconfig=#{Formula["postgresql@13"].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? | |
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 = Formula["postgresql@13"].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/postgis_proc_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 = Formula["postgresql@13"].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/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 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment