2018-04-14 09:39:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-01-02 17:57:29 +00:00
|
|
|
set -euo pipefail
|
2018-04-14 09:39:44 +00:00
|
|
|
if ! [[ $# -eq 3 ]]; then
|
|
|
|
echo "Usage: $0 [Python.framework] [AppBundle.app] [AppBundle.app/Contents/MacOS/Executable]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-19 10:43:33 +00:00
|
|
|
python_version=python3.9
|
2019-03-08 23:01:24 +00:00
|
|
|
|
2018-04-14 09:39:44 +00:00
|
|
|
py_framework=$1
|
|
|
|
appbundle=$2
|
|
|
|
executable=$3
|
|
|
|
|
2021-01-02 17:57:29 +00:00
|
|
|
echo "Embedding $py_framework into $appbundle | $executable"
|
|
|
|
|
|
|
|
mkdir -p "$appbundle/Contents/Frameworks"
|
|
|
|
if [ ! -d "$appbundle/Contents/Frameworks/Python.framework" ]
|
|
|
|
then
|
|
|
|
cp -a -n "$py_framework" "$appbundle/Contents/Frameworks/"
|
|
|
|
echo "Cleaning up embedded Python Framework"
|
|
|
|
cd "$appbundle/Contents/Frameworks/Python.framework"
|
|
|
|
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
|
2021-01-24 09:11:26 +00:00
|
|
|
rm -r Versions/Current/Resources/Python.app "Versions/Current/lib/$python_version/test" "Versions/Current/lib/$python_version/idlelib" "Versions/Current/lib/$python_version/curses" "Versions/Current/lib/$python_version/lib2to3" || echo "Couldn't remove something"
|
2021-01-02 17:57:29 +00:00
|
|
|
else
|
|
|
|
echo "Python.framework already exists, skipping copying"
|
|
|
|
cd "$appbundle/Contents/Frameworks/Python.framework"
|
|
|
|
fi
|
2018-04-14 09:39:44 +00:00
|
|
|
|
|
|
|
echo "Making executable $executable point to embedded Framework"
|
|
|
|
install_name_tool -change `otool -L "$executable" | sed -n "s/^[[:blank:]]*\([^[:blank:]]*Python\) (.*$/\1/p"` @executable_path/../Frameworks/Python.framework/Versions/Current/Python "$executable"
|
|
|
|
|
2019-03-08 23:01:24 +00:00
|
|
|
echo "Checking if PySide2 is available"
|
|
|
|
|
|
|
|
pyside_prefix=$(pkg-config --variable=prefix pyside2)
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "PySide2 is not available, ignoring."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "PySide is at $pyside_prefix"
|
|
|
|
|
2021-01-02 17:57:29 +00:00
|
|
|
if [ ! -d "Versions/Current/lib/$python_version/site-packages/PySide2" ]
|
|
|
|
then
|
|
|
|
cp -va "$pyside_prefix/lib/$python_version/" "Versions/Current/lib/$python_version"
|
|
|
|
cd .. # $appbundle/Contents/Frameworks
|
|
|
|
cp -va "$pyside_prefix/lib/"*.dylib .
|
|
|
|
else
|
|
|
|
echo "site-packages/Pyside2 exists, skipping copying"
|
|
|
|
fi
|