|
@@ -17,7 +17,9 @@
|
|
|
# * Fetches python from the official python repository
|
|
|
# * patches python with open3d_python.patch to shortcut the package building process (we don't need)
|
|
|
# a full installer, just the framework.
|
|
|
+# * Fetches expat 2.4.6 to patch a security vulnerability as part of python 3.7.x
|
|
|
# * Ensures you have the necessary environment vars set and pip packages installed in a pip virtualenv
|
|
|
+# * Upgrades PIP to the latest version
|
|
|
# * builds python using python.org official mac package builder we've patched.
|
|
|
# * Uses the relocatable-python script to generate a 'package' folder containing real python but
|
|
|
# with rpaths patched to be relocatable.
|
|
@@ -25,6 +27,7 @@
|
|
|
# * Deploys the finished framework to a the package layout folder using rsync.
|
|
|
# * Copies the license files inside python to the package layout folder
|
|
|
# * Copies the other package system file (json and cmake) to the pacakge layout folder.
|
|
|
+# * Removes older PIP (20.0.3) whl file from ensurepip since PIP will already be installed in this package
|
|
|
#
|
|
|
# The result is a 'package' subfolder containing the package files such as PackageInfo.json
|
|
|
# and a subfolder containing the official python but patched so that they work in that folder structure
|
|
@@ -34,7 +37,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
cd $SCRIPT_DIR
|
|
|
|
|
|
echo ""
|
|
|
-echo "------------------ PYTHON PACKAGE BUILD SCRIPT -------------------"
|
|
|
+echo "--------------- PYTHON PACKAGE BUILD SCRIPT ----------------"
|
|
|
echo ""
|
|
|
echo "BASIC REQUIREMENTS:"
|
|
|
echo " - git installed and in PATH"
|
|
@@ -42,26 +45,44 @@ echo " - XCODE and xcode command line tools installed: xcode-select --install"
|
|
|
echo " - python3 installed and in PATH."
|
|
|
echo ""
|
|
|
|
|
|
-echo "--------------- Clearing any previous package folder -------------"
|
|
|
+echo "--------------- Clearing any previous package folder ----------------"
|
|
|
+echo ""
|
|
|
rm -rf package
|
|
|
|
|
|
-echo "---------------- Clearing any previous temp folder ---------------"
|
|
|
+echo ""
|
|
|
+echo "--------------- Clearing any previous temp folder ----------------"
|
|
|
+echo ""
|
|
|
rm -rf temp
|
|
|
-
|
|
|
mkdir temp
|
|
|
cd temp
|
|
|
|
|
|
mkdir $SCRIPT_DIR/package
|
|
|
|
|
|
-echo "-------------- Cloning python from git --------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- Cloning python 3.7.12 from git ----------------"
|
|
|
+echo ""
|
|
|
git clone https://github.com/python/cpython.git --branch "v3.7.12" --depth 1
|
|
|
retVal=$?
|
|
|
if [ $retVal -ne 0 ]; then
|
|
|
- echo "Error cloning python!"
|
|
|
+ echo "Error cloning python from https://github.com/python/cpython.git"
|
|
|
exit $retVal
|
|
|
fi
|
|
|
|
|
|
-echo "-------------- Cloning relocatable-python from git --------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- Cloning libexpat 2.4.6 from git and applying update ----------------"
|
|
|
+echo ""
|
|
|
+git clone https://github.com/libexpat/libexpat.git --branch "R_2_4_6" --depth 1
|
|
|
+if [ $retVal -ne 0 ]; then
|
|
|
+ echo "Was unable to create libexpat dir via git clone. Is git installed?"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+cp -f -v libexpat/expat/lib/*.h cpython/Modules/expat/
|
|
|
+cp -f -v libexpat/expat/lib/*.c cpython/Modules/expat/
|
|
|
+
|
|
|
+
|
|
|
+echo ""
|
|
|
+echo "---------------- Cloning relocatable-python from git ----------------"
|
|
|
+echo ""
|
|
|
git clone https://github.com/gregneagle/relocatable-python.git
|
|
|
retVal=$?
|
|
|
if [ $retVal -ne 0 ]; then
|
|
@@ -72,17 +93,24 @@ fi
|
|
|
PYTHON_SRC_DIR=$SCRIPT_DIR/temp/cpython
|
|
|
RELOC_SRC_DIR=$SCRIPT_DIR/temp/relocatable-python
|
|
|
|
|
|
-echo "------------- creating python virtual environment ----------"
|
|
|
+echo ""
|
|
|
+echo "---------------- creating python virtual environment ----------------"
|
|
|
+echo ""
|
|
|
cd $SCRIPT_DIR/temp
|
|
|
python3 -m venv py_venv
|
|
|
VENV_BIN_DIR=$SCRIPT_DIR/temp/py_venv/bin
|
|
|
PYTHONNOUSERSITE=1
|
|
|
|
|
|
-echo "------ Installing spinx documentation tool into the v-env -----"
|
|
|
+echo ""
|
|
|
+echo "---------------- Installing spinx documentation tool into the v-env ----------------"
|
|
|
+echo ""
|
|
|
$VENV_BIN_DIR/python3 -m pip install sphinx
|
|
|
|
|
|
cd $RELOC_SRC_DIR
|
|
|
-echo "----- Checking out specific commit hash of relocatable-python -----"
|
|
|
+
|
|
|
+echo ""
|
|
|
+echo "---------------- Checking out specific commit hash of relocatable-python ----------------"
|
|
|
+echo ""
|
|
|
# the hash is a known good commit hash. This also causes it to fail if someone
|
|
|
# tampers the repo!
|
|
|
git reset --hard 5e459c3ccea0daaf181f3b1ef2773dbefce1a563
|
|
@@ -92,7 +120,9 @@ if [ $retVal -ne 0 ]; then
|
|
|
exit $retVal
|
|
|
fi
|
|
|
|
|
|
-echo "------------------- patching the relocator -----------------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- patching the relocator ----------------"
|
|
|
+echo ""
|
|
|
echo Currently in `pwd`
|
|
|
echo patch -p1 $SCRIPT_DIR/open3d_patch.patch
|
|
|
patch -p1 < $SCRIPT_DIR/open3d_patch.patch
|
|
@@ -104,7 +134,9 @@ fi
|
|
|
|
|
|
|
|
|
cd $PYTHON_SRC_DIR
|
|
|
-echo "------------------- patching the python Mac package-maker -----------------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- patching the python source ----------------"
|
|
|
+echo ""
|
|
|
patch -p1 < $SCRIPT_DIR/open3d_python.patch
|
|
|
retVal=$?
|
|
|
if [ $retVal -ne 0 ]; then
|
|
@@ -112,7 +144,9 @@ if [ $retVal -ne 0 ]; then
|
|
|
exit $retVal
|
|
|
fi
|
|
|
|
|
|
-echo "-------------- Building a Mac python package from official sources ----------"
|
|
|
+echo ""
|
|
|
+echo "---------------- Building a Mac python package from official source ----------------"
|
|
|
+echo ""
|
|
|
cd $PYTHON_SRC_DIR
|
|
|
cd Mac
|
|
|
cd BuildScript
|
|
@@ -130,7 +164,9 @@ fi
|
|
|
FRAMEWORK_OUTPUT_FOLDER=$SCRIPT_DIR/temp/python_build/_root/Library/Frameworks
|
|
|
echo Framework output folder: $FRAMEWORK_OUTPUT_FOLDER
|
|
|
cd $RELOC_SRC_DIR
|
|
|
-echo "---------- Altering the produced framework folder to be relocatable ---------"
|
|
|
+echo ""
|
|
|
+echo "---------------- Altering the produced framework folder to be relocatable ----------------"
|
|
|
+echo ""
|
|
|
echo $VENV_BIN_DIR/python3 ./make_relocatable_python_framework.py --install-wheel --upgrade-pip --python-version 3.7.12 --use-existing-framework $FRAMEWORK_OUTPUT_FOLDER/Python.framework
|
|
|
$VENV_BIN_DIR/python3 ./make_relocatable_python_framework.py --install-wheel --upgrade-pip --python-version 3.7.12 --use-existing-framework $FRAMEWORK_OUTPUT_FOLDER/Python.framework
|
|
|
retVal=$?
|
|
@@ -139,7 +175,9 @@ if [ $retVal -ne 0 ]; then
|
|
|
exit $retVal
|
|
|
fi
|
|
|
|
|
|
-echo "------------------ Final RPATH update --------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- Final RPATH update ----------------"
|
|
|
+echo ""
|
|
|
# The filename of the main python dylib is 'Python'.
|
|
|
# It is located at ./package/Python.framework/Versions/3.7
|
|
|
# This, despite just being called 'Python' with no extension is actually the main python
|
|
@@ -155,19 +193,34 @@ echo "------------------ Final RPATH update --------------"
|
|
|
# whether a python native plugin is being located from the framework in some subfolder.
|
|
|
install_name_tool -id @rpath/Python $FRAMEWORK_OUTPUT_FOLDER/Python.framework/Versions/3.7/Python
|
|
|
|
|
|
-echo "-------------- rsync package layout into $SCRIPT_DIR/package ------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- rsync package layout into $SCRIPT_DIR/package ----------------"
|
|
|
+echo ""
|
|
|
mdkir $SCRIPT_DIR/package
|
|
|
rsync -avu --delete "$FRAMEWORK_OUTPUT_FOLDER/" "$SCRIPT_DIR/package"
|
|
|
|
|
|
-echo "---------- Copying Open3DEngine package metadata and license file ------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- Copying Open3DEngine package metadata and license file ----------------"
|
|
|
+echo ""
|
|
|
# the tar contains a 'Python.framework' sub folder
|
|
|
cd $SCRIPT_DIR/package
|
|
|
cp $SCRIPT_DIR/package/Python.framework/Versions/3.7/lib/python3.7/LICENSE.txt ./LICENSE
|
|
|
cp $SCRIPT_DIR/PackageInfo.json .
|
|
|
cp $SCRIPT_DIR/*.cmake .
|
|
|
|
|
|
-echo "-------------- Cleaning temp folder -----------------"
|
|
|
+echo ""
|
|
|
+echo "---------------- Removing pip references from ensurepip ----------------"
|
|
|
+echo ""
|
|
|
+rm -f $SCRIPT_DIR/package/Python.framework/Versions/3.7/lib/python3.7/ensurepip/_bundled/pip-20*.whl
|
|
|
+cat $SCRIPT_DIR/package/Python.framework/Versions/3.7/lib/python3.7/ensurepip/__init__.py | sed 's/"20.1.1"/"22.0.3"/g' | sed 's/("pip", _PIP_VERSION, "py2.py3"),//g' > $SCRIPT_DIR/package/python/lib/python3.7/ensurepip/__init__.py_temp
|
|
|
+rm $SCRIPT_DIR/package/Python.framework/Versions/3.7/lib/python3.7/ensurepip/__init__.py
|
|
|
+mv $SCRIPT_DIR/package/Python.framework/Versions/3.7/lib/python3.7/ensurepip/__init__.py_temp $SCRIPT_DIR/package/python/lib/python3.7/ensurepip/__init__.py
|
|
|
+
|
|
|
+echo ""
|
|
|
+echo "---------------- Cleaning temp folder ----------------"
|
|
|
+echo ""
|
|
|
rm -rf $SCRIPT_DIR/temp
|
|
|
|
|
|
+echo ""
|
|
|
echo "DONE! Package layout folder has been created in $SCRIPT_DIR/package"
|
|
|
exit 0
|