2018-06-26 21:50:33 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
This script is used to collect all available DLLs
|
|
|
|
"""
|
|
|
|
from __future__ import print_function
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import platform
|
|
|
|
import subprocess
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
def main():
|
|
|
|
ap = argparse.ArgumentParser()
|
|
|
|
ap.add_argument('prog')
|
|
|
|
ap.add_argument('dest')
|
|
|
|
args = ap.parse_args()
|
|
|
|
|
|
|
|
if not os.path.exists(args.dest):
|
|
|
|
os.mkdir(args.dest)
|
|
|
|
elif not os.path.isdir(args.dest):
|
|
|
|
print('File exists with destination name')
|
|
|
|
sys.exit(1)
|
2019-01-28 05:28:53 +00:00
|
|
|
|
2018-07-17 03:42:48 +00:00
|
|
|
try:
|
|
|
|
subprocess.check_output(['cygpath', '--help'])
|
|
|
|
except OSError as err:
|
|
|
|
print("Couldn't execute cygpath (Reason: '%s')." % err)
|
|
|
|
print("Make sure you're using a recent version of MSYS2 and that it works correctly.")
|
|
|
|
sys.exit(1)
|
2018-06-26 21:50:33 +00:00
|
|
|
|
2019-01-28 05:28:53 +00:00
|
|
|
sout = subprocess.check_output(['ldd', args.prog]).decode('utf-8')
|
2018-06-26 21:50:33 +00:00
|
|
|
for line in sout.splitlines():
|
|
|
|
line = line.strip().split()
|
2020-04-28 08:03:48 +00:00
|
|
|
dll_name, original_dll_path, dll_load_addr = line[0], line[2], line[3]
|
2018-06-26 21:50:33 +00:00
|
|
|
if dll_name.startswith('???'):
|
|
|
|
print('Unknown DLL?')
|
|
|
|
continue
|
2020-04-28 08:03:48 +00:00
|
|
|
|
2018-07-17 03:42:48 +00:00
|
|
|
# ldd on msys gives Unix-style paths, but mingw Python wants them Windows-style
|
|
|
|
# Use cygpath to convert the paths, because both mingw and msys Python can handle them
|
2020-04-28 08:03:48 +00:00
|
|
|
# Force lookup against /mingw64/bin to avoid external DLLs
|
|
|
|
dll_path = '/mingw64/bin/' + dll_name
|
2019-01-28 05:28:53 +00:00
|
|
|
dll_path = subprocess.check_output(['cygpath', '-w', dll_path]).decode('utf-8').strip()
|
2020-04-28 08:03:48 +00:00
|
|
|
if not os.path.exists(dll_path):
|
|
|
|
print('Skipping DLL outside /mingw64/bin: %s' % original_dll_path)
|
2018-06-26 21:50:33 +00:00
|
|
|
continue
|
2018-07-17 03:42:48 +00:00
|
|
|
|
|
|
|
dest_path = os.path.join(args.dest, dll_name)
|
|
|
|
if os.path.normcase(os.path.realpath(dll_path)) == os.path.normcase(os.path.realpath(dest_path)):
|
|
|
|
# If the DLL is already in the same folder as the executable,
|
|
|
|
# ldd will return the path to that DLL and copyfile will raise an exception
|
|
|
|
# because we try to copy a file over itself
|
|
|
|
print('DLL %s is already next to executable. Skipping copy.' % dll_name)
|
|
|
|
else:
|
|
|
|
print('Copying %s...' % dll_path)
|
|
|
|
shutil.copyfile(dll_path, dest_path)
|
2018-06-26 21:50:33 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|