4
from distutils.dir_util import copy_tree
5
from datetime import datetime
8
def findDependencies(exeFiles, exePath):
9
"Return a dictionary of MachO.Fixes of all recursive dependencies"
12
# allow some sloppyness:
13
if isinstance(exeFiles, str):
14
exeFiles = [MachO.Executable(exeFiles, "executable")]
15
elif isinstance(exeFiles, MachO.Executable):
18
# go through executables and store Fixes
19
todo = [x for x in exeFiles]
20
done = [x.Location for x in exeFiles]
23
print "getting dependencies for " + current.Location
24
for dep in current.getDependencies():
25
if dep.Link not in result:
26
if dep.findLocation(exePath):
27
result[dep.Link] = dep
28
# check if we need to traverse the referenced lib
29
if not dep.isSystem() and dep.Location not in done:
30
print "- adding " + dep.Location
31
done.append(dep.Location)
32
todo.append(MachO.Executable(dep.Location, "lib"))
34
print ("couldn't find " + dep.Link +
35
" -> " + dep.Location)
37
# forget any system dependencies
38
for k,fix in result.items():
45
def ingest(bundle, exceptions=[], strippedFrameworks=[]):
46
"Moves all needed non-System libraries inside the bundle and fixes links"
47
# step 1: find all executables
48
executables = MachO.findExecutables(bundle)
49
# find the bundle executable
50
pat = re.compile("executable")
52
for exe in executables:
53
if pat.match(exe.Kind):
54
exePath = os.path.dirname(exe.Location)
55
print "using @executable_path=" + exePath
57
# step 2: find all dependencies
58
fixes = findDependencies(executables, exePath)
59
# step 3: move all libraries which are not excepted
61
frameworks = os.path.join(bundle, "Contents/Frameworks")
62
if not os.path.exists(frameworks):
63
log.append(">> mkdir " + frameworks)
64
os.makedirs(frameworks, 0755)
65
for k,fix in fixes.items():
66
if fix.Location in exceptions or fix.Link in exceptions:
69
stripFW = fix.Location in strippedFrameworks
70
executables.extend(fix.moveLibrary(bundle, stripFW, log))
72
# step 3.5: copy aspell dictionaries, hacked for aspell via macports for now, #7371
73
aspellsrcpath = "/opt/local/share/aspell"
74
if os.path.exists(aspellsrcpath):
75
aspelldestpath = os.path.join(bundle, "Contents/share/aspell")
76
if not os.path.exists(aspelldestpath):
77
log.append(">> mkdir " + aspelldestpath)
78
os.makedirs(aspelldestpath, 0755)
79
if os.path.exists(aspelldestpath):
80
log.append(">> copying aspell dictionaries")
81
print "copying aspell dictionaries"
82
copy_tree(aspellsrcpath, aspelldestpath)
84
# step 4: fix all executables
85
for exe in executables:
86
exe.applyFixes(fixes, log)
88
logfile = file(os.path.join(bundle, "Contents/osxtools.log"), "a")
89
logfile.write("ingest at " + datetime.now().isoformat(" ") + "\n")
91
logfile.write(e + "\n")
95
def createSymlinks(bundle, links):
98
print "chdir to " + os.path.join(bundle, os.path.dirname(lnk))
99
os.chdir(os.path.join(bundle, os.path.dirname(lnk)))
100
print "symlink " + os.path.basename(lnk) + " -> " + tar
101
os.symlink(tar, os.path.basename(lnk))
105
def relinkOld(FILE, LIBDIR, INSTALLDIR):
106
#LIBS=`otool -L $FILE | sed 's/\([^(]*\)(.*)/\1/g'`
107
#for LIB in $LIBS ; do
108
# LNAM=`basename $LIB`
109
# if [ $FILE -ef $LIBDIR/$LNAM ] ; then
110
# install_name_tool -id $INSTALLDIR$LNAM $FILE
111
# elif [ -e $LIBDIR/$LNAM ] ; then
112
# install_name_tool -change $LIB $INSTALLDIR$LNAM $FILE