When the classes in wave.py opened files themselves, their .close() methods
[python/dscho.git] / Mac / scripts / fullbuild.py
blob30c2c7c7ce87e3ea22e4d1b7e321b83ef0a43837
2 # fullbuild creates everything that needs to be created before a
3 # distribution can be made, and puts it all in the right place.
5 # It expects the projects to be in the places where Jack likes them:
6 # in directories named like 'build.mac'. That is fixable,
7 # however.
9 # NOTE: You should proably make a copy of python with which to execute this
10 # script, rebuilding running programs does not work...
12 MACBUILDNO=":Mac:Include:macbuildno.h"
14 import os
15 import sys
16 import macfs
17 import MacOS
18 import EasyDialogs
19 import regex
20 import string
22 import aetools
23 import AppleEvents
25 OLDAESUPPORT = 0
27 if OLDAESUPPORT:
28 from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite
29 from CodeWarrior_suite import CodeWarrior_suite
30 from Metrowerks_Standard_Suite import Metrowerks_Standard_Suite
31 from Required_Suite import Required_Suite
32 else:
33 import CodeWarrior
35 import Res
36 import Dlg
38 import buildtools
39 import cfmfile
41 # Dialog resource. Note that the item numbers should correspond
42 # to those in the DITL resource. Also note that the order is important:
43 # things are built in this order, so there should be no forward dependencies.
44 DIALOG_ID = 512
46 I_OK=1
47 I_CANCEL=2
48 I_INC_BUILDNO=19
50 I_CORE=3
51 I_PPC_PLUGINS=4
52 I_PPC_EXTENSIONS=5
53 I_68K_PLUGINS=6
54 I_68K_EXTENSIONS=7
55 I_PPC_FULL=8
56 I_PPC_SMALL=9
57 I_68K_FULL=10
58 I_68K_SMALL=11
59 I_APPLETS=12
61 N_BUTTONS=13
63 if OLDAESUPPORT:
64 class MwShell(Metrowerks_Shell_Suite, CodeWarrior_suite, Metrowerks_Standard_Suite,
65 Required_Suite, aetools.TalkTo):
66 pass
67 else:
68 MwShell = CodeWarrior.CodeWarrior
70 RUNNING=[]
72 def buildmwproject(top, creator, projects):
73 """Build projects with an MW compiler"""
74 mgr = MwShell(creator, start=1)
75 mgr.send_timeout = AppleEvents.kNoTimeOut
77 failed = []
78 for file in projects:
79 if type(file) == type(()):
80 file, target = file
81 else:
82 target = ''
83 file = os.path.join(top, file)
84 try:
85 fss = macfs.FSSpec(file)
86 except ValueError:
87 print '** file not found:', file
88 continue
89 print 'Building', file, target
90 try:
91 mgr.open(fss)
92 except aetools.Error, detail:
93 print '**', detail, file
94 continue
95 if target:
96 try:
97 mgr.Set_Current_Target(target)
98 except aetools.Error, arg:
99 print '**', file, target, 'Cannot select:', arg
100 try:
101 mgr.Make_Project()
102 except aetools.Error, arg:
103 print '**', file, target, 'Failed:', arg
104 failed.append(fss)
105 mgr.Close_Project()
106 if failed:
107 print 'Open failed projects and exit?',
108 rv = sys.stdin.readline()
109 if rv[0] in ('y', 'Y'):
110 for fss in failed:
111 mgr.open(fss)
112 sys.exit(0)
113 ## mgr.quit()
115 def buildapplet(top, dummy, list):
116 """Create python applets"""
117 template = buildtools.findtemplate()
118 for src, dst in list:
119 if src[-3:] != '.py':
120 raise 'Should end in .py', src
121 base = os.path.basename(src)
122 src = os.path.join(top, src)
123 dst = os.path.join(top, dst)
124 try:
125 os.unlink(dst)
126 except os.error:
127 pass
128 print 'Building applet', dst
129 buildtools.process(template, src, dst, 1)
131 def buildfat(top, dummy, list):
132 """Build fat binaries"""
133 for dst, src1, src2 in list:
134 dst = os.path.join(top, dst)
135 src1 = os.path.join(top, src1)
136 src2 = os.path.join(top, src2)
137 print 'Building fat binary', dst
138 cfmfile.mergecfmfiles((src1, src2), dst)
140 def handle_dialog(filename):
141 """Handle selection dialog, return list of selected items"""
142 d = Dlg.GetNewDialog(DIALOG_ID, -1)
143 d.SetDialogDefaultItem(I_OK)
144 d.SetDialogCancelItem(I_CANCEL)
145 results = [0]*N_BUTTONS
146 while 1:
147 n = Dlg.ModalDialog(None)
148 if n == I_OK:
149 break
150 if n == I_CANCEL:
151 return []
152 if n == I_INC_BUILDNO:
153 incbuildno(filename)
154 continue
155 if n < len(results):
156 results[n] = (not results[n])
157 ctl = d.GetDialogItemAsControl(n)
158 ctl.SetControlValue(results[n])
159 rv = []
160 for i in range(len(results)):
161 if results[i]:
162 rv.append(i)
163 return rv
166 # The build instructions. Entries are (routine, arg, list-of-files)
167 # XXXX We could also include the builds for stdwin and such here...
168 BUILD_DICT = {
169 I_CORE : (buildmwproject, "CWIE", [
170 (":Mac:Build:PythonCore.prj", "PythonCore"),
171 (":Mac:Build:PythonInterpreter.prj", "PythonInterpreter"),
174 I_PPC_PLUGINS : (buildmwproject, "CWIE", [
175 (":Mac:Build:ucnhash.prj", "ucnhash.ppc"),
176 (":Mac:Build:pyexpat.prj", "pyexpat.ppc"),
177 (":Mac:Build:calldll.ppc.prj", "calldll.ppc"),
178 (":Mac:Build:ctb.prj", "ctb.ppc"),
179 (":Mac:Build:gdbm.prj", "gdbm.ppc"),
180 (":Mac:Build:icglue.prj", "icglue.ppc"),
181 (":Mac:Build:macspeech.prj", "macspeech.ppc"),
182 (":Mac:Build:waste.prj", "waste.ppc"),
183 (":Mac:Build:zlib.prj", "zlib.ppc"),
184 ## (":Mac:Build:_tkinter.prj", "_tkinter.ppc"),
185 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
186 (":Mac:Build:ColorPicker.prj", "ColorPicker.ppc"),
187 (":Mac:Build:Printing.prj", "Printing.ppc"),
188 (":Mac:Build:App.prj", "App.ppc"),
189 (":Mac:Build:Cm.prj", "Cm.ppc"),
190 (":Mac:Build:Drag.prj", "Drag.ppc"),
191 (":Mac:Build:Fm.prj", "Fm.ppc"),
192 (":Mac:Build:Help.prj", "Help.ppc"),
193 (":Mac:Build:Icn.prj", "Icn.ppc"),
194 (":Mac:Build:List.prj", "List.ppc"),
195 (":Mac:Build:Qdoffs.prj", "Qdoffs.ppc"),
196 (":Mac:Build:Qt.prj", "Qt.ppc"),
197 (":Mac:Build:Scrap.prj", "Scrap.ppc"),
198 (":Mac:Build:Snd.prj", "Snd.ppc"),
199 (":Mac:Build:Sndihooks.prj", "Sndihooks.ppc"),
200 (":Mac:Build:TE.prj", "TE.ppc"),
203 I_68K_PLUGINS : (buildmwproject, "CWIE", [
204 (":Mac:Build:ucnhash.prj", "ucnhash.CFM68K"),
205 (":Mac:Build:ucnhash.prj", "ucnhash.CFM68K"),
206 (":Mac:Build:ctb.prj", "ctb.CFM68K"),
207 (":Mac:Build:gdbm.prj", "gdbm.CFM68K"),
208 (":Mac:Build:icglue.prj", "icglue.CFM68K"),
209 (":Mac:Build:waste.prj", "waste.CFM68K"),
210 (":Mac:Build:zlib.prj", "zlib.CFM68K"),
211 ## (":Mac:Build:_tkinter.prj", "_tkinter.CFM68K"),
212 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
213 (":Mac:Build:ColorPicker.prj", "ColorPicker.CFM68K"),
214 (":Mac:Build:Printing.prj", "Printing.CFM68K"),
215 (":Mac:Build:App.prj", "App.CFM68K"),
216 (":Mac:Build:Cm.prj", "Cm.CFM68K"),
217 (":Mac:Build:Drag.prj", "Drag.CFM68K"),
218 (":Mac:Build:Fm.prj", "Fm.CFM68K"),
219 (":Mac:Build:Help.prj", "Help.CFM68K"),
220 (":Mac:Build:Icn.prj", "Icn.CFM68K"),
221 (":Mac:Build:List.prj", "List.CFM68K"),
222 (":Mac:Build:Qdoffs.prj", "Qdoffs.CFM68K"),
223 (":Mac:Build:Qt.prj", "Qt.CFM68K"),
224 (":Mac:Build:Scrap.prj", "Scrap.CFM68K"),
225 (":Mac:Build:Snd.prj", "Snd.CFM68K"),
226 (":Mac:Build:Sndihooks.prj", "Sndihooks.CFM68K"),
227 (":Mac:Build:TE.prj", "TE.CFM68K"),
230 I_68K_FULL : (buildmwproject, "CWIE", [
231 (":Mac:Build:PythonStandalone.prj", "Python68K"),
234 I_68K_SMALL : (buildmwproject, "CWIE", [
235 (":Mac:Build:PythonStandSmall.prj", "PythonSmall68K"),
238 I_PPC_FULL : (buildmwproject, "CWIE", [
239 (":Mac:Build:PythonStandalone.prj", "PythonStandalone"),
242 I_PPC_SMALL : (buildmwproject, "CWIE", [
243 (":Mac:Build:PythonStandSmall.prj", "PythonStandSmall"),
246 I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
247 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
248 ## (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
249 (":Extensions:img:Mac:imgmodules.prj", "imgmodules PPC"),
250 (":Extensions:Numerical:Mac:numpymodules.prj", "multiarraymodule"),
251 (":Extensions:Numerical:Mac:numpymodules.prj", "_numpy"),
252 (":Extensions:Numerical:Mac:numpymodules.prj", "umathmodule"),
253 (":Extensions:Numerical:Mac:numpymodules.prj", "lapack_litemodule"),
254 (":Extensions:Numerical:Mac:numpymodules.prj", "ranlibmodule"),
257 I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
258 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
259 ## (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
260 (":Extensions:img:Mac:imgmodules.prj", "imgmodules CFM68K"),
261 ## (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
264 I_APPLETS : (buildapplet, None, [
265 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs"),
266 (":Mac:scripts:BuildApplet.py", "BuildApplet"),
267 (":Mac:scripts:BuildApplication.py", "BuildApplication"),
268 (":Mac:scripts:ConfigurePython.py", "ConfigurePython"),
269 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE"),
270 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave"),
271 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet"),
275 def incbuildno(filename):
276 fp = open(filename)
277 line = fp.readline()
278 fp.close()
280 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
281 pat.match(line)
282 buildno = pat.group(1)
283 if not buildno:
284 raise 'Incorrect macbuildno.h line', line
285 new = string.atoi(buildno) + 1
286 fp = open(filename, 'w')
287 fp.write('#define BUILD %d\n'%new)
288 fp.close()
290 def main():
291 try:
292 h = Res.FSpOpenResFile('fullbuild.rsrc', 1)
293 except Res.Error:
294 pass # Assume we already have acces to our own resource
296 dir, ok = macfs.GetDirectory('Python source folder:')
297 if not ok:
298 sys.exit(0)
299 dir = dir.as_pathname()
301 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
303 instructions = []
304 for i in todo:
305 instructions.append(BUILD_DICT[i])
307 for routine, arg, list in instructions:
308 routine(dir, arg, list)
310 print "All done!"
311 sys.exit(1)
313 if __name__ == '__main__':
314 main()