Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows|Cygwin: Script for deploying Cygwin libraries
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/python | ||
# This script goes through a Cygwin deployment and copies all the required | ||
# dependencies from the system directory. All executables (EXE, DLL) are | ||
# checked. | ||
|
||
from __future__ import print_function | ||
|
||
import sys, os, shutil, subprocess, re, platform | ||
if not platform.system().startswith('CYGWIN_'): | ||
raise Exception('Please run under cygwin') | ||
system_bin = '/bin' | ||
objdump_cmd = '/bin/objdump' | ||
root = os.path.join(sys.argv[1]) | ||
binaries = set(filter(lambda n: os.path.splitext(n)[1].lower() in ['.exe', '.dll'], | ||
os.listdir(root))) | ||
while binaries: | ||
binary = binaries.pop() | ||
if binary.startswith('lib'): | ||
# Not a cygwin library. | ||
continue | ||
print('--', binary) | ||
bin_path = os.path.join(root, binary) | ||
deps = subprocess.check_output([objdump_cmd, '-p', bin_path]).decode() | ||
for deps_line in deps.split('\n'): | ||
found = re.search('DLL Name: (.*)', deps_line) | ||
if found: | ||
dll_name = found.group(1).strip() | ||
dll_path = os.path.join(system_bin, dll_name) | ||
dest_path = os.path.join(root, dll_name) | ||
if os.path.exists(dll_path) and not os.path.exists(dest_path): | ||
# Copy this dependency. | ||
print(dll_path) | ||
shutil.copy(dll_path, dest_path) | ||
binaries.add(dest_path) |