blob: 520cf5c0b0772c8ed6d95f16928d13f93f881df8 [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 Jansenbe614ee2001-01-02 22:02:02 +000019import re
Jack Jansenfaad9951997-09-01 15:37:07 +000020import 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 Jansene56e87d2001-01-03 11:12:21 +000048# label 3
49I_PPC_EXTLIBS=4
50I_GEN_PROJECTS=5
Jack Jansen1f5cd702001-01-21 22:25:11 +000051I_GEN_PROJECTS_FORCE=6
52I_GEN_IMGPROJECTS=7
53I_GEN_IMGPROJECTS_FORCE=8
54I_INC_BUILDNO=9
55# label 10
56I_PPC_CORE=11
57I_PPC_PLUGINS=12
58I_PPC_EXTENSIONS=13
59# label 14
60I_CARBON_CORE=15
61I_CARBON_PLUGINS=16
62I_CARBON_EXTENSIONS=17
63# label 18
64I_PPC_FULL=19
65I_PPC_SMALL=20
66# label 21
67I_APPLETS=22
Jack Jansen0f00c5e1997-05-06 16:15:32 +000068
Jack Jansen1f5cd702001-01-21 22:25:11 +000069N_BUTTONS=23
Jack Jansen6655c4e1995-09-01 12:03:32 +000070
Jack Jansen87426b92000-08-17 22:12:12 +000071if OLDAESUPPORT:
72 class MwShell(Metrowerks_Shell_Suite, CodeWarrior_suite, Metrowerks_Standard_Suite,
73 Required_Suite, aetools.TalkTo):
74 pass
75else:
76 MwShell = CodeWarrior.CodeWarrior
Jack Jansen6655c4e1995-09-01 12:03:32 +000077
Jack Jansenf04fa721996-04-10 14:51:14 +000078RUNNING=[]
Jack Jansen6655c4e1995-09-01 12:03:32 +000079
80def buildmwproject(top, creator, projects):
81 """Build projects with an MW compiler"""
Jack Jansenb9e5e141996-09-20 15:30:52 +000082 mgr = MwShell(creator, start=1)
Jack Jansen1023dff1996-02-21 15:28:49 +000083 mgr.send_timeout = AppleEvents.kNoTimeOut
84
Jack Jansenbc66f952000-07-24 19:45:07 +000085 failed = []
Jack Jansen6655c4e1995-09-01 12:03:32 +000086 for file in projects:
Jack Jansen82bfde91997-08-27 14:10:29 +000087 if type(file) == type(()):
88 file, target = file
89 else:
90 target = ''
Jack Jansen6655c4e1995-09-01 12:03:32 +000091 file = os.path.join(top, file)
Just van Rossum2607a441999-01-30 18:27:12 +000092 try:
93 fss = macfs.FSSpec(file)
Jack Jansene56e87d2001-01-03 11:12:21 +000094 except MacOS.Error:
Just van Rossum2607a441999-01-30 18:27:12 +000095 print '** file not found:', file
96 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000097 print 'Building', file, target
Just van Rossum2607a441999-01-30 18:27:12 +000098 try:
99 mgr.open(fss)
100 except aetools.Error, detail:
101 print '**', detail, file
102 continue
Jack Jansen82bfde91997-08-27 14:10:29 +0000103 if target:
104 try:
105 mgr.Set_Current_Target(target)
106 except aetools.Error, arg:
107 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +0000108 try:
109 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +0000110 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +0000111 print '**', file, target, 'Failed:', arg
Jack Jansenbc66f952000-07-24 19:45:07 +0000112 failed.append(fss)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000113 mgr.Close_Project()
Jack Jansenbc66f952000-07-24 19:45:07 +0000114 if failed:
115 print 'Open failed projects and exit?',
116 rv = sys.stdin.readline()
117 if rv[0] in ('y', 'Y'):
118 for fss in failed:
119 mgr.open(fss)
120 sys.exit(0)
Jack Jansenf04fa721996-04-10 14:51:14 +0000121## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000122
123def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000124 """Create python applets"""
Jack Jansen490ec9c1998-07-31 09:45:27 +0000125 template = buildtools.findtemplate()
Just van Rossum9d609b41999-02-01 01:21:18 +0000126 for src, dst in list:
Jack Jansen6655c4e1995-09-01 12:03:32 +0000127 if src[-3:] != '.py':
128 raise 'Should end in .py', src
129 base = os.path.basename(src)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000130 src = os.path.join(top, src)
Just van Rossum9d609b41999-02-01 01:21:18 +0000131 dst = os.path.join(top, dst)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000132 try:
133 os.unlink(dst)
134 except os.error:
135 pass
136 print 'Building applet', dst
Jack Jansen490ec9c1998-07-31 09:45:27 +0000137 buildtools.process(template, src, dst, 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000138
Jack Jansen1f5cd702001-01-21 22:25:11 +0000139def buildprojectfile(top, arg, list):
Jack Jansene56e87d2001-01-03 11:12:21 +0000140 """Create CodeWarrior project files with a script"""
141 for folder, module, routine in list:
142 print "Generating project files with", module
143 sys.path.insert(0, os.path.join(top, folder))
144 m = __import__(module)
145 r = getattr(m, routine)
Jack Jansen1f5cd702001-01-21 22:25:11 +0000146 r(arg)
Jack Jansene56e87d2001-01-03 11:12:21 +0000147 del sys.path[0]
148
Jack Jansen1f5cd702001-01-21 22:25:11 +0000149def buildcarbonnotyet(top, arg, list):
150 print "No carbon builds yet"
151
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000152def buildfat(top, dummy, list):
153 """Build fat binaries"""
154 for dst, src1, src2 in list:
155 dst = os.path.join(top, dst)
156 src1 = os.path.join(top, src1)
157 src2 = os.path.join(top, src2)
158 print 'Building fat binary', dst
159 cfmfile.mergecfmfiles((src1, src2), dst)
160
Jack Jansen675cda01997-09-09 13:57:15 +0000161def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000162 """Handle selection dialog, return list of selected items"""
163 d = Dlg.GetNewDialog(DIALOG_ID, -1)
164 d.SetDialogDefaultItem(I_OK)
165 d.SetDialogCancelItem(I_CANCEL)
166 results = [0]*N_BUTTONS
167 while 1:
168 n = Dlg.ModalDialog(None)
169 if n == I_OK:
170 break
171 if n == I_CANCEL:
172 return []
Jack Jansen675cda01997-09-09 13:57:15 +0000173 if n == I_INC_BUILDNO:
174 incbuildno(filename)
175 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000176 if n < len(results):
177 results[n] = (not results[n])
Jack Jansenc9b1e901999-12-24 13:39:23 +0000178 ctl = d.GetDialogItemAsControl(n)
179 ctl.SetControlValue(results[n])
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000180 rv = []
181 for i in range(len(results)):
182 if results[i]:
183 rv.append(i)
184 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000185
186#
187# The build instructions. Entries are (routine, arg, list-of-files)
188# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000189BUILD_DICT = {
Jack Jansen1f5cd702001-01-21 22:25:11 +0000190I_GEN_PROJECTS : (buildprojectfile, 0, [
Jack Jansene56e87d2001-01-03 11:12:21 +0000191 (":Mac:scripts", "genpluginprojects", "genallprojects")
192 ]),
193
Jack Jansen1f5cd702001-01-21 22:25:11 +0000194I_GEN_PROJECTS_FORCE : (buildprojectfile, 1, [
195 (":Mac:scripts", "genpluginprojects", "genallprojects")
196 ]),
197
198I_GEN_IMGPROJECTS : (buildprojectfile, 0, [
Jack Jansene56e87d2001-01-03 11:12:21 +0000199 (":Extensions:img:Mac", "genimgprojects", "genallprojects")
200 ]),
201
Jack Jansen1f5cd702001-01-21 22:25:11 +0000202I_GEN_IMGPROJECTS_FORCE : (buildprojectfile, 1, [
203 (":Extensions:img:Mac", "genimgprojects", "genallprojects")
204 ]),
205
206I_PPC_CORE : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000207 (":Mac:Build:PythonCore.mcp", "PythonCore"),
208 (":Mac:Build:PythonInterpreter.mcp", "PythonInterpreter"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000209 ]),
210
Jack Jansen1f5cd702001-01-21 22:25:11 +0000211I_CARBON_CORE : (buildmwproject, "CWIE", [
212 (":Mac:Build:PythonCore.mcp", "PythonCoreCarbon"),
213 (":Mac:Build:PythonInterpreter.mcp", "PythonInterpreterCarbon"),
214 ]),
215
Jack Jansene56e87d2001-01-03 11:12:21 +0000216I_PPC_EXTLIBS : (buildmwproject, "CWIE", [
217## (":Mac:Build:buildlibs.mcp", "buildlibs ppc plus tcl/tk"),
218 (":Mac:Build:buildlibs.mcp", "buildlibs ppc"),
219 ]),
220
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000221I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000222 (":Mac:Build:ucnhash.mcp", "ucnhash.ppc"),
223 (":Mac:Build:pyexpat.mcp", "pyexpat.ppc"),
224 (":Mac:Build:calldll.mcp", "calldll.ppc"),
225 (":Mac:Build:ctb.mcp", "ctb.ppc"),
226 (":Mac:Build:gdbm.mcp", "gdbm.ppc"),
227 (":Mac:Build:icglue.mcp", "icglue.ppc"),
228 (":Mac:Build:macspeech.mcp", "macspeech.ppc"),
229 (":Mac:Build:waste.mcp", "waste.ppc"),
230 (":Mac:Build:zlib.mcp", "zlib.ppc"),
231## (":Mac:Build:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansen07d69f62001-01-01 21:51:33 +0000232 (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000233 (":Mac:Build:ColorPicker.mcp", "ColorPicker.ppc"),
234 (":Mac:Build:Printing.mcp", "Printing.ppc"),
235 (":Mac:Build:App.mcp", "App.ppc"),
236 (":Mac:Build:Cm.mcp", "Cm.ppc"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000237 (":Mac:Build:Fm.mcp", "Fm.ppc"),
238 (":Mac:Build:Help.mcp", "Help.ppc"),
239 (":Mac:Build:Icn.mcp", "Icn.ppc"),
240 (":Mac:Build:List.mcp", "List.ppc"),
241 (":Mac:Build:Qdoffs.mcp", "Qdoffs.ppc"),
242 (":Mac:Build:Qt.mcp", "Qt.ppc"),
243 (":Mac:Build:Scrap.mcp", "Scrap.ppc"),
244 (":Mac:Build:Snd.mcp", "Snd.ppc"),
245 (":Mac:Build:Sndihooks.mcp", "Sndihooks.ppc"),
246 (":Mac:Build:TE.mcp", "TE.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000247 ]),
248
Jack Jansenc3fc51f2001-01-23 22:36:52 +0000249I_CARBON_PLUGINS : (buildmwproject, "CWIE", [
250 (":Mac:Build:ucnhash.carbon.mcp", "ucnhash.carbon"),
251 (":Mac:Build:pyexpat.carbon.mcp", "pyexpat.carbon"),
252 (":Mac:Build:calldll.carbon.mcp", "calldll.carbon"),
253 (":Mac:Build:gdbm.carbon.mcp", "gdbm.carbon"),
254## (":Mac:Build:icglue.carbon.mcp", "icglue.carbon"),
255## (":Mac:Build:waste.carbon.mcp", "waste.carbon"),
256 (":Mac:Build:zlib.carbon.mcp", "zlib.carbon"),
Jack Jansen7b7e7132001-01-23 23:19:41 +0000257## (":Mac:Build:_tkinter.mcp", "_tkinter.carbon"),
Jack Jansenc3fc51f2001-01-23 22:36:52 +0000258## (":Extensions:Imaging:_tkinter.carbon.mcp", "_tkinter.carbon"),
259 (":Mac:Build:ColorPicker.carbon.mcp", "ColorPicker.carbon"),
260 (":Mac:Build:App.carbon.mcp", "App.carbon"),
261 (":Mac:Build:Cm.carbon.mcp", "Cm.carbon"),
262 (":Mac:Build:Fm.carbon.mcp", "Fm.carbon"),
263 (":Mac:Build:Icn.carbon.mcp", "Icn.carbon"),
264 (":Mac:Build:List.carbon.mcp", "List.carbon"),
265 (":Mac:Build:Qdoffs.carbon.mcp", "Qdoffs.carbon"),
266 (":Mac:Build:Qt.carbon.mcp", "Qt.carbon"),
267## (":Mac:Build:Scrap.carbon.mcp", "Scrap.carbon"),
268 (":Mac:Build:Snd.carbon.mcp", "Snd.carbon"),
269 (":Mac:Build:Sndihooks.carbon.mcp", "Sndihooks.carbon"),
270 (":Mac:Build:TE.carbon.mcp", "TE.carbon"),
271 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000272
273I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000274 (":Mac:Build:PythonStandSmall.mcp", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000275 ]),
276
277I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000278 (":Extensions:Imaging:_imaging.mcp", "_imaging.ppc"),
279## (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansen7b7e7132001-01-23 23:19:41 +0000280 (":Extensions:img:Mac:imgmodules.mcp", "imgmodules.ppc"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000281## (":Extensions:Numerical:Mac:numpymodules.mcp", "multiarraymodule"),
282## (":Extensions:Numerical:Mac:numpymodules.mcp", "_numpy"),
283## (":Extensions:Numerical:Mac:numpymodules.mcp", "umathmodule"),
284## (":Extensions:Numerical:Mac:numpymodules.mcp", "arrayfns"),
285## (":Extensions:Numerical:Packages:FFT:Mac:fftpack.mcp", "fftpack.ppc"),
286## (":Extensions:Numerical:Packages:LALITE:Mac:lapack_lite.mcp", "lapack_lite.ppc"),
287## (":Extensions:Numerical:Packages:RANLIB:Mac:ranlib.mcp", "ranlib.ppc"),
288## (":Extensions:Numerical:Packages:RNG:Mac:RNG.mcp", "RNG.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000289 ]),
290
Jack Jansen7b7e7132001-01-23 23:19:41 +0000291I_CARBON_EXTENSIONS : (buildmwproject, "CWIE", [
292## (":Extensions:Imaging:_imaging.mcp", "_imaging.carbon"),
293## (":Extensions:Imaging:_tkinter.mcp", "_tkinter.carbon"),
294 (":Extensions:img:Mac:imgmodules.mcp", "imgmodules.carbon"),
295## (":Extensions:Numerical:Mac:numpymodules.mcp", "multiarraymodule"),
296## (":Extensions:Numerical:Mac:numpymodules.mcp", "_numpy"),
297## (":Extensions:Numerical:Mac:numpymodules.mcp", "umathmodule"),
298## (":Extensions:Numerical:Mac:numpymodules.mcp", "arrayfns"),
299## (":Extensions:Numerical:Packages:FFT:Mac:fftpack.mcp", "fftpack.ppc"),
300## (":Extensions:Numerical:Packages:LALITE:Mac:lapack_lite.mcp", "lapack_lite.ppc"),
301## (":Extensions:Numerical:Packages:RANLIB:Mac:ranlib.mcp", "ranlib.ppc"),
302## (":Extensions:Numerical:Packages:RNG:Mac:RNG.mcp", "RNG.ppc"),
303 ]),
304
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000305I_APPLETS : (buildapplet, None, [
Just van Rossum9d609b41999-02-01 01:21:18 +0000306 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs"),
307 (":Mac:scripts:BuildApplet.py", "BuildApplet"),
308 (":Mac:scripts:BuildApplication.py", "BuildApplication"),
309 (":Mac:scripts:ConfigurePython.py", "ConfigurePython"),
310 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE"),
Just van Rossumf84fdfe2000-03-28 20:50:36 +0000311 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave"),
312 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000313 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000314}
Jack Jansenfaad9951997-09-01 15:37:07 +0000315
316def incbuildno(filename):
317 fp = open(filename)
318 line = fp.readline()
319 fp.close()
320
Jack Jansenbe614ee2001-01-02 22:02:02 +0000321 pat = re.compile('#define BUILD ([0-9]+)')
322 m = pat.search(line)
323 if not m or not m.group(1):
Jack Jansenfaad9951997-09-01 15:37:07 +0000324 raise 'Incorrect macbuildno.h line', line
Jack Jansenbe614ee2001-01-02 22:02:02 +0000325 buildno = m.group(1)
Jack Jansenfaad9951997-09-01 15:37:07 +0000326 new = string.atoi(buildno) + 1
327 fp = open(filename, 'w')
328 fp.write('#define BUILD %d\n'%new)
329 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000330
331def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000332 try:
Jack Jansend13c3852000-06-20 21:59:25 +0000333 h = Res.FSpOpenResFile('fullbuild.rsrc', 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000334 except Res.Error:
335 pass # Assume we already have acces to our own resource
336
Jack Jansen6655c4e1995-09-01 12:03:32 +0000337 dir, ok = macfs.GetDirectory('Python source folder:')
338 if not ok:
339 sys.exit(0)
340 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000341
Jack Jansen675cda01997-09-09 13:57:15 +0000342 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
343
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000344 instructions = []
345 for i in todo:
346 instructions.append(BUILD_DICT[i])
347
348 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000349 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000350
Jack Jansene56e87d2001-01-03 11:12:21 +0000351 if todo:
352 print "All done!"
Jack Jansen6655c4e1995-09-01 12:03:32 +0000353
354if __name__ == '__main__':
355 main()
356