blob: 4747e38bdbc67c6fd783f5f42d36abf957c7326a [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
51I_GEN_IMGPROJECTS=6
52I_INC_BUILDNO=7
53# label 8
54I_CORE=9
55I_PPC_PLUGINS=10
56I_PPC_EXTENSIONS=11
57# label 12
58I_PPC_FULL=13
59I_PPC_SMALL=14
60# label 15
61I_APPLETS=16
Jack Jansen0f00c5e1997-05-06 16:15:32 +000062
Jack Jansene56e87d2001-01-03 11:12:21 +000063N_BUTTONS=17
Jack Jansen6655c4e1995-09-01 12:03:32 +000064
Jack Jansen87426b92000-08-17 22:12:12 +000065if OLDAESUPPORT:
66 class MwShell(Metrowerks_Shell_Suite, CodeWarrior_suite, Metrowerks_Standard_Suite,
67 Required_Suite, aetools.TalkTo):
68 pass
69else:
70 MwShell = CodeWarrior.CodeWarrior
Jack Jansen6655c4e1995-09-01 12:03:32 +000071
Jack Jansenf04fa721996-04-10 14:51:14 +000072RUNNING=[]
Jack Jansen6655c4e1995-09-01 12:03:32 +000073
74def buildmwproject(top, creator, projects):
75 """Build projects with an MW compiler"""
Jack Jansenb9e5e141996-09-20 15:30:52 +000076 mgr = MwShell(creator, start=1)
Jack Jansen1023dff1996-02-21 15:28:49 +000077 mgr.send_timeout = AppleEvents.kNoTimeOut
78
Jack Jansenbc66f952000-07-24 19:45:07 +000079 failed = []
Jack Jansen6655c4e1995-09-01 12:03:32 +000080 for file in projects:
Jack Jansen82bfde91997-08-27 14:10:29 +000081 if type(file) == type(()):
82 file, target = file
83 else:
84 target = ''
Jack Jansen6655c4e1995-09-01 12:03:32 +000085 file = os.path.join(top, file)
Just van Rossum2607a441999-01-30 18:27:12 +000086 try:
87 fss = macfs.FSSpec(file)
Jack Jansene56e87d2001-01-03 11:12:21 +000088 except MacOS.Error:
Just van Rossum2607a441999-01-30 18:27:12 +000089 print '** file not found:', file
90 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000091 print 'Building', file, target
Just van Rossum2607a441999-01-30 18:27:12 +000092 try:
93 mgr.open(fss)
94 except aetools.Error, detail:
95 print '**', detail, file
96 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000097 if target:
98 try:
99 mgr.Set_Current_Target(target)
100 except aetools.Error, arg:
101 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +0000102 try:
103 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +0000104 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +0000105 print '**', file, target, 'Failed:', arg
Jack Jansenbc66f952000-07-24 19:45:07 +0000106 failed.append(fss)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000107 mgr.Close_Project()
Jack Jansenbc66f952000-07-24 19:45:07 +0000108 if failed:
109 print 'Open failed projects and exit?',
110 rv = sys.stdin.readline()
111 if rv[0] in ('y', 'Y'):
112 for fss in failed:
113 mgr.open(fss)
114 sys.exit(0)
Jack Jansenf04fa721996-04-10 14:51:14 +0000115## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000116
117def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000118 """Create python applets"""
Jack Jansen490ec9c1998-07-31 09:45:27 +0000119 template = buildtools.findtemplate()
Just van Rossum9d609b41999-02-01 01:21:18 +0000120 for src, dst in list:
Jack Jansen6655c4e1995-09-01 12:03:32 +0000121 if src[-3:] != '.py':
122 raise 'Should end in .py', src
123 base = os.path.basename(src)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000124 src = os.path.join(top, src)
Just van Rossum9d609b41999-02-01 01:21:18 +0000125 dst = os.path.join(top, dst)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000126 try:
127 os.unlink(dst)
128 except os.error:
129 pass
130 print 'Building applet', dst
Jack Jansen490ec9c1998-07-31 09:45:27 +0000131 buildtools.process(template, src, dst, 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000132
Jack Jansene56e87d2001-01-03 11:12:21 +0000133def buildprojectfile(top, dummy, list):
134 """Create CodeWarrior project files with a script"""
135 for folder, module, routine in list:
136 print "Generating project files with", module
137 sys.path.insert(0, os.path.join(top, folder))
138 m = __import__(module)
139 r = getattr(m, routine)
140 r()
141 del sys.path[0]
142
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000143def buildfat(top, dummy, list):
144 """Build fat binaries"""
145 for dst, src1, src2 in list:
146 dst = os.path.join(top, dst)
147 src1 = os.path.join(top, src1)
148 src2 = os.path.join(top, src2)
149 print 'Building fat binary', dst
150 cfmfile.mergecfmfiles((src1, src2), dst)
151
Jack Jansen675cda01997-09-09 13:57:15 +0000152def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000153 """Handle selection dialog, return list of selected items"""
154 d = Dlg.GetNewDialog(DIALOG_ID, -1)
155 d.SetDialogDefaultItem(I_OK)
156 d.SetDialogCancelItem(I_CANCEL)
157 results = [0]*N_BUTTONS
158 while 1:
159 n = Dlg.ModalDialog(None)
160 if n == I_OK:
161 break
162 if n == I_CANCEL:
163 return []
Jack Jansen675cda01997-09-09 13:57:15 +0000164 if n == I_INC_BUILDNO:
165 incbuildno(filename)
166 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000167 if n < len(results):
168 results[n] = (not results[n])
Jack Jansenc9b1e901999-12-24 13:39:23 +0000169 ctl = d.GetDialogItemAsControl(n)
170 ctl.SetControlValue(results[n])
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000171 rv = []
172 for i in range(len(results)):
173 if results[i]:
174 rv.append(i)
175 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000176
177#
178# The build instructions. Entries are (routine, arg, list-of-files)
179# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000180BUILD_DICT = {
Jack Jansene56e87d2001-01-03 11:12:21 +0000181I_GEN_PROJECTS : (buildprojectfile, None, [
182 (":Mac:scripts", "genpluginprojects", "genallprojects")
183 ]),
184
185I_GEN_IMGPROJECTS : (buildprojectfile, None, [
186 (":Extensions:img:Mac", "genimgprojects", "genallprojects")
187 ]),
188
Jack Jansen82bfde91997-08-27 14:10:29 +0000189I_CORE : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000190 (":Mac:Build:PythonCore.mcp", "PythonCore"),
191 (":Mac:Build:PythonInterpreter.mcp", "PythonInterpreter"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000192 ]),
193
Jack Jansene56e87d2001-01-03 11:12:21 +0000194I_PPC_EXTLIBS : (buildmwproject, "CWIE", [
195## (":Mac:Build:buildlibs.mcp", "buildlibs ppc plus tcl/tk"),
196 (":Mac:Build:buildlibs.mcp", "buildlibs ppc"),
197 ]),
198
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000199I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000200 (":Mac:Build:ucnhash.mcp", "ucnhash.ppc"),
201 (":Mac:Build:pyexpat.mcp", "pyexpat.ppc"),
202 (":Mac:Build:calldll.mcp", "calldll.ppc"),
203 (":Mac:Build:ctb.mcp", "ctb.ppc"),
204 (":Mac:Build:gdbm.mcp", "gdbm.ppc"),
205 (":Mac:Build:icglue.mcp", "icglue.ppc"),
206 (":Mac:Build:macspeech.mcp", "macspeech.ppc"),
207 (":Mac:Build:waste.mcp", "waste.ppc"),
208 (":Mac:Build:zlib.mcp", "zlib.ppc"),
209## (":Mac:Build:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansen07d69f62001-01-01 21:51:33 +0000210 (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000211 (":Mac:Build:ColorPicker.mcp", "ColorPicker.ppc"),
212 (":Mac:Build:Printing.mcp", "Printing.ppc"),
213 (":Mac:Build:App.mcp", "App.ppc"),
214 (":Mac:Build:Cm.mcp", "Cm.ppc"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000215 (":Mac:Build:Fm.mcp", "Fm.ppc"),
216 (":Mac:Build:Help.mcp", "Help.ppc"),
217 (":Mac:Build:Icn.mcp", "Icn.ppc"),
218 (":Mac:Build:List.mcp", "List.ppc"),
219 (":Mac:Build:Qdoffs.mcp", "Qdoffs.ppc"),
220 (":Mac:Build:Qt.mcp", "Qt.ppc"),
221 (":Mac:Build:Scrap.mcp", "Scrap.ppc"),
222 (":Mac:Build:Snd.mcp", "Snd.ppc"),
223 (":Mac:Build:Sndihooks.mcp", "Sndihooks.ppc"),
224 (":Mac:Build:TE.mcp", "TE.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000225 ]),
226
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000227
228I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000229 (":Mac:Build:PythonStandSmall.mcp", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000230 ]),
231
232I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansena5d384d2000-12-03 22:36:42 +0000233 (":Extensions:Imaging:_imaging.mcp", "_imaging.ppc"),
234## (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
Jack Jansen07d69f62001-01-01 21:51:33 +0000235 (":Extensions:img:Mac:imgmodules.mcp", "imgmodules"),
Jack Jansena5d384d2000-12-03 22:36:42 +0000236## (":Extensions:Numerical:Mac:numpymodules.mcp", "multiarraymodule"),
237## (":Extensions:Numerical:Mac:numpymodules.mcp", "_numpy"),
238## (":Extensions:Numerical:Mac:numpymodules.mcp", "umathmodule"),
239## (":Extensions:Numerical:Mac:numpymodules.mcp", "arrayfns"),
240## (":Extensions:Numerical:Packages:FFT:Mac:fftpack.mcp", "fftpack.ppc"),
241## (":Extensions:Numerical:Packages:LALITE:Mac:lapack_lite.mcp", "lapack_lite.ppc"),
242## (":Extensions:Numerical:Packages:RANLIB:Mac:ranlib.mcp", "ranlib.ppc"),
243## (":Extensions:Numerical:Packages:RNG:Mac:RNG.mcp", "RNG.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000244 ]),
245
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000246I_APPLETS : (buildapplet, None, [
Just van Rossum9d609b41999-02-01 01:21:18 +0000247 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs"),
248 (":Mac:scripts:BuildApplet.py", "BuildApplet"),
249 (":Mac:scripts:BuildApplication.py", "BuildApplication"),
250 (":Mac:scripts:ConfigurePython.py", "ConfigurePython"),
251 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE"),
Just van Rossumf84fdfe2000-03-28 20:50:36 +0000252 (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave"),
253 (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000254 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000255}
Jack Jansenfaad9951997-09-01 15:37:07 +0000256
257def incbuildno(filename):
258 fp = open(filename)
259 line = fp.readline()
260 fp.close()
261
Jack Jansenbe614ee2001-01-02 22:02:02 +0000262 pat = re.compile('#define BUILD ([0-9]+)')
263 m = pat.search(line)
264 if not m or not m.group(1):
Jack Jansenfaad9951997-09-01 15:37:07 +0000265 raise 'Incorrect macbuildno.h line', line
Jack Jansenbe614ee2001-01-02 22:02:02 +0000266 buildno = m.group(1)
Jack Jansenfaad9951997-09-01 15:37:07 +0000267 new = string.atoi(buildno) + 1
268 fp = open(filename, 'w')
269 fp.write('#define BUILD %d\n'%new)
270 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000271
272def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000273 try:
Jack Jansend13c3852000-06-20 21:59:25 +0000274 h = Res.FSpOpenResFile('fullbuild.rsrc', 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000275 except Res.Error:
276 pass # Assume we already have acces to our own resource
277
Jack Jansen6655c4e1995-09-01 12:03:32 +0000278 dir, ok = macfs.GetDirectory('Python source folder:')
279 if not ok:
280 sys.exit(0)
281 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000282
Jack Jansen675cda01997-09-09 13:57:15 +0000283 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
284
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000285 instructions = []
286 for i in todo:
287 instructions.append(BUILD_DICT[i])
288
289 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000290 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000291
Jack Jansene56e87d2001-01-03 11:12:21 +0000292 if todo:
293 print "All done!"
Jack Jansen6655c4e1995-09-01 12:03:32 +0000294
295if __name__ == '__main__':
296 main()
297