blob: 73ccc8f27b20a505730a4d88726e4d765bd541f4 [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 Jansena5d384d2000-12-03 22:36:42 +0000170 (":Mac:Build:PythonCore.mcp", "PythonCore"),
171 (":Mac:Build:PythonInterpreter.mcp", "PythonInterpreter"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000172 ]),
173
174I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000175 (":Mac:Build:ucnhash.mcp", "ucnhash.ppc"),
176 (":Mac:Build:pyexpat.mcp", "pyexpat.ppc"),
177 (":Mac:Build:calldll.mcp", "calldll.ppc"),
178 (":Mac:Build:ctb.mcp", "ctb.ppc"),
179 (":Mac:Build:gdbm.mcp", "gdbm.ppc"),
180 (":Mac:Build:icglue.mcp", "icglue.ppc"),
181 (":Mac:Build:macspeech.mcp", "macspeech.ppc"),
182 (":Mac:Build:waste.mcp", "waste.ppc"),
183 (":Mac:Build:zlib.mcp", "zlib.ppc"),
184## (":Mac:Build:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansen07d69f62001-01-01 21:51:33 +0000185 (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000186 (":Mac:Build:ColorPicker.mcp", "ColorPicker.ppc"),
187 (":Mac:Build:Printing.mcp", "Printing.ppc"),
188 (":Mac:Build:App.mcp", "App.ppc"),
189 (":Mac:Build:Cm.mcp", "Cm.ppc"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000190 (":Mac:Build:Fm.mcp", "Fm.ppc"),
191 (":Mac:Build:Help.mcp", "Help.ppc"),
192 (":Mac:Build:Icn.mcp", "Icn.ppc"),
193 (":Mac:Build:List.mcp", "List.ppc"),
194 (":Mac:Build:Qdoffs.mcp", "Qdoffs.ppc"),
195 (":Mac:Build:Qt.mcp", "Qt.ppc"),
196 (":Mac:Build:Scrap.mcp", "Scrap.ppc"),
197 (":Mac:Build:Snd.mcp", "Snd.ppc"),
198 (":Mac:Build:Sndihooks.mcp", "Sndihooks.ppc"),
199 (":Mac:Build:TE.mcp", "TE.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000200 ]),
201
202I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000203 (":Mac:Build:ucnhash.mcp", "ucnhash.CFM68K"),
204 (":Mac:Build:ucnhash.mcp", "ucnhash.CFM68K"),
205 (":Mac:Build:ctb.mcp", "ctb.CFM68K"),
206 (":Mac:Build:gdbm.mcp", "gdbm.CFM68K"),
207 (":Mac:Build:icglue.mcp", "icglue.CFM68K"),
208 (":Mac:Build:waste.mcp", "waste.CFM68K"),
209 (":Mac:Build:zlib.mcp", "zlib.CFM68K"),
210## (":Mac:Build:_tkinter.mcp", "_tkinter.CFM68K"),
211 (":Extensions:Imaging:_tkinter.mcp", "_tkinter.CFM68K"),
212 (":Mac:Build:ColorPicker.mcp", "ColorPicker.CFM68K"),
213 (":Mac:Build:Printing.mcp", "Printing.CFM68K"),
214 (":Mac:Build:App.mcp", "App.CFM68K"),
215 (":Mac:Build:Cm.mcp", "Cm.CFM68K"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000216 (":Mac:Build:Fm.mcp", "Fm.CFM68K"),
217 (":Mac:Build:Help.mcp", "Help.CFM68K"),
218 (":Mac:Build:Icn.mcp", "Icn.CFM68K"),
219 (":Mac:Build:List.mcp", "List.CFM68K"),
220 (":Mac:Build:Qdoffs.mcp", "Qdoffs.CFM68K"),
221 (":Mac:Build:Qt.mcp", "Qt.CFM68K"),
222 (":Mac:Build:Scrap.mcp", "Scrap.CFM68K"),
223 (":Mac:Build:Snd.mcp", "Snd.CFM68K"),
224 (":Mac:Build:Sndihooks.mcp", "Sndihooks.CFM68K"),
225 (":Mac:Build:TE.mcp", "TE.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000226 ]),
227
228I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000229 (":Mac:Build:PythonStandalone.mcp", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000230 ]),
231
232I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000233 (":Mac:Build:PythonStandSmall.mcp", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000234 ]),
235
236I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000237 (":Mac:Build:PythonStandalone.mcp", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000238 ]),
239
240I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000241 (":Mac:Build:PythonStandSmall.mcp", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000242 ]),
243
244I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000245 (":Extensions:Imaging:_imaging.mcp", "_imaging.ppc"),
246## (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansen07d69f62001-01-01 21:51:33 +0000247 (":Extensions:img:Mac:imgmodules.mcp", "imgmodules"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000248## (":Extensions:Numerical:Mac:numpymodules.mcp", "multiarraymodule"),
249## (":Extensions:Numerical:Mac:numpymodules.mcp", "_numpy"),
250## (":Extensions:Numerical:Mac:numpymodules.mcp", "umathmodule"),
251## (":Extensions:Numerical:Mac:numpymodules.mcp", "arrayfns"),
252## (":Extensions:Numerical:Packages:FFT:Mac:fftpack.mcp", "fftpack.ppc"),
253## (":Extensions:Numerical:Packages:LALITE:Mac:lapack_lite.mcp", "lapack_lite.ppc"),
254## (":Extensions:Numerical:Packages:RANLIB:Mac:ranlib.mcp", "ranlib.ppc"),
255## (":Extensions:Numerical:Packages:RNG:Mac:RNG.mcp", "RNG.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000256 ]),
257
258I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000259 (":Extensions:Imaging:_imaging.mcp", "_imaging.CFM68K"),
260## (":Extensions:Imaging:_tkinter.mcp", "_tkinter.CFM68K"),
261 (":Extensions:img:Mac:imgmodules.mcp", "imgmodules CFM68K"),
262## (":Extensions:NumPy:numpymodules.mcp", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000263 ]),
264
265I_APPLETS : (buildapplet, None, [
Just van Rossum9d609b41999-02-01 01:21:18 +0000266 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs"),
267 (":Mac:scripts:BuildApplet.py", "BuildApplet"),
268 (":Mac:scripts:BuildApplication.py", "BuildApplication"),
269 (":Mac:scripts:ConfigurePython.py", "ConfigurePython"),
270 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE"),
Just van Rossumf84fdfe2000-03-28 20:50:36 +0000271 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave"),
272 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000273 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000274}
Jack Jansenfaad9951997-09-01 15:37:07 +0000275
276def incbuildno(filename):
277 fp = open(filename)
278 line = fp.readline()
279 fp.close()
280
281 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
282 pat.match(line)
283 buildno = pat.group(1)
284 if not buildno:
285 raise 'Incorrect macbuildno.h line', line
286 new = string.atoi(buildno) + 1
287 fp = open(filename, 'w')
288 fp.write('#define BUILD %d\n'%new)
289 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000290
291def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000292 try:
Jack Jansend13c3852000-06-20 21:59:25 +0000293 h = Res.FSpOpenResFile('fullbuild.rsrc', 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000294 except Res.Error:
295 pass # Assume we already have acces to our own resource
296
Jack Jansen6655c4e1995-09-01 12:03:32 +0000297 dir, ok = macfs.GetDirectory('Python source folder:')
298 if not ok:
299 sys.exit(0)
300 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000301
Jack Jansen675cda01997-09-09 13:57:15 +0000302 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
303
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000304 instructions = []
305 for i in todo:
306 instructions.append(BUILD_DICT[i])
307
308 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000309 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000310
Jack Jansen6655c4e1995-09-01 12:03:32 +0000311 print "All done!"
Jack Jansen6655c4e1995-09-01 12:03:32 +0000312
313if __name__ == '__main__':
314 main()
315