geo-libs 1.86 KB
Newer Older
Kenneth Reitz's avatar
Kenneth Reitz committed
1 2 3 4 5 6 7 8 9 10 11 12
#!/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.
13 14 15
VENDORED_GDAL="${VENDOR_URL}/libraries/vendor/gdal.tar.gz"
VENDORED_GEOS="${VENDOR_URL}/libraries/vendor/geos.tar.gz"
VENDORED_PROJ="${VENDOR_URL}/libraries/vendor/proj.tar.gz"
Kenneth Reitz's avatar
Kenneth Reitz committed
16

David Zülke's avatar
David Zülke committed
17
PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
Kenneth Reitz's avatar
Kenneth Reitz committed
18 19

# Syntax sugar.
Kenneth Reitz's avatar
Kenneth Reitz committed
20 21
# shellcheck source=bin/utils
source "$BIN_DIR/utils"
Kenneth Reitz's avatar
Kenneth Reitz committed
22 23 24

# If GDAL exists within requirements, use vendored gdal.
if [[ "$BUILD_WITH_GEO_LIBRARIES" ]]; then
25
  mcount "buildvar.BUILD_WITH_GEO_LIBRARIES"
Kenneth Reitz's avatar
Kenneth Reitz committed
26

27
  if [ ! -f ".heroku/vendor/bin/proj" ]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
28 29 30
    echo "-----> Bootstrapping gdal, geos, proj."
    mkdir -p .heroku/vendor
    # Download and extract cryptography into target vendor directory.
Kenneth Reitz's avatar
Kenneth Reitz committed
31 32 33
    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
Kenneth Reitz's avatar
Kenneth Reitz committed
34

35
    mcount "steps.vendor.geo_libs"
Kenneth Reitz's avatar
Kenneth Reitz committed
36 37 38
    # Copy libjasper from build image to slug.
    if [[ "$STACK" == "heroku-16" ]]; then
      cp /usr/lib/x86_64-linux-gnu/libjasper.so* ".heroku/vendor/lib/."
39
      mcount "steps.vendor.libjasper"
Kenneth Reitz's avatar
Kenneth Reitz committed
40 41
    fi

Kenneth Reitz's avatar
Kenneth Reitz committed
42
  fi
43

Kenneth Reitz's avatar
Kenneth Reitz committed
44 45
  GDAL=$(pwd)/vendor
  export GDAL
46 47 48 49 50 51
  # set path for post_compile hooks
  export GDAL_LIBRARY_PATH="$BUILD_DIR/.heroku/vendor/lib/libgdal.so"
  export GEOS_LIBRARY_PATH="$BUILD_DIR/.heroku/vendor/lib/libgeos_c.so"
  # set path for runtime environmeht
  set_env GDAL_LIBRARY_PATH "/app/.heroku/vendor/lib/libgdal.so"
  set_env GEOS_LIBRARY_PATH "/app/.heroku/vendor/lib/libgeos_c.so"
Kenneth Reitz's avatar
Kenneth Reitz committed
52
fi