pgadmin4/pkg/mac/build.sh

274 lines
10 KiB
Bash
Raw Normal View History

2016-06-02 07:56:56 -05:00
#!/bin/bash
# Build script to create Mac App Bundle and DMG for pgAdmin4 runtime
export WD=$(cd `dirname $0` && pwd)
2019-03-21 09:02:19 -05:00
export SOURCEDIR=${WD}/../..
export BUILDROOT=${WD}/../../mac-build
export DISTROOT=${WD}/../../dist
2016-06-02 07:56:56 -05:00
export VIRTUALENV=venv
2019-03-21 09:02:19 -05:00
if [ ! -f ${SOURCEDIR}/pkg/mac/framework.conf ]; then
echo
echo "Error: pkg/mac/framework.conf not found!"
echo "Copy pkg/mac/framework.conf.in to pkg/mac/framework.conf and edit as required for the current system."
echo
exit 1
fi
export SYSTEM_PYTHON=0
2019-03-21 09:02:19 -05:00
if [ "x${PYTHON_HOME}" == "x" ]; then
2016-06-02 07:56:56 -05:00
echo "PYTHON_HOME not set. Setting it to default"
export PYTHON_HOME=/System/Library/Frameworks/Python.framework/Versions/2.7
export PYTHON_VERSION=27
export SYSTEM_PYTHON=1
2016-06-02 07:56:56 -05:00
fi
# Check if Python is working and calculate PYTHON_VERSION
2019-03-21 09:02:19 -05:00
if ${PYTHON_HOME}/bin/python2 -V > /dev/null 2>&1; then
export PYTHON_VERSION=`${PYTHON_HOME}/bin/python2 -V 2>&1 | awk '{print $2}' | cut -d"." -f1-2 | sed 's/\.//'`
elif ${PYTHON_HOME}/bin/python3 -V > /dev/null 2>&1; then
export PYTHON_VERSION=`${PYTHON_HOME}/bin/python3 -V 2>&1 | awk '{print $2}' | cut -d"." -f1-2 | sed 's/\.//'`
2016-06-02 07:56:56 -05:00
else
echo "Error: Python installation missing!"
exit 1
fi
2019-03-21 09:02:19 -05:00
if [ "${PYTHON_VERSION}" -gt "37" -a "${PYTHON_VERSION}" -lt "27" ]; then
2016-06-02 07:56:56 -05:00
echo "Python version not supported"
exit 1
fi
2019-03-21 09:02:19 -05:00
if [ "${PYTHON_VERSION}" -ge "30" ]; then
export PYTHON=${PYTHON_HOME}/bin/python3
2016-06-02 07:56:56 -05:00
export PIP=pip3
else
2019-03-21 09:02:19 -05:00
export PYTHON=${PYTHON_HOME}/bin/python2
2016-06-02 07:56:56 -05:00
export PIP=pip
fi
2019-03-21 09:02:19 -05:00
if [ "x${QTDIR}" == "x" ]; then
2016-06-02 07:56:56 -05:00
echo "QTDIR not set. Setting it to default"
export QTDIR=~/Qt/5.8/clang_64
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
export QMAKE=${QTDIR}/bin/qmake
if ! ${QMAKE} --version > /dev/null 2>&1; then
2016-06-02 07:56:56 -05:00
echo "Error: qmake not found. QT installation is not present or incomplete."
exit 1
fi
2019-03-21 09:02:19 -05:00
if [ "x${PGDIR}" == "x" ]; then
2016-06-02 07:56:56 -05:00
echo "PGDIR not set. Setting it to default"
export PGDIR=/usr/local/pgsql
fi
_get_version() {
export APP_RELEASE=`grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g'`
export APP_REVISION=`grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g'`
export APP_NAME=`grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //'`
2019-03-21 09:02:19 -05:00
export APP_BUNDLE_NAME=${APP_NAME}.app
export APP_LONG_VERSION=${APP_RELEASE}.${APP_REVISION}
export APP_SHORT_VERSION=`echo ${APP_LONG_VERSION} | cut -d . -f1,2`
2016-06-02 07:56:56 -05:00
export APP_SUFFIX=`grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g"`
2019-03-21 09:02:19 -05:00
if [ ! -z ${APP_SUFFIX} ]; then
export APP_LONG_VERSION=${APP_LONG_VERSION}-${APP_SUFFIX}
2016-06-02 07:56:56 -05:00
fi
}
_cleanup() {
echo "Cleaning up the old environment and app bundle"
2019-03-21 09:02:19 -05:00
rm -rf ${SOURCEDIR}/runtime/pgAdmin4.app
rm -rf ${BUILDROOT}
rm -f ${DISTROOT}/pgadmin4*.dmg
2016-06-02 07:56:56 -05:00
}
_create_python_virtualenv() {
2019-03-21 09:02:19 -05:00
export PATH=${PGDIR}/bin:${PATH}
export LD_LIBRARY_PATH=${PGDIR}/lib:${LD_LIBRARY_PATH}
test -d ${BUILDROOT} || mkdir ${BUILDROOT} || exit 1
cd ${BUILDROOT}
2019-03-21 09:02:19 -05:00
if [ ${SYSTEM_PYTHON} -eq 1 ]; then
test -d ${VIRTUALENV} || virtualenv -p ${PYTHON} ${VIRTUALENV} || exit 1
else
2019-03-21 09:02:19 -05:00
test -d ${VIRTUALENV} || virtualenv -p ${PYTHON} --always-copy ${VIRTUALENV} || exit 1
fi
2019-03-21 09:02:19 -05:00
source ${VIRTUALENV}/bin/activate
${PIP} install --no-cache-dir --no-binary psycopg2 -r ${SOURCEDIR}/requirements.txt || { echo PIP install failed. Please resolve the issue and rerun the script; exit 1; }
2016-06-02 07:56:56 -05:00
# Figure out some paths for use when completing the venv
# Use "python" here as we want the venv path
2016-06-02 07:56:56 -05:00
export PYMODULES_PATH=`python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"`
2019-03-21 09:02:19 -05:00
export DIR_PYMODULES_PATH=`dirname ${PYMODULES_PATH}`
# Use $PYTHON here as we want the system path
2019-03-21 09:02:19 -05:00
export PYSYSLIB_PATH=`${PYTHON} -c "import sys; print('%s/lib/python%d.%.d' % (sys.prefix, sys.version_info.major, sys.version_info.minor))"`
# Symlink in the rest of the Python libs. This is required because the runtime
# will clear PYTHONHOME for safety, which has the side-effect of preventing
2018-05-02 06:05:17 -05:00
# it from finding modules that are not explicitly included in the venv
2019-03-21 09:02:19 -05:00
cd ${DIR_PYMODULES_PATH}
# Files
2019-03-21 09:02:19 -05:00
for FULLPATH in ${PYSYSLIB_PATH}/*.py; do
FILE=${FULLPATH##*/}
2019-03-21 09:02:19 -05:00
if [ ! -e ${FILE} ]; then
if [ ${SYSTEM_PYTHON} -eq 1 ]; then
ln -s ${FULLPATH} ${FILE}
else
2019-03-21 09:02:19 -05:00
cp ${FULLPATH} ${FILE}
fi
fi
done
# Paths
2019-03-21 09:02:19 -05:00
for FULLPATH in ${PYSYSLIB_PATH}/*/; do
FULLPATH=${FULLPATH%*/}
FILE=${FULLPATH##*/}
2019-03-21 09:02:19 -05:00
if [ ! -e ${FILE} ]; then
if [ ${SYSTEM_PYTHON} -eq 1 ]; then
ln -s ${FULLPATH} ${FILE}
else
2019-03-21 09:02:19 -05:00
cp -R ${FULLPATH} ${FILE}
fi
fi
done
# Remove tests
cd site-packages
find . -name "test" -type d -exec rm -rf "{}" \;
find . -name "tests" -type d -exec rm -rf "{}" \;
# Link the python<version> directory to python so that the private environment path is found by the application.
2019-03-21 09:02:19 -05:00
if test -d ${DIR_PYMODULES_PATH}; then
ln -s $(basename ${DIR_PYMODULES_PATH}) ${DIR_PYMODULES_PATH}/../python
2016-06-02 07:56:56 -05:00
fi
}
_build_runtime() {
_create_python_virtualenv || exit 1
2019-03-21 09:02:19 -05:00
cd ${SOURCEDIR}/runtime
make clean
2019-03-21 09:02:19 -05:00
${QMAKE} || { echo qmake failed; exit 1; }
2016-06-02 07:56:56 -05:00
make || { echo make failed; exit 1; }
2019-03-21 09:02:19 -05:00
cp -r pgAdmin4.app "${BUILDROOT}/${APP_BUNDLE_NAME}"
2016-06-02 07:56:56 -05:00
}
_build_doc() {
2019-03-21 09:02:19 -05:00
cd ${SOURCEDIR}/docs/en_US
test -d "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources" || "mkdir -p ${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources"
test -d "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/docs/en_US" || mkdir -p "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/docs/en_US"
cp -r _build/html "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/docs/en_US/" || exit 1
2016-06-02 07:56:56 -05:00
}
_complete_bundle() {
2019-03-21 09:02:19 -05:00
cd ${SOURCEDIR}/pkg/mac
# Copy the binary utilities into place
2019-03-21 09:02:19 -05:00
mkdir -p "${BUILDROOT/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
cp "${PGDIR}/bin/pg_dump" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
cp "${PGDIR}/bin/pg_dumpall" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
cp "${PGDIR}/bin/pg_restore" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
cp "${PGDIR}/bin/psql" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
2016-06-02 07:56:56 -05:00
# Replace the place holders with the current version
2019-03-21 09:02:19 -05:00
sed -e "s/PGADMIN_LONG_VERSION/${APP_LONG_VERSION}/g" -e "s/PGADMIN_SHORT_VERSION/${APP_SHORT_VERSION}/g" pgadmin.Info.plist.in > pgadmin.Info.plist
2016-06-02 07:56:56 -05:00
# copy Python private environment to app bundle
2019-03-21 09:02:19 -05:00
cp -PR ${BUILDROOT}/${VIRTUALENV} "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/" || exit 1
2016-06-02 07:56:56 -05:00
2019-03-21 09:02:19 -05:00
if [ ${SYSTEM_PYTHON} -eq 1 ]; then
# remove the python bin and include from app bundle as it is not needed
2019-03-21 09:02:19 -05:00
rm -rf "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/${VIRTUALENV}/bin" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/${VIRTUALENV}/include"
rm -rf "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/${VIRTUALENV}/.Python"
fi
# Remove any TCL-related files that may cause us problems
2019-03-21 09:02:19 -05:00
find "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/${VIRTUALENV}/" -name "_tkinter*" -exec rm -f "{}" \;
2016-06-02 07:56:56 -05:00
# run complete-bundle to copy the dependent libraries and frameworks and fix the rpaths
2019-03-21 09:02:19 -05:00
./complete-bundle.sh "${BUILDROOT}/${APP_BUNDLE_NAME}" || { echo complete-bundle.sh failed; exit 1; }
2016-06-02 07:56:56 -05:00
2019-03-21 09:02:19 -05:00
pushd ${SOURCEDIR}/web
yarn install || exit 1
yarn run bundle || exit 1
curl https://curl.haxx.se/ca/cacert.pem -o cacert.pem -s || { echo Failed to download cacert.pem; exit 1; }
popd
2016-06-02 07:56:56 -05:00
# copy the web directory to the bundle as it is required by runtime
2019-03-21 09:02:19 -05:00
cp -r ${SOURCEDIR}/web "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/" || exit 1
cd "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/web"
2016-06-02 07:56:56 -05:00
rm -f pgadmin4.db config_local.*
rm -rf karma.conf.js package.json node_modules/ regression/ tools/ pgadmin/static/js/generated/.cache
find . -name "tests" -type d -exec rm -rf "{}" \;
find . -name "feature_tests" -type d -exec rm -rf "{}" \;
find . -name ".DS_Store" -exec rm -f "{}" \;
echo "SERVER_MODE = False" > config_distro.py
echo "HELP_PATH = '../../../docs/en_US/html/'" >> config_distro.py
2016-11-23 07:38:17 -06:00
echo "DEFAULT_BINARY_PATHS = {" >> config_distro.py
2016-11-23 07:43:12 -06:00
echo " 'pg': '\$DIR/../../SharedSupport'," >> config_distro.py
2016-11-23 07:38:17 -06:00
echo " 'ppas': ''" >> config_distro.py
echo "}" >> config_distro.py
2016-06-02 07:56:56 -05:00
# Remove the .pyc files if any
2019-03-21 09:02:19 -05:00
cd "${BUILDROOT}/${APP_BUNDLE_NAME}"
2016-10-04 07:51:28 -05:00
find . -name *.pyc | xargs rm -f
2016-06-02 07:56:56 -05:00
}
_framework_config() {
2019-03-21 09:02:19 -05:00
cd ${SOURCEDIR}/pkg/mac
./framework-config.sh "${BUILDROOT}/${APP_BUNDLE_NAME}" || { echo "framework-config.sh failed"; exit 1; }
}
_codesign_bundle() {
2019-03-21 09:02:19 -05:00
cd ${SOURCEDIR}/pkg/mac
if [ ! -f codesign.conf ]; then
echo
echo "******************************************************************"
echo "* codesign.conf not found. NOT signing the bundle."
echo "******************************************************************"
echo
sleep 5
return
fi
2019-03-21 09:02:19 -05:00
./codesign-bundle.sh "${BUILDROOT}/${APP_BUNDLE_NAME}" || { echo codesign-bundle.sh failed; exit 1; }
}
2016-06-02 07:56:56 -05:00
_create_dmg() {
2019-03-21 09:02:19 -05:00
cd ${SOURCEDIR}
2016-06-02 07:56:56 -05:00
./pkg/mac/create-dmg.sh || { echo create-dmg.sh failed; exit 1; }
# Clean the mac-build/ on successful build
2019-03-21 09:02:19 -05:00
rm -rf ${BUILDROOT}/*
2016-06-02 07:56:56 -05:00
}
_codesign_dmg() {
2019-03-21 09:02:19 -05:00
cd ${SOURCEDIR}/pkg/mac
if [ ! -f codesign.conf ]; then
echo
echo "******************************************************************"
echo "* codesign.conf not found. NOT signing the disk image."
echo "******************************************************************"
echo
sleep 5
return
fi
./codesign-dmg.sh || { echo codesign-bundle.sh failed; exit 1; }
}
2016-06-02 07:56:56 -05:00
_get_version || { echo Could not get versioning; exit 1; }
_cleanup
_build_runtime || { echo Runtime build failed; exit 1; }
_build_doc
_complete_bundle
_framework_config
_codesign_bundle
2016-06-02 07:56:56 -05:00
_create_dmg
_codesign_dmg