blob: 64adda96aea08393178798c4447780c9823150cf [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 Jansen490ec9c1998-07-31 09:45:27 +000031import buildtools
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)
Just van Rossum2607a441999-01-30 18:27:12 +000073 try:
74 fss = macfs.FSSpec(file)
75 except ValueError:
76 print '** file not found:', file
77 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000078 print 'Building', file, target
Just van Rossum2607a441999-01-30 18:27:12 +000079 try:
80 mgr.open(fss)
81 except aetools.Error, detail:
82 print '**', detail, file
83 continue
Jack Jansen82bfde91997-08-27 14:10:29 +000084 if target:
85 try:
86 mgr.Set_Current_Target(target)
87 except aetools.Error, arg:
88 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +000089 try:
90 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +000091 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +000092 print '**', file, target, 'Failed:', arg
Jack Jansen6655c4e1995-09-01 12:03:32 +000093 mgr.Close_Project()
Jack Jansenf04fa721996-04-10 14:51:14 +000094## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +000095
96def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +000097 """Create python applets"""
Jack Jansen490ec9c1998-07-31 09:45:27 +000098 template = buildtools.findtemplate()
Just van Rossum9d609b41999-02-01 01:21:18 +000099 for src, dst in list:
Jack Jansen6655c4e1995-09-01 12:03:32 +0000100 if src[-3:] != '.py':
101 raise 'Should end in .py', src
102 base = os.path.basename(src)
Just van Rossum9d609b41999-02-01 01:21:18 +0000103 #dst = os.path.join(top, base)[:-3]
Jack Jansen6655c4e1995-09-01 12:03:32 +0000104 src = os.path.join(top, src)
Just van Rossum9d609b41999-02-01 01:21:18 +0000105 dst = os.path.join(top, dst)
Jack Jansen6655c4e1995-09-01 12:03:32 +0000106 try:
107 os.unlink(dst)
108 except os.error:
109 pass
110 print 'Building applet', dst
Jack Jansen490ec9c1998-07-31 09:45:27 +0000111 buildtools.process(template, src, dst, 1)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000112
113def buildfat(top, dummy, list):
114 """Build fat binaries"""
115 for dst, src1, src2 in list:
116 dst = os.path.join(top, dst)
117 src1 = os.path.join(top, src1)
118 src2 = os.path.join(top, src2)
119 print 'Building fat binary', dst
120 cfmfile.mergecfmfiles((src1, src2), dst)
121
Jack Jansen675cda01997-09-09 13:57:15 +0000122def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000123 """Handle selection dialog, return list of selected items"""
124 d = Dlg.GetNewDialog(DIALOG_ID, -1)
125 d.SetDialogDefaultItem(I_OK)
126 d.SetDialogCancelItem(I_CANCEL)
127 results = [0]*N_BUTTONS
128 while 1:
129 n = Dlg.ModalDialog(None)
130 if n == I_OK:
131 break
132 if n == I_CANCEL:
133 return []
Jack Jansen675cda01997-09-09 13:57:15 +0000134 if n == I_INC_BUILDNO:
135 incbuildno(filename)
136 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000137 if n < len(results):
138 results[n] = (not results[n])
139 tp, h, rect = d.GetDialogItem(n)
140 h.as_Control().SetControlValue(results[n])
141 rv = []
142 for i in range(len(results)):
143 if results[i]:
144 rv.append(i)
145 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000146
147#
148# The build instructions. Entries are (routine, arg, list-of-files)
149# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000150BUILD_DICT = {
Jack Jansen82bfde91997-08-27 14:10:29 +0000151I_CORE : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000152 (":Mac:Build:PythonCore.prj", "PythonCore"),
153 (":Mac:Build:Python.prj", "PythonFAT"),
154 (":Mac:Build:PythonApplet.prj", "PythonAppletFAT"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000155 ]),
156
157I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000158 (":Mac:Build:PlugIns.prj", "PlugIns.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000159 ]),
160
161I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000162 (":Mac:Build:PlugIns.prj", "PlugIns.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000163 ]),
164
165I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000166 (":Mac:Build:PythonStandalone.prj", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000167 ]),
168
169I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000170 (":Mac:Build:PythonStandSmall.prj", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000171 ]),
172
173I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000174 (":Mac:Build:PythonStandalone.prj", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000175 ]),
176
177I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansenc9bda411999-01-28 17:46:50 +0000178 (":Mac:Build:PythonStandSmall.prj", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000179 ]),
180
181I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000182 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
183 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
184 (":Extensions:NumPy:numpymodules.prj", "numpymodules.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000185 ]),
186
187I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000188 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
189 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
190 (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000191 ]),
192
193I_APPLETS : (buildapplet, None, [
Just van Rossum9d609b41999-02-01 01:21:18 +0000194 (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs"),
195 (":Mac:scripts:BuildApplet.py", "BuildApplet"),
196 (":Mac:scripts:BuildApplication.py", "BuildApplication"),
197 (":Mac:scripts:ConfigurePython.py", "ConfigurePython"),
198 (":Mac:Tools:IDE:PythonIDE.py", "Python IDE"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000199 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000200}
Jack Jansenfaad9951997-09-01 15:37:07 +0000201
202def incbuildno(filename):
203 fp = open(filename)
204 line = fp.readline()
205 fp.close()
206
207 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
208 pat.match(line)
209 buildno = pat.group(1)
210 if not buildno:
211 raise 'Incorrect macbuildno.h line', line
212 new = string.atoi(buildno) + 1
213 fp = open(filename, 'w')
214 fp.write('#define BUILD %d\n'%new)
215 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000216
217def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000218 try:
219 h = Res.OpenResFile('fullbuild.rsrc')
220 except Res.Error:
221 pass # Assume we already have acces to our own resource
222
Jack Jansen6655c4e1995-09-01 12:03:32 +0000223 dir, ok = macfs.GetDirectory('Python source folder:')
224 if not ok:
225 sys.exit(0)
226 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000227
Jack Jansen675cda01997-09-09 13:57:15 +0000228 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
229
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000230 instructions = []
231 for i in todo:
232 instructions.append(BUILD_DICT[i])
233
234 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000235 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000236
Jack Jansen6655c4e1995-09-01 12:03:32 +0000237 print "All done!"
238 sys.exit(1)
239
240if __name__ == '__main__':
241 main()
242