/[ascend]/trunk/scons/installgtk.py
ViewVC logotype

Contents of /trunk/scons/installgtk.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2139 - (show annotations) (download) (as text)
Sat Dec 19 08:20:14 2009 UTC (14 years, 6 months ago) by jpye
File MIME type: text/x-python
File size: 6089 byte(s)
Very close now, libraries are being rerouted but the paths still aren't correct.
1 # SCons support for bundled GTK installation
2 # Written by John Pye, Nov 2009
3
4
5 """
6 This tool provides SCons support for installing the necessary files to allow
7 GTK to run in a standalone installation.
8
9 This approach is suitable for Mac (and maybe Windows too) where we often must
10 assume that GTK+ is not separately installed on the system, or can't assume that
11 the version will be compatible.
12
13 Ultimately, it would be desirable for a Mac 'framework' to be utilised for this
14 purpose, but that is not yet available.
15
16 Currently, this tool is a command-line thing that you must run after ASCEND
17 has been compiled, but before you run 'scons install'. It will copy all the
18 necessary files into dist/gtk.bundle; these files will then be copied by SCons
19 into their files (.dmg preparation folder) location.
20 """
21
22 #import SCons.Builder
23 #import SCons.Util
24 #import SCons.Scanner
25 import os.path
26 import glob
27 import subprocess, sys, os.path, re, shutil
28
29 otool_re = re.compile(r"""\s+(.+)\s\(compatibility version (.*), current version (.*)\)""")
30
31 def find_deps(binary):
32 deps = set()
33 P = subprocess.Popen(['/usr/bin/otool','-L',binary],stdout=subprocess.PIPE)
34 O = P.communicate()[0].strip()
35 for o in O.split("\n")[1:]:
36 m = otool_re.match(o)
37 #print " -->",m.group(1)
38 deps.add(m.group(1))
39 return deps
40
41 def reroute_deps(lib,gtksite,pysite):
42 deps = find_deps(lib)
43 for d in deps:
44 oldpath = d
45 r = os.path.commonprefix([oldpath,gtksite])
46 if r == gtksite:
47 # this dependency is pointing into the GTK installation location
48 c = os.path.commonprefix([lib,gtksite])
49 newpath = "@executable_path/gtk.bundle/gtk/" + oldpath[len(r):]
50 else:
51 r = os.path.commonprefix([oldpath,pysite])
52 if r == pysite:
53 # this dependency is pointing to a file installed inside Python
54 newpath = "@executable_path/gtk.bundle/python/" + oldpath[len(r):]
55 else:
56 continue
57
58 cmd = ['/usr/bin/install_name_tool','-change',oldpath,newpath,lib]
59 #print "RELINK %s: %s --> %s" % (lib,oldpath,newpath)
60 #print " ".join(cmd)
61 P = subprocess.Popen(cmd,stdout=subprocess.PIPE)
62 P.communicate()
63
64 def generate(env):
65 pass
66
67 def exists(env):
68 pass
69
70 if __name__ == "__main__":
71 import modulefinder
72 M = modulefinder.ModuleFinder()
73 sys.path.append("..")
74 script = os.path.normpath(os.path.join(sys.path[0],"../pygtk/gtkbrowser.py"))
75 M.run_script(script)
76
77 imports = set()
78 ignore_paths = ['/System/Library/Frameworks/Python.framework'
79 ,'/System/Library/Frameworks/Carbon.framework'
80 ,'/System/Library/Frameworks/Cocoa.framework'
81 ,'/usr/lib'
82 ,os.path.dirname(script)]
83 for name, m in M.modules.items():
84 if not m.__file__:
85 continue
86 ok = True
87 for i in ignore_paths:
88 if os.path.commonprefix([i,m.__file__]) == i:
89 ok = False
90 if ok is False:
91 continue
92
93 imports.add(m)
94 print m
95
96 print "\n\nChecking otool deps"
97
98 files = set()
99 pyfiles = set()
100 for m in imports:
101 files.add(m.__file__)
102
103 if m.__file__[-3:] == ".so":
104 print "FILE:",m.__file__
105 files |= find_deps(m.__file__)
106
107 elif m.__file__[-3:] == ".py":
108 print "PY:",m.__file__
109 pyfiles.add(m.__file__)
110
111 print "\n\nOTOOL DEPS"
112 for f in files:
113 if f[-3:] != ".py":
114 print f
115
116 print "\n\nRemoving system libs from list"
117 realimports = set()
118 #ignore_paths += ['/usr/lib']
119 for f in files:
120 ok = True
121 for i in ignore_paths:
122 if os.path.commonprefix([i,f]) == i:
123 ok = False
124 if ok is False:
125 #print "REMOVE",f
126 continue
127 realimports.add(f)
128 print f
129
130 distpath = os.path.normpath(os.path.join(sys.path[0],"../dist"))
131 if not os.path.exists(distpath):
132 os.mkdir(distpath)
133 targetpath=os.path.join(distpath,"gtk.bundle")
134 if not os.path.exists(targetpath):
135 os.mkdir(targetpath)
136
137 pytarget=os.path.join(targetpath,"python")
138 if not os.path.exists(pytarget):
139 os.mkdir(pytarget)
140 print "PYTHON TARGET =",pytarget
141
142
143 print "\nCopying Python includes"
144 pysite="/Library/Python/2.5/site-packages/"
145 if pysite[-1:]!="/":
146 raise RuntimeError("missing trailing slash in pysite")
147
148 gtksite = os.path.expanduser("~/gtk/inst/")
149 if gtksite[-1:]!="/":
150 raise RuntimeError("missing trailing slash in gtksite")
151
152 for f in pyfiles:
153 if os.path.commonprefix([f,pysite]) == pysite:
154 r = f[len(pysite):]
155 else:
156 raise RuntimeError("Unknown python file location '%s'" % f)
157
158 dir,f1 = os.path.split(r)
159 if not os.path.exists(os.path.join(pytarget,dir)):
160 print "Create directory '%s'"% dir
161 os.makedirs(os.path.join(pytarget,dir))
162
163 print "Copy %s --> %s" % (f, os.path.join(pytarget,r))
164 shutil.copy(f,os.path.join(pytarget,r))
165
166 print "\nCopying Python shared libraries and rerouting"
167 copied = set()
168 for f in realimports:
169 if os.path.commonprefix([f,pysite]) == pysite:
170 r = f[len(pysite):]
171 else:
172 continue
173 print "Copy %s --> %s" % (f, os.path.join(pytarget,r))
174
175 dir,f1 = os.path.split(r)
176 if not os.path.exists(os.path.join(pytarget,dir)):
177 print "Create directory '%s'"% dir
178 os.makedirs(os.path.join(pytarget,dir))
179
180 t = os.path.join(pytarget,r)
181 shutil.copy(f,t)
182 copied.add(f)
183
184 reroute_deps(t,gtksite,pysite)
185
186
187 print "\nCopying GTK libraries and rerouting"
188 gtktarget = os.path.join(targetpath,"gtk")
189 if not os.path.exists(gtktarget):
190 os.mkdir(gtktarget)
191
192 for f in realimports:
193 if os.path.commonprefix([f,gtksite]) == gtksite:
194 r = f[len(gtksite):]
195 else:
196 continue
197
198 dir,f1 = os.path.split(r)
199 if not os.path.exists(os.path.join(gtktarget,dir)):
200 print "Create directory '%s'"% dir
201 os.makedirs(os.path.join(gtktarget,dir))
202
203 print "Copy %s --> %s" % (f, os.path.join(gtktarget,r))
204 t = os.path.join(gtktarget,r)
205 shutil.copy(f,t)
206 copied.add(f)
207
208 reroute_deps(t,gtksite,pysite)
209
210 if copied != realimports:
211 print "\nError: some library files were not copied:"
212 for f in realimports - copied:
213 print f
214
215
216
217 # ETC="$PREFIX/etc/gimp/ $PREFIX/etc/gtk-2.0/ $PREFIX/etc/pango/ $PREFIX/lib/gimp/2.0/python/*.py* $PREFIX/lib/gimp/2.0/environ $PREFIX/lib/gimp/2.0/interpreters $PREFIX/etc/fonts"
218
219 # get the 'etc' files for GTK, Pango, fonts
220
221
222
223 #SHARE=`echo $PREFIX/share/gimp/ $PREFIX/share/locale/*/LC_MESSAGES/gimp*`
224
225 # get the share files for
226

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22