From eab957c8c96acf1689ca98368a23940f2fe00e97 Mon Sep 17 00:00:00 2001
From: Kenneth Reitz <me@kennethreitz.org>
Date: Fri, 11 Mar 2016 14:58:28 -0500
Subject: [PATCH] BUILD_WITH_GEO_LIBRARIES

---
 bin/compile        |  3 +++
 bin/steps/gdal     |  6 +-----
 bin/steps/geo-libs | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 5 deletions(-)
 create mode 100755 bin/steps/geo-libs

diff --git a/bin/compile b/bin/compile
index 035b36e4..898fc695 100755
--- a/bin/compile
+++ b/bin/compile
@@ -201,6 +201,9 @@ source $BIN_DIR/steps/pylibmc
 # Libffi support.
 source $BIN_DIR/steps/cryptography
 
+# Support for Geo libraries.
+sub-env $BIN_DIR/steps/geo-libs
+
 # GDAL support.
 source $BIN_DIR/steps/gdal
 
diff --git a/bin/steps/gdal b/bin/steps/gdal
index 6f15f4c6..2ebe12ec 100755
--- a/bin/steps/gdal
+++ b/bin/steps/gdal
@@ -11,8 +11,6 @@
 
 # The location of the pre-compiled cryptography binary.
 VENDORED_GDAL="https://lang-python.s3.amazonaws.com/$STACK/libraries/vendor/gdal.tar.gz"
-VENDORED_GEOS="https://lang-python.s3.amazonaws.com/$STACK/libraries/vendor/geos.tar.gz"
-VENDORED_PROJ="https://lang-python.s3.amazonaws.com/$STACK/libraries/vendor/proj.tar.gz"
 
 PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
 
@@ -27,12 +25,10 @@ if (pip-grep -s requirements.txt GDAL gdal pygdal &> /dev/null) then
   if [ -f ".heroku/vendor/bin/gdalserver" ]; then
     export GDAL=$(pwd)/vendor
   else
-    echo "-----> Noticed GDAL. Bootstrapping gdal, geos, proj."
+    echo "-----> Noticed GDAL. Bootstrapping gdal."
     mkdir -p .heroku/vendor
     # Download and extract cryptography into target vendor directory.
     curl $VENDORED_GDAL -s | tar zxv -C .heroku/vendor &> /dev/null
-    curl $VENDORED_GEOS -s | tar zxv -C .heroku/vendor &> /dev/null
-    curl $VENDORED_PROJ -s | tar zxv -C .heroku/vendor &> /dev/null
 
     export GDAL=$(pwd)/vendor
   fi
diff --git a/bin/steps/geo-libs b/bin/steps/geo-libs
new file mode 100755
index 00000000..4a1148f1
--- /dev/null
+++ b/bin/steps/geo-libs
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+# This script serves as the GDAL build step of the
+# [**Python Buildpack**](https://github.com/heroku/heroku-buildpack-python)
+# compiler.
+#
+# A [buildpack](https://devcenter.heroku.com/articles/buildpacks) is an
+# adapter between a Python application and Heroku's runtime.
+#
+# This script is invoked by [`bin/compile`](/).
+
+# The location of the pre-compiled cryptography binary.
+VENDORED_GDAL="https://lang-python.s3.amazonaws.com/$STACK/libraries/vendor/gdal.tar.gz"
+VENDORED_GEOS="https://lang-python.s3.amazonaws.com/$STACK/libraries/vendor/geos.tar.gz"
+VENDORED_PROJ="https://lang-python.s3.amazonaws.com/$STACK/libraries/vendor/proj.tar.gz"
+
+PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
+
+# Syntax sugar.
+source $BIN_DIR/utils
+
+bpwatch start geo_libs_install
+
+# If GDAL exists within requirements, use vendored gdal.
+if [[ "$BUILD_WITH_GEO_LIBRARIES" ]]; then
+
+  if [ -f ".heroku/vendor/bin/gdalserver" ]; then
+    export GDAL=$(pwd)/vendor
+  else
+    echo "-----> Bootstrapping gdal, geos, proj."
+    mkdir -p .heroku/vendor
+    # Download and extract cryptography into target vendor directory.
+    curl $VENDORED_GDAL -s | tar zxv -C .heroku/vendor &> /dev/null
+    curl $VENDORED_GEOS -s | tar zxv -C .heroku/vendor &> /dev/null
+    curl $VENDORED_PROJ -s | tar zxv -C .heroku/vendor &> /dev/null
+
+    export GDAL=$(pwd)/vendor
+  fi
+fi
+
+bpwatch stop geo_libs_install
-- 
GitLab