blob: c4d95e47e3a246b8fa11b901eac5c64580f94ffc [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 Jansen82bfde91997-08-27 14:10:29 +000031import BuildApplet
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 Jansen6655c4e1995-09-01 12:03:32 +000067 for file in projects:
Jack Jansen82bfde91997-08-27 14:10:29 +000068 if type(file) == type(()):
69 file, target = file
70 else:
71 target = ''
Jack Jansen6655c4e1995-09-01 12:03:32 +000072 file = os.path.join(top, file)
73 fss = macfs.FSSpec(file)
Jack Jansen82bfde91997-08-27 14:10:29 +000074 print 'Building', file, target
Jack Jansen6655c4e1995-09-01 12:03:32 +000075 mgr.open(fss)
Jack Jansen82bfde91997-08-27 14:10:29 +000076 if target:
77 try:
78 mgr.Set_Current_Target(target)
79 except aetools.Error, arg:
80 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +000081 try:
82 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +000083 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +000084 print '**', file, target, 'Failed:', arg
Jack Jansen6655c4e1995-09-01 12:03:32 +000085 mgr.Close_Project()
Jack Jansenf04fa721996-04-10 14:51:14 +000086## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +000087
88def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +000089 """Create python applets"""
Jack Jansen82bfde91997-08-27 14:10:29 +000090 template = BuildApplet.findtemplate()
Jack Jansen6655c4e1995-09-01 12:03:32 +000091 for src in list:
92 if src[-3:] != '.py':
93 raise 'Should end in .py', src
94 base = os.path.basename(src)
95 dst = os.path.join(top, base)[:-3]
96 src = os.path.join(top, src)
97 try:
98 os.unlink(dst)
99 except os.error:
100 pass
101 print 'Building applet', dst
Jack Jansen82bfde91997-08-27 14:10:29 +0000102 BuildApplet.process(template, src, dst)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000103
104def buildfat(top, dummy, list):
105 """Build fat binaries"""
106 for dst, src1, src2 in list:
107 dst = os.path.join(top, dst)
108 src1 = os.path.join(top, src1)
109 src2 = os.path.join(top, src2)
110 print 'Building fat binary', dst
111 cfmfile.mergecfmfiles((src1, src2), dst)
112
Jack Jansen675cda01997-09-09 13:57:15 +0000113def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000114 """Handle selection dialog, return list of selected items"""
115 d = Dlg.GetNewDialog(DIALOG_ID, -1)
116 d.SetDialogDefaultItem(I_OK)
117 d.SetDialogCancelItem(I_CANCEL)
118 results = [0]*N_BUTTONS
119 while 1:
120 n = Dlg.ModalDialog(None)
121 if n == I_OK:
122 break
123 if n == I_CANCEL:
124 return []
Jack Jansen675cda01997-09-09 13:57:15 +0000125 if n == I_INC_BUILDNO:
126 incbuildno(filename)
127 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000128 if n < len(results):
129 results[n] = (not results[n])
130 tp, h, rect = d.GetDialogItem(n)
131 h.as_Control().SetControlValue(results[n])
132 rv = []
133 for i in range(len(results)):
134 if results[i]:
135 rv.append(i)
136 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000137
138#
139# The build instructions. Entries are (routine, arg, list-of-files)
140# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000141BUILD_DICT = {
Jack Jansen82bfde91997-08-27 14:10:29 +0000142I_CORE : (buildmwproject, "CWIE", [
143 (":build.mac:PythonCore.prj", "PythonCore"),
144 (":build.mac:Python.prj", "PythonFAT"),
145 (":build.mac:PythonApplet.prj", "PythonAppletFAT"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000146 ]),
147
148I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000149 (":PlugIns:PlugIns.prj", "PlugIns.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000150 ]),
151
152I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000153 (":PlugIns:PlugIns.prj", "PlugIns.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000154 ]),
155
156I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000157 (":build.macstand:PythonStandalone.prj", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000158 ]),
159
160I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000161 (":build.macstand:PythonStandSmall.prj", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000162 ]),
163
164I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000165 (":build.macstand:PythonStandalone.prj", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000166 ]),
167
168I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000169 (":build.macstand:PythonStandSmall.prj", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000170 ]),
171
172I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000173 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
174 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
175 (":Extensions:NumPy:numpymodules.prj", "numpymodules.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000176 ]),
177
178I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000179 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
180 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
181 (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000182 ]),
183
184I_APPLETS : (buildapplet, None, [
Jack Jansen6655c4e1995-09-01 12:03:32 +0000185 ":Mac:scripts:EditPythonPrefs.py",
Jack Jansen82bfde91997-08-27 14:10:29 +0000186 ":Mac:scripts:BuildApplet.py",
187 ":Mac:scripts:ConfigurePython.py"
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000188 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000189}
Jack Jansenfaad9951997-09-01 15:37:07 +0000190
191def incbuildno(filename):
192 fp = open(filename)
193 line = fp.readline()
194 fp.close()
195
196 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
197 pat.match(line)
198 buildno = pat.group(1)
199 if not buildno:
200 raise 'Incorrect macbuildno.h line', line
201 new = string.atoi(buildno) + 1
202 fp = open(filename, 'w')
203 fp.write('#define BUILD %d\n'%new)
204 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000205
206def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000207 try:
208 h = Res.OpenResFile('fullbuild.rsrc')
209 except Res.Error:
210 pass # Assume we already have acces to our own resource
211
Jack Jansen6655c4e1995-09-01 12:03:32 +0000212 dir, ok = macfs.GetDirectory('Python source folder:')
213 if not ok:
214 sys.exit(0)
215 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000216
Jack Jansen675cda01997-09-09 13:57:15 +0000217 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
218
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000219 instructions = []
220 for i in todo:
221 instructions.append(BUILD_DICT[i])
222
223 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000224 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000225
Jack Jansen6655c4e1995-09-01 12:03:32 +0000226 print "All done!"
227 sys.exit(1)
228
229if __name__ == '__main__':
230 main()
231