2018-12-18 18:11:26 +01:00
#!/usr/bin/env bash
SCRIPT_NAME = ` basename " $0 " `
2018-12-18 19:51:49 +01:00
TMP_WHEEL = "/tmp/klayout_tempwheel"
2018-12-18 18:11:26 +01:00
display_usage( ) {
echo "This script fixes auditwheel-repaired wheels."
echo "Caution: This will delete the original wheel."
2018-12-18 19:51:49 +01:00
echo -e " \nUsage:\n./ ${ SCRIPT_NAME } [--help|-h] klayout-...-manylinux1_x86_64.whl \n "
2018-12-18 18:11:26 +01:00
}
if [ [ ( $1 = = "--help" ) || $1 = = "-h" ] ]
then
display_usage
exit 0
fi
# Check number of arguments
if [ $# -eq 0 ] ; then
2018-12-18 19:51:49 +01:00
>& 2 echo -e "ERROR: No filename supplied\n"
2018-12-18 18:11:26 +01:00
display_usage
exit 1
elif [ ! $# -eq 1 ] ; then
2018-12-18 19:51:49 +01:00
>& 2 echo -e "ERROR: Too many files supplied. Provide one filename at at time.\n"
2018-12-18 18:11:26 +01:00
display_usage
exit 1
fi
# Read wheel file from argument
WHL = " $1 "
# Check WHL is a valid file
if [ [ ! -f " $WHL " ] ] ; then
2018-12-18 19:51:49 +01:00
>& 2 echo -e " ERROR: $WHL is not a file "
2018-12-18 18:11:26 +01:00
exit 1
fi
# Convert to absolute path (linux only)
WHL = $( readlink -f $WHL )
# Record old current directory
OLD_PWD = $PWD
# The produced wheel from auditwheel, klayout-*-manylinux1_x86_64.whl, is defective in the following way: dbcore.so etc. have RPATHs reset to `$ORIGIN/.libs`, so we need to move all .so's `lib_*` into `.libs`, as well as `db_plugins`. We also need to change the dist-info/RECORD file paths. This is a bug from auditwheel, it should either have added a new RPATH, $ORIGIN/.libs, where it places libz, libcurl, libexpat, instead of renaming the existing ones, or moved the files to the right place.
2018-12-18 19:51:49 +01:00
# Checking if it was previously patched
if unzip -l $WHL | grep -q 'patched_after_auditwheel_repair' ; then
echo " $( basename $WHL ) is already patched. Doing nothing. "
exit 0
fi
2018-12-18 18:11:26 +01:00
# Repair script below
2018-12-18 19:51:49 +01:00
if [ [ -d $TMP_WHEEL ] ] ; then
rm -rf $TMP_WHEEL
fi
echo " Unpacking $WHL into $TMP_WHEEL "
unzip -q $WHL -d $TMP_WHEEL
2018-12-18 18:11:26 +01:00
2018-12-18 19:51:49 +01:00
cd $TMP_WHEEL /klayout
echo "Moving files: mv lib_* db_plugins .libs/"
mv lib_* db_plugins .libs/ 2>/dev/null
if [ $? -ne 0 ] ; then
>& 2 echo "ERROR: lib_*.so or db_plubins not found. Quitting."
exit 1
fi
2018-12-18 18:11:26 +01:00
cd ../klayout-*.dist-info/
2018-12-18 19:51:49 +01:00
echo "Patching klayout-*.dist-info/RECORD"
2018-12-18 18:11:26 +01:00
sed -i 's/^klayout\/lib_/klayout\/.libs\/lib_/g' RECORD
sed -i 's/^klayout\/db_plugins/klayout\/.libs\/db_plugins/g' RECORD
cd ../
2018-12-18 19:51:49 +01:00
touch $TMP_WHEEL /patched_after_auditwheel_repair
echo " Packing $WHL from $TMP_WHEEL "
2018-12-18 18:11:26 +01:00
rm -f $WHL
zip -rq $WHL ./*
2018-12-18 19:51:49 +01:00
echo " Done. $( basename $WHL ) is patched. "
2018-12-18 18:11:26 +01:00
# Cleanup (should always execute)
cd $OLD_PWD