blob: ff090d0f779b5ba468cc2daee5e47c1e0dde4ee6 [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
22import addpack
Jack Jansen6655c4e1995-09-01 12:03:32 +000023import aetools
Jack Jansen1023dff1996-02-21 15:28:49 +000024import AppleEvents
Jack Jansen6655c4e1995-09-01 12:03:32 +000025from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite
Jack Jansen82bfde91997-08-27 14:10:29 +000026from CodeWarrior_Standard_Suite import CodeWarrior_Standard_Suite
Jack Jansen0f00c5e1997-05-06 16:15:32 +000027from Required_Suite import Required_Suite
28
29import Res
30import Dlg
Jack Jansen6655c4e1995-09-01 12:03:32 +000031
Jack Jansen82bfde91997-08-27 14:10:29 +000032import BuildApplet
Jack Jansen0f00c5e1997-05-06 16:15:32 +000033import cfmfile
34
35# Dialog resource. Note that the item numbers should correspond
36# to those in the DITL resource. Also note that the order is important:
37# things are built in this order, so there should be no forward dependencies.
38DIALOG_ID = 512
39
40I_OK=1
41I_CANCEL=2
42
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
113def handle_dialog():
114 """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 []
125 if n < len(results):
126 results[n] = (not results[n])
127 tp, h, rect = d.GetDialogItem(n)
128 h.as_Control().SetControlValue(results[n])
129 rv = []
130 for i in range(len(results)):
131 if results[i]:
132 rv.append(i)
133 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000134
135#
136# The build instructions. Entries are (routine, arg, list-of-files)
137# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000138BUILD_DICT = {
Jack Jansen82bfde91997-08-27 14:10:29 +0000139I_CORE : (buildmwproject, "CWIE", [
140 (":build.mac:PythonCore.prj", "PythonCore"),
141 (":build.mac:Python.prj", "PythonFAT"),
142 (":build.mac:PythonApplet.prj", "PythonAppletFAT"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000143 ]),
144
145I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000146 (":PlugIns:PlugIns.prj", "PlugIns.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000147 ]),
148
149I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000150 (":PlugIns:PlugIns.prj", "PlugIns.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000151 ]),
152
153I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000154 (":build.macstand:PythonStandalone.prj", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000155 ]),
156
157I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000158 (":build.macstand:PythonStandSmall.prj", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000159 ]),
160
161I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000162 (":build.macstand:PythonStandalone.prj", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000163 ]),
164
165I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000166 (":build.macstand:PythonStandSmall.prj", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000167 ]),
168
169I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000170 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
171 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
172 (":Extensions:NumPy:numpymodules.prj", "numpymodules.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000173 ]),
174
175I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000176 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
177 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
178 (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000179 ]),
180
181I_APPLETS : (buildapplet, None, [
Jack Jansen6655c4e1995-09-01 12:03:32 +0000182 ":Mac:scripts:EditPythonPrefs.py",
Jack Jansen82bfde91997-08-27 14:10:29 +0000183 ":Mac:scripts:BuildApplet.py",
184 ":Mac:scripts:ConfigurePython.py"
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000185 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000186}
Jack Jansenfaad9951997-09-01 15:37:07 +0000187
188def incbuildno(filename):
189 fp = open(filename)
190 line = fp.readline()
191 fp.close()
192
193 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
194 pat.match(line)
195 buildno = pat.group(1)
196 if not buildno:
197 raise 'Incorrect macbuildno.h line', line
198 new = string.atoi(buildno) + 1
199 fp = open(filename, 'w')
200 fp.write('#define BUILD %d\n'%new)
201 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000202
203def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000204 try:
205 h = Res.OpenResFile('fullbuild.rsrc')
206 except Res.Error:
207 pass # Assume we already have acces to our own resource
208
Jack Jansen6655c4e1995-09-01 12:03:32 +0000209 dir, ok = macfs.GetDirectory('Python source folder:')
210 if not ok:
211 sys.exit(0)
212 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000213
214 todo = handle_dialog()
215
Jack Jansenfaad9951997-09-01 15:37:07 +0000216 incbuildno(os.path.join(dir, MACBUILDNO))
217
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000218 instructions = []
219 for i in todo:
220 instructions.append(BUILD_DICT[i])
221
222 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000223 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000224
Jack Jansen6655c4e1995-09-01 12:03:32 +0000225 print "All done!"
226 sys.exit(1)
227
228if __name__ == '__main__':
229 main()
230