Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Updated make_wheel script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoyt Koepke committed Jan 3, 2020
1 parent d8e29d9 commit c44d323
Showing 1 changed file with 23 additions and 106 deletions.
129 changes: 23 additions & 106 deletions scripts/make_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fi

push_ld_library_path() {
OLD_LIBRARY_PATH=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${WORKSPACE}/deps/local/lib:${WORKSPACE}/deps/local/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${WORKSPACE}/targets/lib;$LD_LIBRARY_PATH
}

pop_ld_library_path() {
Expand All @@ -186,7 +186,7 @@ build_source() {

# make src/
cd ${WORKSPACE}/${build_type}/src
make -j${NUM_PROCS}
make -j${NUM_PROCS} install

# make test/
if [[ -z $SKIP_TEST ]]; then
Expand All @@ -197,6 +197,7 @@ build_source() {
make -j${NUM_PROCS}
fi
fi

pop_ld_library_path

echo -e "\n\n================= Done Build Source ================\n\n"
Expand All @@ -222,126 +223,42 @@ unit_test() {
echo -e "\n\n================= Done Python Unit Tests ================\n\n"
}

mac_patch_rpath() {
echo -e "\n\n\n================= Patching Mac RPath ================\n\n\n"
# on mac we need to do a little work to fix up RPaths
cd ${WORKSPACE}/${build_type}/src/python
# - look for all files
# - run 'file' on it
# - look for binary files (shared libraries, executables)
# - output is in the form [file]: type, so cut on ":", we just want the file
flist=`find . -type f -not -path "*/CMakeFiles/*" -not -path "./dist/*" | xargs -L 1 file | grep x86_64 | cut -f 1 -d :`

# We are generally going to be installed in
# a place of the form
# PREFIX/lib/python2.7/site-packages/[module]
# libpython2.7 will probably in PREFIX/lib
# So for instance if I am in
# PREFIX/lib/python2.7/site-packages/turicreate/unity_server
# I need to add
# ../../../ to the rpath (to make it to lib/)
# But if I am in
#
# PREFIX/lib/python2.7/site-packages/turicreate/something/somewhere
# I need to add
# ../../../../ to the rpath
for f in $flist; do
# Lets explain the regexes
# - The first regex removes "./"
# - The second regex replaces the string "[something]/" with "../"
# (making sure something does not contain '/' characters)
# - The 3rd regex removes the last "filename" bit
#
# Example:
# Input: ./turicreate/cython/cy_ipc.so
# After 1st regex: turicreate/cython/cy_ipc.so
# After 2nd regex: ../../cy_ipc.so
# After 3rd regex: ../../
relative=`echo $f | sed 's:\./::g' | sed 's:[^/]*/:../:g' | sed 's:[^/]*$::'`
# Now we need ../../ to get to PREFIX/lib
rpath="@loader_path/../../$relative"
install_name_tool -add_rpath $rpath $f || true
done
}


### Package the release folder into a wheel, and strip the binaries ###
package_wheel() {
if [[ $OSTYPE == darwin* ]]; then
mac_patch_rpath
fi
echo -e "\n\n\n================= Packaging Wheel ================\n\n\n"
cd ${WORKSPACE}/${build_type}/src/python

# strip binaries
if [[ ! $OSTYPE == darwin* ]]; then
cd ${WORKSPACE}/${build_type}/src/python/turicreate
BINARY_LIST=`find . -type f -exec file {} \; | grep x86 | cut -d: -f 1`
echo "Stripping binaries: $BINARY_LIST"

# make newline the separator for items in for loop - default is whitespace
OLD_IFS=${IFS}
IFS=$'\n'

for f in $BINARY_LIST; do
if [ $OSTYPE == "msys" ] && [ $f == "./pylambda_worker.exe" ]; then
echo "Skipping pylambda_worker"
else
echo "Stripping $f"
strip -Sx $f;
fi
done

# set IFS back to default
IFS=${OLD_IFS}
cd ..
fi
cd ${WORKSPACE}/src/python

echo -e "\n\n\n================= Building Wheel ================\n\n\n"
cd ${WORKSPACE}/${build_type}/src/python
dist_type="bdist_wheel"

VERSION_NUMBER=`${PYTHON_EXECUTABLE} -c "from turicreate.version_info import version; print(version)"`
${PYTHON_EXECUTABLE} setup.py ${dist_type} # This produced an wheel starting with turicreate-${VERSION_NUMBER} under dist/
VERSION_NUMBER=`${PYTHON_EXECUTABLE} -c "import setup; print(setup.VERSION)"`
wheel_name=`${PYTHON_EXECUTABLE} setup.py -q bdist_wheel_name`
old_platform_tag=`${PYTHON_EXECUTABLE} -c "import distutils; print(distutils.util.get_platform())"`
LD_LIBRARY_PATH='${WORKSPACE}/targets/lib' CPATH='${WORKSPACE}/targets/include' ${PYTHON_EXECUTABLE} setup.py bdist_wheel


cd ${WORKSPACE}

WHEEL_PATH=`ls ${WORKSPACE}/${build_type}/src/python/dist/turicreate-${VERSION_NUMBER}*.whl`
WHEEL_PATH=`ls ${WORKSPACE}/src/python/dist/${wheel_name}.whl`

if [[ $OSTYPE == darwin* ]]; then
# Change the platform tag embedded in the file name
temp=`echo $WHEEL_PATH | perl -ne 'print m/(^.*-).*$/'`
temp=${temp/-cpdarwin-/-cp35m-}

DYLD_LIBRARY_PATH="${WORKSPACE}/targets/lib" delocate-wheel -v ${WHEEL_PATH}

platform_tag="macosx_10_12_intel.macosx_10_12_x86_64.macosx_10_13_intel.macosx_10_13_x86_64.macosx_10_14_intel.macosx_10_14_x86_64"
# sdk_version=`xcrun --show-sdk-version`
# if [[ $sdk_version =~ ^10\.13 ]]; then
# platform_tag="macosx_10_13_intel.macosx_10_12_x86_64"
# elif [[ $sdk_version =~ ^10\.12 ]]; then
# platform_tag="macosx_10_12_intel.macosx_10_12_x86_64"
# fi

NEW_WHEEL_PATH=${temp}${platform_tag}".whl"
mv ${WHEEL_PATH} ${NEW_WHEEL_PATH}
WHEEL_PATH=${NEW_WHEEL_PATH}
else
# Don't pick up -manylinux1 wheels, since those may have been created by a later step from a previous build.
# Ignore those for now by selecting only -linux wheels.
WHEEL_PATH=`ls ${WORKSPACE}/${build_type}/src/python/dist/turicreate-${VERSION_NUMBER}*-linux*.whl`
fi

# Set Python Language Version Number
NEW_WHEEL_PATH=${WHEEL_PATH}
if [[ "$python35" == "1" ]]; then
NEW_WHEEL_PATH=${WHEEL_PATH/-py3-/-cp35-}
elif [[ "$python36" == "1" ]]; then
NEW_WHEEL_PATH=${WHEEL_PATH/-py3-/-cp36-}
NEW_WHEEL_PATH=${WORKSPACE}/targets/${wheel_name/$old_platform_tag/$platform_tag}.whl

else
NEW_WHEEL_PATH=${WHEEL_PATH/-py2-/-cp27-}
fi
NEW_WHEEL_PATH=${NEW_WHEEL_PATH/linux/manylinux1}
if [[ ! "${WHEEL_PATH}" == "${NEW_WHEEL_PATH}" ]]; then
mv "${WHEEL_PATH}" "${NEW_WHEEL_PATH}"
WHEEL_PATH=${NEW_WHEEL_PATH}
LD_LIBRARY_PATH="${WORKSPACE}/targets/lib" auditwheel repair ${WHEEL_PATH}

NEW_WHEEL_PATH=${WORKSPACE}/targets/${wheel_name}.whl
fi

mv ${WHEEL_PATH} ${NEW_WHEEL_PATH}
WHEEL_PATH=${NEW_WHEEL_PATH}


if [[ -z $SKIP_SMOKE_TEST ]]; then
# Install the wheel and do a smoke test
Expand Down

0 comments on commit c44d323

Please sign in to comment.