|
| 1 | +#! /usr/bin/env python3 |
| 2 | +"""pyWindeployqt |
| 3 | +
|
| 4 | +This is a wrapper for mingw32 objdump replacing windeployqt which is missing from MXE |
| 5 | +I don't know why they disabled it, but here it is. |
| 6 | +
|
| 7 | +Example: |
| 8 | +./deploy.py --build=~/ClionProjects/project/build/ \ |
| 9 | +--objdump=/home/user/mxe/usr/bin/i686-w64-mingw32.shared-objdump \ |
| 10 | +~/ClionProjects/project/build/project.exe; |
| 11 | +
|
| 12 | +""" |
| 13 | + |
| 14 | +__author__ = 'Alexey Elymanov (strangeqargo@gmail.com)' |
| 15 | + |
| 16 | +import subprocess |
| 17 | +import os |
| 18 | +import sys |
| 19 | +import re |
| 20 | +import os.path |
| 21 | + |
| 22 | +import argparse |
| 23 | +parser = argparse.ArgumentParser() |
| 24 | + |
| 25 | +parser.add_argument("--build", help="where to place libraries, optional, files will go to target location by default") |
| 26 | +parser.add_argument("--objdump", help="objdump executable (/home/user/mxe/usr/bin/i686-w64-mingw32.shared-objdump)") |
| 27 | +parser.add_argument("--libs", help="where to search for libraries (optional) infers from objdump") |
| 28 | +parser.add_argument("target") |
| 29 | + |
| 30 | +args = parser.parse_args() |
| 31 | +if len(sys.argv) == 1 or not (args.libs or args.objdump): |
| 32 | + parser.print_help() |
| 33 | + sys.exit(1) |
| 34 | + |
| 35 | +target = os.path.expanduser(args.target) |
| 36 | +objdump_path = os.path.expanduser(args.objdump) |
| 37 | + |
| 38 | +if not args.build: |
| 39 | + build_path = os.path.expanduser(os.path.dirname(args.target)) + "/" |
| 40 | +else: |
| 41 | + build_path = os.path.expanduser(args.build) |
| 42 | + |
| 43 | +libs = args.libs |
| 44 | +if not args.libs: |
| 45 | + libs = objdump_path.replace('/bin', '').replace('-objdump','') |
| 46 | + |
| 47 | + |
| 48 | +# build_path = "/home/user/ClionProjects/project/build/" |
| 49 | +# libs = "/home/user/mxe/usr/i686-w64-mingw32.shared" |
| 50 | +# objdump_path = "/home/user/mxe/usr/bin/i686-w64-mingw32.shared-objdump" |
| 51 | +# target = "project.exe" |
| 52 | + |
| 53 | + |
| 54 | +def run_check(): |
| 55 | + return subprocess.getoutput("wine project.exe") |
| 56 | + |
| 57 | + |
| 58 | +def find_dll(dll): |
| 59 | + out = subprocess.getoutput("find " + libs + " | grep -i '" + dll+"$'") |
| 60 | + return out.strip('\n') |
| 61 | + |
| 62 | + |
| 63 | +def library_install_exe(out=''): |
| 64 | + out = run_check().splitlines() |
| 65 | + for line in out: |
| 66 | + # err = re.search('(err:module:import_dll (Library |Loading library)) (.*?\.dll) ', line) |
| 67 | + err = re.search('([^ ]+\.dll) \(which', line) |
| 68 | + if err is not None: |
| 69 | + |
| 70 | + dll = err.group(1) |
| 71 | + dll = find_dll(dll) |
| 72 | + if dll is not None: |
| 73 | + copy_command = "cp " + dll + " " + build_path |
| 74 | + print("copy: ", copy_command) |
| 75 | + subprocess.getoutput(copy_command) |
| 76 | + library_install_exe(out) |
| 77 | + |
| 78 | + |
| 79 | +def library_install_objdump(path, level): |
| 80 | + if path in skip_libs or path in done: |
| 81 | + return |
| 82 | + |
| 83 | + if level > 0: |
| 84 | + lib = find_dll(path) |
| 85 | + if lib == "": # not found |
| 86 | + skip_libs.append(path) |
| 87 | + print("Not found: " + path) |
| 88 | + return |
| 89 | + print(lib) |
| 90 | + subprocess.getoutput("cp " + lib + " " + build_path) |
| 91 | + |
| 92 | + else: |
| 93 | + print("Processing target " + path) |
| 94 | + lib = path |
| 95 | + |
| 96 | + done.append(path) |
| 97 | + |
| 98 | + command = objdump_path + " -p " + lib + " | grep -o ': .*\.dll$'" |
| 99 | + res = subprocess.getstatusoutput(command) |
| 100 | + if (res[0] > 0): |
| 101 | + print("Error: objdump failed with " + lib) |
| 102 | + else: |
| 103 | + dlls = subprocess.getoutput(command).split("\n") |
| 104 | + for line in dlls: |
| 105 | + dll = (line.split(": "))[1] |
| 106 | + if dll not in done and dll not in skip_libs: |
| 107 | + level += 1 |
| 108 | + library_install_objdump(dll, level) |
| 109 | + |
| 110 | +skip_libs = list() |
| 111 | +done = list() |
| 112 | + |
| 113 | + |
| 114 | +def main(): |
| 115 | + |
| 116 | + os.chdir(build_path) |
| 117 | + |
| 118 | + #library_install_exe(target) |
| 119 | + library_install_objdump(target, 0) |
| 120 | + |
| 121 | + pass |
| 122 | + |
| 123 | +main() |
0 commit comments