Commit 20f6073c authored by Ivan Yossi's avatar Ivan Yossi 👌 Committed by Ashwin Dhakaita

packaging osx: Add Python as Framework

a Python.Framework install precompiles all python files and
also behaves better with code signing process.

To migrate:
- rebuild ext_python ext_sip ext_pyqt
- remove from BUILDROOT/i/lib python3.5 directory
parent e65dd730
......@@ -21,26 +21,18 @@ if (UNIX)
UPDATE_COMMAND ""
)
else(APPLE)
find_package(PythonInterp 3.5)
if(NOT PYTHONINTERP_FOUND)
SET(PYTHON_EXECUTABLE ${PREFIX_ext_sip}/bin/python3)
if(NOT EXISTS "${PYTHON_EXECUTABLE}")
message("WARNING: using system python3!")
SET(PYTHON_EXECUTABLE python3)
endif()
# Get PYTHONVERSION
execute_process(COMMAND ${PYTHON_EXECUTABLE} -V COMMAND awk "{print $2}" OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHON_VERSION})
list(GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list(GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
endif()
set(PY_VER "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
ExternalProject_Add( ext_sip
DOWNLOAD_DIR ${EXTERNALS_DOWNLOAD_DIR}
URL https://www.riverbankcomputing.com/static/Downloads/sip/4.19.15/sip-4.19.15.tar.gz
URL_MD5 236578d2199da630ae1251671b9a7bfe
URL https://www.riverbankcomputing.com/static/Downloads/sip/sip-4.19.14.tar.gz
URL_MD5 bba62b2ea7e16193c7dfcfadb8dd0d05
CMAKE_ARGS -DPYTHON_INCLUDE_DIR=${PREFIX_ext_sip}/lib/Python.framework/Headers
CONFIGURE_COMMAND ${PYTHON_EXECUTABLE} <SOURCE_DIR>/configure.py --deployment-target=10.11
......@@ -48,6 +40,8 @@ if (UNIX)
-e ${PREFIX_ext_sip}/include --sipdir ${PREFIX_ext_sip}/share/sip --target-py-version 3.5 --sip-module PyQt5.sip
BUILD_COMMAND make
INSTALL_COMMAND make install
COMMAND ${CMAKE_COMMAND} -E copy ${PREFIX_ext_sip}/sip/PyQt5/sip.so ${PREFIX_ext_sip}/lib/python${PY_VER}/site-packages/PyQt5/sip.so
COMMAND ${CMAKE_COMMAND} -E copy ${PREFIX_ext_sip}/sip/PyQt5/sip.pyi ${PREFIX_ext_sip}/lib/python${PY_VER}/site-packages/PyQt5/sip.pyi
BUILD_IN_SOURCE 1
......
......@@ -358,6 +358,7 @@ set_krita_dirs() {
# build_krita
# run cmake krita
build_krita () {
export DYLD_FRAMEWORK_PATH=${FRAMEWORK_PATH}
export DYLD_FRAMEWORK_PATH=${FRAMEWORK_PATH}
echo ${KIS_BUILD_DIR}
echo ${KIS_INSTALL_DIR}
......@@ -374,7 +375,7 @@ build_krita () {
-DKDE_INSTALL_BUNDLEDIR=${KIS_INSTALL_DIR}/bin \
-DPYQT_SIP_DIR_OVERRIDE=${KIS_INSTALL_DIR}/share/sip/ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11
-DPYTHON_INCLUDE_DIR=${KIS_INSTALL_DIR}/lib/Python.framework/Headers
# copiling phase
......@@ -450,24 +451,24 @@ fix_boost_rpath () {
fi
done
}
batch_fixboost() {
xargs -P4 -I FILE bash -c 'fixboost_find "FILE"'
}
export -f fixboost_find
export -f log
export -f log_cmd
print_msg "Fixing boost in... ${KIS_INSTALL_DIR}"
# install_name_tool -add_rpath ${KIS_INSTALL_DIR}/lib $BUILDROOT/$KRITA_INSTALL/bin/krita.app/Contents/MacOS/gmic_krita_qt
log_cmd install_name_tool -add_rpath ${KIS_INSTALL_DIR}/lib ${KIS_INSTALL_DIR}/bin/krita.app/Contents/MacOS/krita
# echo "Added rpath ${KIS_INSTALL_DIR}/lib to krita bin"
# install_name_tool -add_rpath ${BUILDROOT}/deps/lib ${KIS_INSTALL_DIR}/bin/krita.app/Contents/MacOS/krita
log_cmd install_name_tool -change libboost_system.dylib @rpath/libboost_system.dylib ${KIS_INSTALL_DIR}/bin/krita.app/Contents/MacOS/krita
# import site
find -L "${KIS_INSTALL_DIR}" -name '*so' -o -name '*dylib' | batch_fixboost
# site.addsitedir(os.path.join(framework_path,'site-packages'))
# site.addsitedir(os.path.join(framework_path,'site-packages', 'PyQt5'))
# " \
# > ${PythonLibDir}/sitecustomize.py
# fi
log "Fixing boost done!"
}
......
......@@ -273,6 +273,38 @@ strip_python_dmginstall() {
rm -rf distutils tkinter ensurepip venv lib2to3 idlelib
}
fix_python_framework() {
# Fix python.framework rpath and slims down installation
# fix library LD_RPATH excutable_path and loader_path.
# It is intended to be used for Libraries inside Frameworks.
fix_framework_library() {
xargs -P4 -I FILE sh -c "
install_name_tool -rpath ${KIS_INSTALL_DIR}/lib @loader_path/Frameworks \"${libFile}\" 2> /dev/null
install_name_tool -add_rpath @loader_path/../../../ \"${libFile}\" 2> /dev/null
"
}
# Start fixing all executables
PythonFrameworkBase="${KRITA_DMG}/krita.app/Contents/Frameworks/Python.framework"
install_name_tool -change @loader_path/../../../../libintl.9.dylib @loader_path/../../../libintl.9.dylib "${PythonFrameworkBase}/Python"
install_name_tool -add_rpath @executable_path/../../../../../../../ "${PythonFrameworkBase}/Versions/Current/Resources/Python.app/Contents/MacOS/Python"
install_name_tool -add_rpath @executable_path/../../../../ "${PythonFrameworkBase}/Versions/Current/bin/python${PY_VERSION}"
install_name_tool -add_rpath @executable_path/../../../../ "${PythonFrameworkBase}/Versions/Current/bin/python${PY_VERSION}m"
# Fix rpaths from Python.Framework
# install_name_tool change @loader_path/../../../libz.1.dylib
# Fix main library
printf ${PythonFrameworkBase}/Python | fix_framework_library
# find ${PythonFrameworkBase} -name "*.so" -not -type l | fix_framework_library
}
cd ${PythonFrameworkBase}
find . -name "test*" -type d | xargs rm -rf
find "${PythonFrameworkBase}/Versions/${PY_VERSION}/bin" -not -name "python*" | xargs rm -f
cd "${PythonFrameworkBase}/Versions/${PY_VERSION}/lib/python${PY_VERSION}"
rm -rf distutils tkinter ensurepip venv lib2to3 idlelib
}
fix_python_framework() {
# Fix python.framework rpath and slims down installation
PythonFrameworkBase="${KRITA_DMG}/krita.app/Contents/Frameworks/Python.framework"
......@@ -354,8 +386,6 @@ krita_deploy () {
mkdir -p ${KRITA_DMG}/krita.app/Contents/PlugIns
mkdir -p ${KRITA_DMG}/krita.app/Contents/Frameworks
mkdir -p ${KRITA_DMG}/krita.app/Contents/Frameworks
echo "Copying share..."
# Deletes old copies of translation and qml to be recreated
cd ${KIS_INSTALL_DIR}/share/
......@@ -407,12 +437,6 @@ krita_deploy () {
# rsync -prul {KIS_INSTALL_DIR}/lib/libkrita* Frameworks/
echo "Copying python..."
# folders with period in name are treated as Frameworks for codesign
# there cant be empty files
rsync -prul ${KIS_INSTALL_DIR}/lib/python3.5/ ${KRITA_DMG}/krita.app/Contents/Frameworks/python
ln -s python ${KRITA_DMG}/krita.app/Contents/Frameworks/python3.5
rsync -prul ${KIS_INSTALL_DIR}/lib/krita-python-libs ${KRITA_DMG}/krita.app/Contents/Frameworks/
# To avoid errors macdeployqt must be run from bin location
# ext_qt will not build macdeployqt by default so it must be build manually
# cd ${BUILDROOT}/depbuild/ext_qt/ext_qt-prefix/src/ext_qt/qttools/src
......@@ -459,11 +483,6 @@ krita_deploy () {
krita_findmissinglibs $(find ${KRITA_DMG}/krita.app/Contents -type f -perm 755 -or -name "*.dylib" -or -name "*.so")
echo "Done!"
# fix python
# precompile all pyc so the dont alter signature
cd ${KRITA_DMG}/krita.app
${KIS_INSTALL_DIR}/bin/python -m compileall .
}
# helper to define function only once
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment