From 28c1f440713a16fe276a59cbdb34fe1d0eaecf28 Mon Sep 17 00:00:00 2001
From: Mohcine Chraibi <m.chraibi@fz-juelich.de>
Date: Fri, 29 Mar 2019 09:59:59 +0100
Subject: [PATCH] WIP: update deploy scripts

---
 deployAPPLE.sh     | 16 ++++++++++++++--
 fixQtdependency.py | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 fixQtdependency.py

diff --git a/deployAPPLE.sh b/deployAPPLE.sh
index c2edf57..81f2a99 100755
--- a/deployAPPLE.sh
+++ b/deployAPPLE.sh
@@ -31,7 +31,7 @@ echo "INFO: make .."
 make -j4
 
 
-echo "INFO: running  <dylibbundler -od -b -x ../bin/${CMD}.app/Contents/MacOS/${CMD} -d ../bin/${CMD}.app/Contents/libs/>"
+# echo "INFO: running  <dylibbundler -od -b -x ../bin/${CMD}.app/Contents/MacOS/${CMD} -d ../bin/${CMD}.app/Contents/libs/>"
 dylibbundler -od -b -x ../bin/${CMD}.app/Contents/MacOS/${CMD} -d ../bin/${CMD}.app/Contents/libs/
 
 
@@ -51,8 +51,15 @@ if [[ -n $isPythonDependencyGlobal ]];then
 
         Frameworks=`echo ${Python} |  awk -F Frameworks '{ print "Frameworks"$2 }'`
         echo "WARNING: ${RED} change <$Python> to <@executable_path/../$Frameworks> ${CMD} ${NC}."
+        echo "cp `dirname ${Python}`"
+        echo "in ../bin/jpsvis.app/Contents/${Framworks}"
+        destination=`echo ${p} |  awk -F Frameworks '{ print $1"Frameworks" }'`
+        # todo: this python stuff is hard coded yet!
+        mkdir -p ../bin/jpsvis.app/Contents/Frameworks/Python.framework/Versions
+        cp -r `dirname ${Python}` ../bin/jpsvis.app/Contents/Frameworks/Python.framework/Versions
 
-        install_name_tool -change $Python @executable_path/../$Frameworks ../bin/${CMD}.app/Contents/MacOS/${CMD}
+
+        install_name_tool -change $Python @executable_path/../Frameworks/Python.framework/Versions/3.7/Python ../bin/${CMD}.app/Contents/MacOS/${CMD}
 
         echo "INFO: Check again"
         otool -L ../bin/${CMD}.app/Contents/MacOS/${CMD} | grep Python.framework
@@ -65,4 +72,9 @@ cd ..
 # check if dependencies to libs are local to .app
 python checkDependencies.py bin/jpsvis.app/
 
+# qt dependencies
+python fixQtdependency.py
+
+# because of https://github.com/auriamg/macdylibbundler/issues/12
+
 appdmg Resources/dmg.json ${CMD}-${VERSION}.dmg
diff --git a/fixQtdependency.py b/fixQtdependency.py
new file mode 100644
index 0000000..aa27f1c
--- /dev/null
+++ b/fixQtdependency.py
@@ -0,0 +1,35 @@
+import glob
+import subprocess
+import shlex
+import os
+import sys
+from shutil import copyfile
+RED = '\033[0;31m'
+NC = '\033[0m' # No Color
+
+executable = "bin/jpsvis.app/Contents/MacOS/jpsvis"
+cmd = "otool -L %s"%executable
+
+f = open("blah.txt", "w")
+res = subprocess.call(shlex.split(cmd), stdout=f)
+f.close()
+f = open("blah.txt", "r")
+lines = f.readlines()
+for line in lines:
+    if line.find("Qt") > 0 and line.find("vtk") < 0:
+        old_qt_dep = line.split()[0]
+        filename = old_qt_dep.split("/")[-1]
+        new_qt_dep = "bin/jpsvis.app/Contents/libs/%s"%filename
+        if not os.path.exists(new_qt_dep):
+            copyfile(old_qt_dep, new_qt_dep)
+
+
+        change = "install_name_tool -change %s %s %s"%(old_qt_dep, "@executable_path/../libs/%s"%filename, executable)
+        print("<< old: ", old_qt_dep)
+        print(">> new: ", "@executable_path/../libs/%s"%filename)
+        res = subprocess.call(shlex.split(change))
+
+        # todo: The copied qt libs should not reference system libs.
+
+        # Library not loaded: /usr/local/Cellar/qt/5.12.2/lib/QtCore.framework/Versions/5/QtCore
+        # Referenced from: /Applications/jpsvis.app/Contents/libs/QtNetwork
-- 
GitLab