blob: fef2a42ea5a33debba3e17927222172cd0733e7e [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 Jansen87426b92000-08-17 22:12:12 +000024
25OLDAESUPPORT = 0
26
27if 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
32else:
33 import CodeWarrior
Jack Jansen0f00c5e1997-05-06 16:15:32 +000034
35import Res
36import Dlg
Jack Jansen6655c4e1995-09-01 12:03:32 +000037
Jack Jansen490ec9c1998-07-31 09:45:27 +000038import buildtools
Jack Jansen0f00c5e1997-05-06 16:15:32 +000039import cfmfile
40
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.
44DIALOG_ID = 512
45
46I_OK=1
47I_CANCEL=2
Jack Jansen675cda01997-09-09 13:57:15 +000048I_INC_BUILDNO=19
Jack Jansen0f00c5e1997-05-06 16:15:32 +000049
Jack Jansen82bfde91997-08-27 14:10:29 +000050I_CORE=3
Jack Jansen0f00c5e1997-05-06 16:15:32 +000051I_PPC_PLUGINS=4
52I_PPC_EXTENSIONS=5
Jack Jansen82bfde91997-08-27 14:10:29 +000053I_68K_PLUGINS=6
54I_68K_EXTENSIONS=7
55I_PPC_FULL=8
56I_PPC_SMALL=9
57I_68K_FULL=10
58I_68K_SMALL=11
59I_APPLETS=12
Jack Jansen0f00c5e1997-05-06 16:15:32 +000060
Jack Jansen82bfde91997-08-27 14:10:29 +000061N_BUTTONS=13
Jack Jansen6655c4e1995-09-01 12:03:32 +000062
Jack Jansen87426b92000-08-17 22:12:12 +000063if OLDAESUPPORT:
64 class MwShell(Metrowerks_Shell_Suite, CodeWarrior_suite, Metrowerks_Standard_Suite,
65 Required_Suite, aetools.TalkTo):
66 pass
67else:
68 MwShell = CodeWarrior.CodeWarrior
Jack Jansen6655c4e1995-09-01 12:03:32 +000069
Jack Jansenf04fa721996-04-10 14:51:14 +000070RUNNING=[]
Jack Jansen6655c4e1995-09-01 12:03:32 +000071
72def buildmwproject(top, creator, projects):
73 """Build projects with an MW compiler"""
Jack Jansenb9e5e141996-09-20 15:30:52 +000074 mgr = MwShell(creator, start=1)
Jack Jansen1023dff1996-02-21 15:28:49 +000075 mgr.send_timeout = AppleEvents.kNoTimeOut
76
Jack Jansenbc66f952000-07-24 19:45:07 +000077 failed = []
Jack Jansen6655c4e1995-09-01 12:03:32 +000078 for file in projects:
Jack Jansen82bfde91997-08-27 14:10:29 +000079 if type(file) == type(()):
80 file, target = file
81 else:
82 target = ''
Jack Jansen6655c4e1995-09-01 12:03:32 +000083 file = os.path.join(top, file)
Just van Rossum2607a441999-01-30 18:27:12 +000084 try:
85 fss = macfs.FSSpec(file)
86 except ValueError:
87 print '** file not found:', file
88 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000089 print 'Building', file, target
Just van Rossum2607a441999-01-30 18:27:12 +000090 try:
91 mgr.open(fss)
92 except aetools.Error, detail:
93 print '**', detail, file
94 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000095 if target:
96 try:
97 mgr.Set_Current_Target(target)
98 except aetools.Error, arg:
99 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +0000100 try:
101 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +0000102 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +0000103 print '**', file, target, 'Failed:', arg
Jack Jansenbc66f952000-07-24 19:45:07 +0000104 failed.append(fss)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000105 mgr.Close_Project()
Jack Jansenbc66f952000-07-24 19:45:07 +0000106 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)
Jack Jansenf04fa721996-04-10 14:51:14 +0000113## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000114
115def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000116 """Create python applets"""
Jack Jansen490ec9c1998-07-31 09:45:27 +0000117 template = buildtools.findtemplate()
Just van Rossum9d609b41999-02-01 01:21:18 +0000118 for src, dst in list:
Jack Jansen6655c4e1995-09-01 12:03:32 +0000119 if src[-3:] != '.py':
120 raise 'Should end in .py', src
121 base = os.path.basename(src)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000122 src = os.path.join(top, src)
Just van Rossum9d609b41999-02-01 01:21:18 +0000123 dst = os.path.join(top, dst)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000124 try:
125 os.unlink(dst)
126 except os.error:
127 pass
128 print 'Building applet', dst
Jack Jansen490ec9c1998-07-31 09:45:27 +0000129 buildtools.process(template, src, dst, 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000130
131def 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)
139
Jack Jansen675cda01997-09-09 13:57:15 +0000140def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000141 """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 []
Jack Jansen675cda01997-09-09 13:57:15 +0000152 if n == I_INC_BUILDNO:
153 incbuildno(filename)
154 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000155 if n < len(results):
156 results[n] = (not results[n])
Jack Jansenc9b1e901999-12-24 13:39:23 +0000157 ctl = d.GetDialogItemAsControl(n)
158 ctl.SetControlValue(results[n])
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000159 rv = []
160 for i in range(len(results)):
161 if results[i]:
162 rv.append(i)
163 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000164
165#
166# The build instructions. Entries are (routine, arg, list-of-files)
167# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000168BUILD_DICT = {
Jack Jansen82bfde91997-08-27 14:10:29 +0000169I_CORE : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000170 (":Mac:Build:PythonCore.prj", "PythonCore"),
Jack Jansen3b805261999-02-14 23:12:06 +0000171 (":Mac:Build:PythonInterpreter.prj", "PythonInterpreter"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000172 ]),
173
174I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen89d017d2000-07-07 13:08:09 +0000175 (":Mac:Build:ucnhash.prj", "ucnhash.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000176 (":Mac:Build:calldll.ppc.prj", "calldll.ppc"),
177 (":Mac:Build:ctb.prj", "ctb.ppc"),
178 (":Mac:Build:gdbm.prj", "gdbm.ppc"),
179 (":Mac:Build:icglue.prj", "icglue.ppc"),
180 (":Mac:Build:macspeech.prj", "macspeech.ppc"),
181 (":Mac:Build:waste.prj", "waste.ppc"),
182 (":Mac:Build:zlib.prj", "zlib.ppc"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000183## (":Mac:Build:_tkinter.prj", "_tkinter.ppc"),
184 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000185 (":Mac:Build:ColorPicker.prj", "ColorPicker.ppc"),
186 (":Mac:Build:Printing.prj", "Printing.ppc"),
Jack Jansen57ed1391999-03-04 23:00:11 +0000187 (":Mac:Build:App.prj", "App.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000188 (":Mac:Build:Cm.prj", "Cm.ppc"),
Jack Jansen6c38e5b2000-04-08 21:29:31 +0000189 (":Mac:Build:Drag.prj", "Drag.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000190 (":Mac:Build:Fm.prj", "Fm.ppc"),
191 (":Mac:Build:Help.prj", "Help.ppc"),
192 (":Mac:Build:Icn.prj", "Icn.ppc"),
193 (":Mac:Build:List.prj", "List.ppc"),
Jack Jansen6a51b371999-03-07 23:10:32 +0000194 (":Mac:Build:Qdoffs.prj", "Qdoffs.ppc"),
Jack Jansen87352f81999-02-12 10:29:06 +0000195 (":Mac:Build:Qt.prj", "Qt.ppc"),
196 (":Mac:Build:Scrap.prj", "Scrap.ppc"),
197 (":Mac:Build:Snd.prj", "Snd.ppc"),
198 (":Mac:Build:Sndihooks.prj", "Sndihooks.ppc"),
199 (":Mac:Build:TE.prj", "TE.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000200 ]),
201
202I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen89d017d2000-07-07 13:08:09 +0000203 (":Mac:Build:ucnhash.prj", "ucnhash.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000204 (":Mac:Build:ctb.prj", "ctb.CFM68K"),
205 (":Mac:Build:gdbm.prj", "gdbm.CFM68K"),
206 (":Mac:Build:icglue.prj", "icglue.CFM68K"),
207 (":Mac:Build:waste.prj", "waste.CFM68K"),
208 (":Mac:Build:zlib.prj", "zlib.CFM68K"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000209## (":Mac:Build:_tkinter.prj", "_tkinter.CFM68K"),
210 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000211 (":Mac:Build:ColorPicker.prj", "ColorPicker.CFM68K"),
212 (":Mac:Build:Printing.prj", "Printing.CFM68K"),
Jack Jansen57ed1391999-03-04 23:00:11 +0000213 (":Mac:Build:App.prj", "App.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000214 (":Mac:Build:Cm.prj", "Cm.CFM68K"),
Jack Jansen6c38e5b2000-04-08 21:29:31 +0000215 (":Mac:Build:Drag.prj", "Drag.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000216 (":Mac:Build:Fm.prj", "Fm.CFM68K"),
217 (":Mac:Build:Help.prj", "Help.CFM68K"),
218 (":Mac:Build:Icn.prj", "Icn.CFM68K"),
219 (":Mac:Build:List.prj", "List.CFM68K"),
Jack Jansen6a51b371999-03-07 23:10:32 +0000220 (":Mac:Build:Qdoffs.prj", "Qdoffs.CFM68K"),
Jack Jansen87352f81999-02-12 10:29:06 +0000221 (":Mac:Build:Qt.prj", "Qt.CFM68K"),
222 (":Mac:Build:Scrap.prj", "Scrap.CFM68K"),
223 (":Mac:Build:Snd.prj", "Snd.CFM68K"),
224 (":Mac:Build:Sndihooks.prj", "Sndihooks.CFM68K"),
225 (":Mac:Build:TE.prj", "TE.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000226 ]),
227
228I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000229 (":Mac:Build:PythonStandalone.prj", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000230 ]),
231
232I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000233 (":Mac:Build:PythonStandSmall.prj", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000234 ]),
235
236I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000237 (":Mac:Build:PythonStandalone.prj", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000238 ]),
239
240I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000241 (":Mac:Build:PythonStandSmall.prj", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000242 ]),
243
244I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000245 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000246## (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
Jack Jansen8eea5ba1999-02-06 17:44:28 +0000247 (":Extensions:img:Mac:imgmodules.prj", "imgmodules PPC"),
Just van Rossum7bcd84d1999-02-02 23:58:50 +0000248 (":Extensions:Numerical:Mac:numpymodules.prj", "multiarraymodule"),
249 (":Extensions:Numerical:Mac:numpymodules.prj", "_numpy"),
250 (":Extensions:Numerical:Mac:numpymodules.prj", "umathmodule"),
251 (":Extensions:Numerical:Mac:numpymodules.prj", "fast_umathmodule"),
252 (":Extensions:Numerical:Mac:numpymodules.prj", "fftpackmodule"),
253 (":Extensions:Numerical:Mac:numpymodules.prj", "lapack_litemodule"),
254 (":Extensions:Numerical:Mac:numpymodules.prj", "ranlibmodule"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000255 ]),
256
257I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000258 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
Jack Jansenbfbf1132000-04-23 22:13:15 +0000259## (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
Jack Jansen8eea5ba1999-02-06 17:44:28 +0000260 (":Extensions:img:Mac:imgmodules.prj", "imgmodules CFM68K"),
Just van Rossum7bcd84d1999-02-02 23:58:50 +0000261## (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000262 ]),
263
264I_APPLETS : (buildapplet, None, [
Just van Rossum9d609b41999-02-01 01:21:18 +0000265 (":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"),
Just van Rossumf84fdfe2000-03-28 20:50:36 +0000270 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave"),
271 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000272 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000273}
Jack Jansenfaad9951997-09-01 15:37:07 +0000274
275def incbuildno(filename):
276 fp = open(filename)
277 line = fp.readline()
278 fp.close()
279
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()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000289
290def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000291 try:
Jack Jansend13c3852000-06-20 21:59:25 +0000292 h = Res.FSpOpenResFile('fullbuild.rsrc', 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000293 except Res.Error:
294 pass # Assume we already have acces to our own resource
295
Jack Jansen6655c4e1995-09-01 12:03:32 +0000296 dir, ok = macfs.GetDirectory('Python source folder:')
297 if not ok:
298 sys.exit(0)
299 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000300
Jack Jansen675cda01997-09-09 13:57:15 +0000301 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
302
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000303 instructions = []
304 for i in todo:
305 instructions.append(BUILD_DICT[i])
306
307 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000308 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000309
Jack Jansen6655c4e1995-09-01 12:03:32 +0000310 print "All done!"
311 sys.exit(1)
312
313if __name__ == '__main__':
314 main()
315