Path: blob/main/Sage_framework/build_sage_framework.sh
170 views
BASE_DIR=`pwd`1VERSION=`../bin/get_sage_version`2SAGE_SYMLINK="/var/tmp/sage-$VERSION-current"3PYTHON_LONG_VERSION=`readlink repo/sage/venv | cut -f2 -d '-' | sed s/python//`4PYTHON_VERSION=`echo ${PYTHON_LONG_VERSION} | cut -f 1,2 -d'.'`5PY_VRSN=`echo ${PYTHON_VERSION} | sed 's/\\.//g'`6echo Building framework for SageMath ${VERSION} using Python ${PYTHON_LONG_VERSION}7TKINTER_LIB=_tkinter.cpython-${PY_VRSN}-darwin.so8REPO=${BASE_DIR}/repo/sage9FILES=${BASE_DIR}/files10BUILD=${BASE_DIR}/build11VERSION_DIR=${BUILD}/Sage.framework/Versions/${VERSION}12CURRENT_DIR=${BUILD}/Sage.framework/Versions/Current13RESOURCE_DIR=${VERSION_DIR}/Resources14VENV_DIR="local/var/lib/sage/venv-python${PYTHON_LONG_VERSION}"15VENV_PYLIB="${VENV_DIR}/lib/python${PYTHON_VERSION}"16VENV_KERNEL_DIR=${VERSION_DIR}/"${VENV_DIR}/share/jupyter/kernels"17NBEXTENSIONS="${VERSION_DIR}/${VENV_DIR}/share/jupyter/nbextensions"18THREEJS_SAGE="${NBEXTENSIONS}/threejs-sage"19INPUT_HOOKS=${VERSION_DIR}/${VENV_PYLIB}/site-packages/IPython/terminal/pt_inputhooks2021# This allows Sage.framework to be a symlink to the framework inside the application.22if ! [ -d "${BUILD}/Sage.framework" ]; then23mkdir -p "${BUILD}"/Sage.framework24fi2526# Clean out everything.27echo Removing old framework ...28rm -rf "${BUILD}"/Sage.framework/*2930# Create the bundle directories31mkdir -p "${RESOURCE_DIR}"32ln -s ${VERSION} "${CURRENT_DIR}"33ln -s Versions/Current/Resources "${BUILD}"/Sage.framework/Resources34ln -s ${VENV_DIR} ${VERSION_DIR}/venv3536# Create the resource files37cp "${REPO}"/{COPYING.txt,README.md,VERSION.txt} "${RESOURCE_DIR}"38sed "s/__VERSION__/${VERSION}/g" "${FILES}"/Info.plist > "${RESOURCE_DIR}"/Info.plist39cp ${FILES}/pip.conf ${RESOURCE_DIR}40mkdir -p ${VERSION_DIR}/local/{bin,include,lib,etc,libexec}41echo "Copying files ..."42cp -R "${REPO}"/local/bin/ ${VERSION_DIR}/local/bin43cp -R "${REPO}"/local/include/ ${VERSION_DIR}/local/include44cp -R "${REPO}"/local/lib/ ${VERSION_DIR}/local/lib45cp -R "${REPO}"/local/etc/ ${VERSION_DIR}/local/etc46cp -R "${REPO}"/local/libexec/ ${VERSION_DIR}/local/libexec47ln -s lib "${VERSION_DIR}"/local/lib6448mkdir -p ${VERSION_DIR}/local/var/lib/sage/{installed,scripts}49mkdir -p ${VERSION_DIR}/${VENV_DIR}/etc50cp -R "${REPO}"/local/var/lib/sage/installed/ ${VERSION_DIR}/local/var/lib/sage/installed51cp -R "${REPO}"/local/var/lib/sage/scripts/ ${VERSION_DIR}/local/var/lib/sage/scripts52cp -R "${REPO}"/${VENV_DIR}/{bin,lib,include,share} ${VERSION_DIR}/${VENV_DIR}53cp -R "${REPO}"/${VENV_DIR}/etc/jupyter ${VERSION_DIR}/${VENV_DIR}/etc5455# Copy the useful parts of local/share56rm -rf ${VERSION_DIR}/${VENV_DIR}/share/{doc,man}57mkdir -p ${VERSION_DIR}/local/share58for share_dir in `ls "${REPO}"/local/share`; do59if [ $share_dir != "doc" ]; then60cp -R "${REPO}"/local/share/$share_dir ${VERSION_DIR}/local/share/$share_dir61fi62done6364# Create the runpath.sh script65echo SAGE_SYMLINK=/var/tmp/sage-${VERSION}-current > ${VERSION_DIR}/local/var/lib/sage/runpath.sh66chmod 755 ${VERSION_DIR}/local/var/lib/sage/runpath.sh6768# Copy our modified files into the bundle69# Install jupyter kernels, etc.70rm -rf ${VERSION_DIR}/${VENV_DIR}/share/jupyter/kernels/sagemath71# See sage/repl/ipython_kernel/install.py72mkdir -p ${VENV_KERNEL_DIR}/sagemath73sed "s/__VERSION__/${VERSION}/g" "${FILES}"/kernel.json > ${VENV_KERNEL_DIR}/sagemath/kernel.json74#cp -p ${FILES}/${TKINTER} ${VERSION_DIR}/${VENV_PYLIB}/lib-dynload/75cp -p ${FILES}/tkinter/__init__.py ${VERSION_DIR}/${VENV_PYLIB}/tkinter/__init__.py76cp ${FILES}/osx.py ${INPUT_HOOKS}77cp -p ${FILES}/BuildPackages.sh ${VERSION_DIR}/local/lib/gap/bin78cp ${FILES}/sage-notebook ${VERSION_DIR}/${VENV_DIR}/bin79sed "s/__VERSION__/${VERSION}/g" "${FILES}"/sage-notebook > ${VERSION_DIR}/${VENV_DIR}/bin/sage-notebook80cp ${FILES}/sage ${VERSION_DIR}/${VENV_DIR}/bin81cp ${FILES}/sage-env ${VERSION_DIR}/${VENV_DIR}/bin82cp ${FILES}/sagedoc.py ${VERSION_DIR}/${VENV_PYLIB}/site-packages/sage/misc/83cp ${FILES}/ipython_kernel/* ${VERSION_DIR}/${VENV_PYLIB}/site-packages/sage/repl/ipython_kernel84# Fix illegal symlinks that point outside of the bundle85rm -rf ${VERSION_DIR}/local/share/jupyter/kernels/sagemath/doc86rm -f ${VERSION_DIR}/local/share/threejs-sage/threejs-sage87rm -rf ${THREEJS_SAGE}88ln -s ../../../../../../../share/threejs-sage ${THREEJS_SAGE}8990# Make @interact work91mkdir -p ${NBEXTENSIONS}/widgets/notebook92ln -s ../../jupyter-js-widgets ${NBEXTENSIONS}/widgets/notebook/js9394# Remove some useless stuff95rm -rf ${VERSION_DIR}/local/lib/saclib96rm -rf ${VERSION_DIR}/local/share/man9798# Update Sage's jupyter kernel directory.99rm -rf ${VERSION_DIR}/venv/share/jupyter/kernels100cp -R ../package/local_share/jupyter/kernels ${VERSION_DIR}/venv/share/jupyter101102# # Install current versions of pip packages over the ones built by Sage103104if [ -L ${SAGE_SYMLINK} ]; then105rm ${SAGE_SYMLINK}106elif [ -e ${SAGE_SYMLINK} ]; then107echo ${SAGE_SYMLINK} is not a symlink !!!108exit 1109fi110mv $VERSION_DIR $SAGE_SYMLINK111pushd ${SAGE_SYMLINK}112113PIP_ARGS="install --upgrade --no-user --force-reinstall --upgrade-strategy eager"114venv/bin/python3 -m pip $PIP_ARGS jupyterlab115venv/bin/python3 -m pip $PIP_ARGS notebook116venv/bin/python3 -m pip $PIP_ARGS pillow117118# Install cocoserver119PIP_ARGS="install --no-user --upgrade --no-deps"120venv/bin/python3 -m pip $PIP_ARGS cocoserver121122popd123mv $SAGE_SYMLINK $VERSION_DIR124125# Fix up rpaths and shebangs126echo "Patching files ..."127source ../IDs.sh128mv files_to_sign files_to_sign.bak129python3 fix_paths.py repo ${VERSION_DIR}/local/bin >> files_to_sign130python3 fix_paths.py repo ${VERSION_DIR}/local/lib >> files_to_sign131python3 fix_paths.py repo ${VERSION_DIR}/local/libexec >> files_to_sign132python3 fix_paths.py repo ${VERSION_DIR}/${VENV_DIR}/bin >> files_to_sign133python3 fix_paths.py repo ${VERSION_DIR}/${VENV_DIR}/lib >> files_to_sign134python3 fix_scripts.py ${VERSION_DIR}/$VENV_DIR}/bin135136# Fix the absolute symlinks for the GAP packages137pushd ${VERSION_DIR}/local/share/gap/pkg > /dev/null138for pkg in `ls` ; do139if [[ -L $pkg/bin ]]; then140rm $pkg/bin ;141ln -s ../../../../lib/gap/pkg/$pkg/bin $pkg/bin ;142fi143done144popd > /dev/null145146# Remove xattrs (must be done before signing!)147xattr -rc ${BUILD}/Sage.framework148149# Remove byte code150find ${BUILD}/Sage.framework -name '*.pyc' -delete151# Sign the framework.152echo "Signing files ..."153python3 sign_sage.py154# Overwrite the _tkinter extension with our signed version155cp -p ${FILES}/${TKINTER_LIB} ${VERSION_DIR}/${VENV_PYLIB}/lib-dynload/156# Start sage to create a minimal set of bytecode files.157echo "Starting Sage to create byte code files ..."158${VERSION_DIR}/venv/bin/sage -c "print(2+2) ; exit"159echo "We need to sign the framework again:"160python3 sign_sage.py framework161162163