Subversion Repositories Scribus

Rev

Rev 12462 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12462 avox 1
import os
2
import re
3
import MachO
13180 cbradney 4
from distutils.dir_util import copy_tree
12462 avox 5
from datetime import datetime
6
 
7
 
8
def findDependencies(exeFiles, exePath):
9
        "Return a dictionary of MachO.Fixes of all recursive dependencies"
10
        result = {}
11
 
12
        # allow some sloppyness:
13
        if isinstance(exeFiles, str):
14
                exeFiles = [MachO.Executable(exeFiles, "executable")]
15
        elif isinstance(exeFiles, MachO.Executable):
16
                exeFiles = [exeFiles]
17
 
18
        # go through executables and store Fixes                
19
        todo = [x for x in exeFiles]
20
        done = [x.Location for x in exeFiles]
21
        while len(todo) > 0:
22
                current = todo.pop()
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"))
33
                                else:
34
                                        print ("couldn't find " + dep.Link +
35
                                                        " -> " + dep.Location)
36
 
37
        # forget any system dependencies
38
        for k,fix in result.items():
39
                if fix.isSystem():
40
                        del result[k]
41
 
42
        return result
43
 
44
 
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")
51
        exePath = ""
52
        for exe in executables:
53
                if pat.match(exe.Kind):
54
                        exePath = os.path.dirname(exe.Location)
55
                        print "using @executable_path=" + exePath
56
                        break
57
        # step 2: find all dependencies
58
        fixes = findDependencies(executables, exePath)
59
        # step 3: move all libraries which are not excepted
60
        log = []
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:
67
                        del fixes[k]
68
                else:
69
                        stripFW = fix.Location in strippedFrameworks
70
                        executables.extend(fix.moveLibrary(bundle, stripFW, log))
13180 cbradney 71
 
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)
83
 
12462 avox 84
        # step 4: fix all executables
85
        for exe in executables:
86
                exe.applyFixes(fixes, log)
87
        # step 5: write log
88
        logfile = file(os.path.join(bundle, "Contents/osxtools.log"), "a")
89
        logfile.write("ingest at " + datetime.now().isoformat(" ") + "\n")
90
        for e in log:
91
                logfile.write(e + "\n")
92
        logfile.close()
93
 
94
 
95
def createSymlinks(bundle, links):
96
        currDir = os.getcwd()
97
        for lnk,tar in 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))
102
        os.chdir(currDir)
103
 
104
 
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
113
        pass
114