diff --git a/get_deps.py b/get_deps.py index 8ee9a516a2..0fcd01abea 100755 --- a/get_deps.py +++ b/get_deps.py @@ -22,6 +22,13 @@ def main(): elif not os.path.isdir(args.dest): print('File exists with destination name') sys.exit(1) + + 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) sout = subprocess.check_output(['ldd', args.prog]) for line in sout.splitlines(): @@ -30,11 +37,22 @@ def main(): if dll_name.startswith('???'): print('Unknown DLL?') continue - if dll_path.lower().startswith('/c/windows') or dll_path.lower().startswith('c:/windows'): + # 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 + dll_path = subprocess.check_output(['cygpath', '-w', dll_path]).strip() + if dll_path.lower().startswith('c:\\windows'): print('Skipping system DLL %s' % dll_path) continue - print('Copying %s...' % dll_path) - shutil.copyfile(dll_path, os.path.join(args.dest, dll_name)) + + 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) if __name__ == '__main__': main()