From e7e0eee7e6caf957ee64127a4c49cdfcb1572ea7 Mon Sep 17 00:00:00 2001
From: Alykhan Tejani <alykhan.tejani@gmail.com>
Date: Wed, 6 Sep 2017 17:03:47 +0100
Subject: [PATCH] add code to regenerate RECORD file for the wheel after we use
 patchelf

---
 manywheel/build.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/manywheel/build.sh b/manywheel/build.sh
index f9eae113e..82153178b 100755
--- a/manywheel/build.sh
+++ b/manywheel/build.sh
@@ -130,6 +130,24 @@ for whl in /$WHEELHOUSE_DIR/torch*manylinux*.whl; do
     # libshm
     patchelf --set-rpath '$ORIGIN' torch/lib/libshm.so
 
+    # regenerate the RECORD file with new hashes 
+    record_file=`echo $(basename whl) | sed -e 's/-cp.*$/.dist-info\/RECORD/g'`
+    new_record_file="$record_file"_new
+    while read -r line
+    do
+      record_item="$line"
+      IFS=, read -r filename digestmethod digest size <<< "$record_item"
+      if [ $filename == $record_file ]
+      then
+        echo "$line" >> $new_record_file
+      else
+        new_digest=`openssl dgst -sha256 -binary $filename | openssl base64 | sed -e 's/+/-/g' | sed -e 's/\//_/g' | sed -e 's/=//g'`
+        new_size=`ls -nl $filename | awk '{print $5}'`
+        echo $filename,$digestmethod,$new_digest,$new_size >> $new_record_file 
+      fi
+    done < "$record_file"
+    mv $new_record_file $record_file
+
     # zip up the wheel back
     zip -r $(basename $whl) torch*