blob: 2dadfa9e672dc64131bee8ca5830c1ffa3ea5a5a [file] [log] [blame]
Jack Jansen6655c4e1995-09-01 12:03:32 +00001#
2# fullbuild creates everything that needs to be created before a
3# distribution can be made, and puts it all in the right place.
4#
5# It expects the projects to be in the places where Jack likes them:
Jack Jansenfaad9951997-09-01 15:37:07 +00006# in directories named like 'build.mac'. That is fixable,
Jack Jansen6655c4e1995-09-01 12:03:32 +00007# however.
8#
9# NOTE: You should proably make a copy of python with which to execute this
10# script, rebuilding running programs does not work...
11
Jack Jansenfaad9951997-09-01 15:37:07 +000012MACBUILDNO=":Mac:Include:macbuildno.h"
13
Jack Jansen6655c4e1995-09-01 12:03:32 +000014import os
15import sys
16import macfs
Jack Jansen1023dff1996-02-21 15:28:49 +000017import MacOS
Jack Jansenf04fa721996-04-10 14:51:14 +000018import EasyDialogs
Jack Jansenfaad9951997-09-01 15:37:07 +000019import regex
20import string
Jack Jansen6655c4e1995-09-01 12:03:32 +000021
Jack Jansen6655c4e1995-09-01 12:03:32 +000022import aetools
Jack Jansen1023dff1996-02-21 15:28:49 +000023import AppleEvents
Jack Jansen6655c4e1995-09-01 12:03:32 +000024from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite
Jack Jansen82bfde91997-08-27 14:10:29 +000025from CodeWarrior_Standard_Suite import CodeWarrior_Standard_Suite
Jack Jansen0f00c5e1997-05-06 16:15:32 +000026from Required_Suite import Required_Suite
27
28import Res
29import Dlg
Jack Jansen6655c4e1995-09-01 12:03:32 +000030
Jack Jansen490ec9c1998-07-31 09:45:27 +000031import buildtools
Jack Jansen0f00c5e1997-05-06 16:15:32 +000032import cfmfile
33
34# Dialog resource. Note that the item numbers should correspond
35# to those in the DITL resource. Also note that the order is important:
36# things are built in this order, so there should be no forward dependencies.
37DIALOG_ID = 512
38
39I_OK=1
40I_CANCEL=2
Jack Jansen675cda01997-09-09 13:57:15 +000041I_INC_BUILDNO=19
Jack Jansen0f00c5e1997-05-06 16:15:32 +000042
Jack Jansen82bfde91997-08-27 14:10:29 +000043I_CORE=3
Jack Jansen0f00c5e1997-05-06 16:15:32 +000044I_PPC_PLUGINS=4
45I_PPC_EXTENSIONS=5
Jack Jansen82bfde91997-08-27 14:10:29 +000046I_68K_PLUGINS=6
47I_68K_EXTENSIONS=7
48I_PPC_FULL=8
49I_PPC_SMALL=9
50I_68K_FULL=10
51I_68K_SMALL=11
52I_APPLETS=12
Jack Jansen0f00c5e1997-05-06 16:15:32 +000053
Jack Jansen82bfde91997-08-27 14:10:29 +000054N_BUTTONS=13
Jack Jansen6655c4e1995-09-01 12:03:32 +000055
Jack Jansen82bfde91997-08-27 14:10:29 +000056class MwShell(Metrowerks_Shell_Suite, CodeWarrior_Standard_Suite,
57 Required_Suite, aetools.TalkTo):
Jack Jansen6655c4e1995-09-01 12:03:32 +000058 pass
59
Jack Jansenf04fa721996-04-10 14:51:14 +000060RUNNING=[]
Jack Jansen6655c4e1995-09-01 12:03:32 +000061
62def buildmwproject(top, creator, projects):
63 """Build projects with an MW compiler"""
Jack Jansenb9e5e141996-09-20 15:30:52 +000064 mgr = MwShell(creator, start=1)
Jack Jansen1023dff1996-02-21 15:28:49 +000065 mgr.send_timeout = AppleEvents.kNoTimeOut
66
Jack Jansenbc66f952000-07-24 19:45:07 +000067 failed = []
Jack Jansen6655c4e1995-09-01 12:03:32 +000068 for file in projects:
Jack Jansen82bfde91997-08-27 14:10:29 +000069 if type(file) == type(()):
70 file, target = file
71 else:
72 target = ''
Jack Jansen6655c4e1995-09-01 12:03:32 +000073 file = os.path.join(top, file)
Just van Rossum2607a441999-01-30 18:27:12 +000074 try:
75 fss = macfs.FSSpec(file)
76 except ValueError:
77 print '** file not found:', file
78 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000079 print 'Building', file, target
Just van Rossum2607a441999-01-30 18:27:12 +000080 try:
81 mgr.open(fss)
82 except aetools.Error, detail:
83 print '**', detail, file
84 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000085 if target:
86 try:
87 mgr.Set_Current_Target(target)
88 except aetools.Error, arg:
89 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +000090 try:
91 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +000092 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +000093 print '**', file, target, 'Failed:', arg
Jack Jansenbc66f952000-07-24 19:45:07 +000094 failed.append(fss)
Jack Jansen6655c4e1995-09-01 12:03:32 +000095 mgr.Close_Project()
Jack Jansenbc66f952000-07-24 19:45:07 +000096 if failed:
97 print 'Open failed projects and exit?',
98 rv = sys.stdin.readline()
99 if rv[0] in ('y', 'Y'):
100 for fss in failed:
101 mgr.open(fss)
102 sys.exit(0)
Jack Jansenf04fa721996-04-10 14:51:14 +0000103## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000104
105def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000106 """Create python applets"""
Jack Jansen490ec9c1998-07-31 09:45:27 +0000107 template = buildtools.findtemplate()
Just van Rossum9d609b41999-02-01 01:21:18 +0000108 for src, dst in list:
Jack Jansen6655c4e1995-09-01 12:03:32 +0000109 if src[-3:] != '.py':
110 raise 'Should end in .py', src
111 base = os.path.basename(src)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000112 src = os.path.join(top, src)
Just van Rossum9d609b41999-02-01 01:21:18 +0000113 dst = os.path.join(top, dst)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000114 try:
115 os.unlink(dst)
116 except os.error:
117 pass
118 print 'Building applet', dst
Jack Jansen490ec9c1998-07-31 09:45:27 +0000119 buildtools.process(template, src, dst, 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000120
121def buildfat(top, dummy, list):
122 """Build fat binaries"""
123 for dst, src1, src2 in list:
124 dst = os.path.join(top, dst)
125 src1 = os.path.join(top, src1)
126 src2 = os.path.join(top, src2)
127 print 'Building fat binary', dst
128 cfmfile.mergecfmfiles((src1, src2), dst)
129
Jack Jansen675cda01997-09-09 13:57:15 +0000130def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000131 """Handle selection dialog, return list of selected items"""
132 d = Dlg.GetNewDialog(DIALOG_ID, -1)
133 d.SetDialogDefaultItem(I_OK)
134 d.SetDialogCancelItem(I_CANCEL)
135 results = [0]*N_BUTTONS
136 while 1:
137 n = Dlg.ModalDialog(None)
138 if n == I_OK:
139 break
140 if n == I_CANCEL:
141 return []
Jack Jansen675cda01997-09-09 13:57:15 +0000142 if n == I_INC_BUILDNO:
143 incbuildno(filename)
144 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000145 if n < len(results):
146 results[n] = (not results[n])
Jack Jansenc9b1e901999-12-24 13:39:23 +0000147 ctl = d.GetDialogItemAsControl(n)
148 ctl.SetControlValue(results[n])
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000149 rv = []
150 for i in range(len(results)):
151 if results[i]:
152 rv.append(i)
153 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000154
155#
156# The build instructions. Entries are (routine, arg, list-of-files)
157# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000158BUILD_DICT = {
Jack Jansen82bfde91997-08-27 14:10:29 +0000159I_CORE : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000160 (":Mac:Build:PythonCore.prj", "PythonCore"),
Jack Jansen3b805261999-02-14 23:12:06 +0000161 (":Mac:Build:PythonInterpreter.prj", "PythonInterpreter"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000162 ]),
163
164I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen89d017d2000-07-07 13:08:09 +0000165 (":Mac:Build:ucnhash.prj", "ucnhash.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000166 (":Mac:Build:calldll.ppc.prj", "calldll.ppc"),
167 (":Mac:Build:ctb.prj", "ctb.ppc"),
168 (":Mac:Build:gdbm.prj", "gdbm.ppc"),
169 (":Mac:Build:icglue.prj", "icglue.ppc"),
170 (":Mac:Build:macspeech.prj", "macspeech.ppc"),
171 (":Mac:Build:waste.prj", "waste.ppc"),
172 (":Mac:Build:zlib.prj", "zlib.ppc"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000173## (":Mac:Build:_tkinter.prj", "_tkinter.ppc"),
174 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000175 (":Mac:Build:ColorPicker.prj", "ColorPicker.ppc"),
176 (":Mac:Build:Printing.prj", "Printing.ppc"),
Jack Jansen57ed1391999-03-04 23:00:11 +0000177 (":Mac:Build:App.prj", "App.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000178 (":Mac:Build:Cm.prj", "Cm.ppc"),
Jack Jansen6c38e5b2000-04-08 21:29:31 +0000179 (":Mac:Build:Drag.prj", "Drag.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000180 (":Mac:Build:Fm.prj", "Fm.ppc"),
181 (":Mac:Build:Help.prj", "Help.ppc"),
182 (":Mac:Build:Icn.prj", "Icn.ppc"),
183 (":Mac:Build:List.prj", "List.ppc"),
Jack Jansen6a51b371999-03-07 23:10:32 +0000184 (":Mac:Build:Qdoffs.prj", "Qdoffs.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000185 (":Mac:Build:Qt.prj", "Qt.ppc"),
186 (":Mac:Build:Scrap.prj", "Scrap.ppc"),
187 (":Mac:Build:Snd.prj", "Snd.ppc"),
188 (":Mac:Build:Sndihooks.prj", "Sndihooks.ppc"),
189 (":Mac:Build:TE.prj", "TE.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000190 ]),
191
192I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen89d017d2000-07-07 13:08:09 +0000193 (":Mac:Build:ucnhash.prj", "ucnhash.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000194 (":Mac:Build:ctb.prj", "ctb.CFM68K"),
195 (":Mac:Build:gdbm.prj", "gdbm.CFM68K"),
196 (":Mac:Build:icglue.prj", "icglue.CFM68K"),
197 (":Mac:Build:waste.prj", "waste.CFM68K"),
198 (":Mac:Build:zlib.prj", "zlib.CFM68K"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000199## (":Mac:Build:_tkinter.prj", "_tkinter.CFM68K"),
200 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000201 (":Mac:Build:ColorPicker.prj", "ColorPicker.CFM68K"),
202 (":Mac:Build:Printing.prj", "Printing.CFM68K"),
Jack Jansen57ed1391999-03-04 23:00:11 +0000203 (":Mac:Build:App.prj", "App.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000204 (":Mac:Build:Cm.prj", "Cm.CFM68K"),
Jack Jansen6c38e5b2000-04-08 21:29:31 +0000205 (":Mac:Build:Drag.prj", "Drag.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000206 (":Mac:Build:Fm.prj", "Fm.CFM68K"),
207 (":Mac:Build:Help.prj", "Help.CFM68K"),
208 (":Mac:Build:Icn.prj", "Icn.CFM68K"),
209 (":Mac:Build:List.prj", "List.CFM68K"),
Jack Jansen6a51b371999-03-07 23:10:32 +0000210 (":Mac:Build:Qdoffs.prj", "Qdoffs.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000211 (":Mac:Build:Qt.prj", "Qt.CFM68K"),
212 (":Mac:Build:Scrap.prj", "Scrap.CFM68K"),
213 (":Mac:Build:Snd.prj", "Snd.CFM68K"),
214 (":Mac:Build:Sndihooks.prj", "Sndihooks.CFM68K"),
215 (":Mac:Build:TE.prj", "TE.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000216 ]),
217
218I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000219 (":Mac:Build:PythonStandalone.prj", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000220 ]),
221
222I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000223 (":Mac:Build:PythonStandSmall.prj", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000224 ]),
225
226I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000227 (":Mac:Build:PythonStandalone.prj", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000228 ]),
229
230I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000231 (":Mac:Build:PythonStandSmall.prj", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000232 ]),
233
234I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000235 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000236## (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
Jack Jansen8eea5ba1999-02-06 17:44:28 +0000237 (":Extensions:img:Mac:imgmodules.prj", "imgmodules PPC"),
Just van Rossum7bcd84d1999-02-02 23:58:50 +0000238 (":Extensions:Numerical:Mac:numpymodules.prj", "multiarraymodule"),
239 (":Extensions:Numerical:Mac:numpymodules.prj", "_numpy"),
240 (":Extensions:Numerical:Mac:numpymodules.prj", "umathmodule"),
241 (":Extensions:Numerical:Mac:numpymodules.prj", "fast_umathmodule"),
242 (":Extensions:Numerical:Mac:numpymodules.prj", "fftpackmodule"),
243 (":Extensions:Numerical:Mac:numpymodules.prj", "lapack_litemodule"),
244 (":Extensions:Numerical:Mac:numpymodules.prj", "ranlibmodule"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000245 ]),
246
247I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000248 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000249## (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
Jack Jansen8eea5ba1999-02-06 17:44:28 +0000250 (":Extensions:img:Mac:imgmodules.prj", "imgmodules CFM68K"),
Just van Rossum7bcd84d1999-02-02 23:58:50 +0000251## (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000252 ]),
253
254I_APPLETS : (buildapplet, None, [
Just van Rossum9d609b41999-02-01 01:21:18 +0000255 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs"),
256 (":Mac:scripts:BuildApplet.py", "BuildApplet"),
257 (":Mac:scripts:BuildApplication.py", "BuildApplication"),
258 (":Mac:scripts:ConfigurePython.py", "ConfigurePython"),
259 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE"),
Just van Rossumf84fdfe2000-03-28 20:50:36 +0000260 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave"),
261 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000262 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000263}
Jack Jansenfaad9951997-09-01 15:37:07 +0000264
265def incbuildno(filename):
266 fp = open(filename)
267 line = fp.readline()
268 fp.close()
269
270 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
271 pat.match(line)
272 buildno = pat.group(1)
273 if not buildno:
274 raise 'Incorrect macbuildno.h line', line
275 new = string.atoi(buildno) + 1
276 fp = open(filename, 'w')
277 fp.write('#define BUILD %d\n'%new)
278 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000279
280def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000281 try:
Jack Jansend13c3852000-06-20 21:59:25 +0000282 h = Res.FSpOpenResFile('fullbuild.rsrc', 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000283 except Res.Error:
284 pass # Assume we already have acces to our own resource
285
Jack Jansen6655c4e1995-09-01 12:03:32 +0000286 dir, ok = macfs.GetDirectory('Python source folder:')
287 if not ok:
288 sys.exit(0)
289 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000290
Jack Jansen675cda01997-09-09 13:57:15 +0000291 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
292
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000293 instructions = []
294 for i in todo:
295 instructions.append(BUILD_DICT[i])
296
297 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000298 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000299
Jack Jansen6655c4e1995-09-01 12:03:32 +0000300 print "All done!"
301 sys.exit(1)
302
303if __name__ == '__main__':
304 main()
305