install-dylibs.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/python
  2. import subprocess, os, sys, shutil, Queue, fnmatch
  3. def exec_cmd(args, env={}, supress_output=False):
  4. cmd = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, env = env)
  5. output = ''
  6. while True:
  7. out = cmd.stdout.read(1)
  8. if out == '' and cmd.poll() != None:
  9. break
  10. if out != '':
  11. if not supress_output:
  12. sys.stdout.write(out)
  13. output += out
  14. if cmd.wait() != 0:
  15. raise Exception("Command failed: \"%s\"" % " ".join(args), output)
  16. return output
  17. binaries = {}
  18. def install_libraries(binary):
  19. if binaries.has_key(binary): return []
  20. binaries[binary] = True
  21. other_binaries = []
  22. out = exec_cmd(["otool", "-L", binary], supress_output=True)
  23. for line in out.split('\n'):
  24. line = line.strip()
  25. if line.find("dylib") != -1 and (line.startswith('@executable_path') or line.find("libQt5") != -1):
  26. file = line.split('/')[-1].split(' ')[0]
  27. if line.startswith("@executable_path"):
  28. src = os.path.join(sys.argv[1], "dependencies/darwin-x86_64/lib", file)
  29. else:
  30. src = line.split(" (")[0]
  31. dst = os.path.join(sys.argv[2], "Konvergo.app", "Contents", "Frameworks", file)
  32. if os.path.exists(src):
  33. if (not os.path.exists(dst) or os.path.getsize(dst) != os.path.getsize(src)):
  34. print "-- Installing %s" % file
  35. shutil.copyfile(src, dst)
  36. other_binaries.append(src)
  37. return other_binaries
  38. queue = Queue.Queue()
  39. # Add the top-level binaries.
  40. for b in ['Contents/MacOS/Konvergo']:
  41. queue.put(os.path.join(sys.argv[2], "Konvergo.app", b))
  42. for root, dirs, files in os.walk(os.path.join(sys.argv[2], "Konvergo.app", "Contents", "Frameworks", "vlc")):
  43. for f in files:
  44. path = os.path.join(root, f)
  45. queue.put(path)
  46. while queue.empty() == False:
  47. binary = queue.get()
  48. other_binaries = install_libraries(binary)
  49. for b in other_binaries:
  50. queue.put(b)