blob: 2b3585defd025032c1cda9f22338a98d761cfe7c [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
Jack Jansen675cda01997-09-09 13:57:15 +000042I_INC_BUILDNO=19
Jack Jansen0f00c5e1997-05-06 16:15:32 +000043
Jack Jansen82bfde91997-08-27 14:10:29 +000044I_CORE=3
Jack Jansen0f00c5e1997-05-06 16:15:32 +000045I_PPC_PLUGINS=4
46I_PPC_EXTENSIONS=5
Jack Jansen82bfde91997-08-27 14:10:29 +000047I_68K_PLUGINS=6
48I_68K_EXTENSIONS=7
49I_PPC_FULL=8
50I_PPC_SMALL=9
51I_68K_FULL=10
52I_68K_SMALL=11
53I_APPLETS=12
Jack Jansen0f00c5e1997-05-06 16:15:32 +000054
Jack Jansen82bfde91997-08-27 14:10:29 +000055N_BUTTONS=13
Jack Jansen6655c4e1995-09-01 12:03:32 +000056
Jack Jansen82bfde91997-08-27 14:10:29 +000057class MwShell(Metrowerks_Shell_Suite, CodeWarrior_Standard_Suite,
58 Required_Suite, aetools.TalkTo):
Jack Jansen6655c4e1995-09-01 12:03:32 +000059 pass
60
Jack Jansenf04fa721996-04-10 14:51:14 +000061RUNNING=[]
Jack Jansen6655c4e1995-09-01 12:03:32 +000062
63def buildmwproject(top, creator, projects):
64 """Build projects with an MW compiler"""
Jack Jansenb9e5e141996-09-20 15:30:52 +000065 mgr = MwShell(creator, start=1)
Jack Jansen1023dff1996-02-21 15:28:49 +000066 mgr.send_timeout = AppleEvents.kNoTimeOut
67
Jack Jansen6655c4e1995-09-01 12:03:32 +000068 for file in projects:
Jack Jansen82bfde91997-08-27 14:10:29 +000069 if type(file) == type(()):
70 file, target = file
71 else:
72 target = ''
Jack Jansen6655c4e1995-09-01 12:03:32 +000073 file = os.path.join(top, file)
74 fss = macfs.FSSpec(file)
Jack Jansen82bfde91997-08-27 14:10:29 +000075 print 'Building', file, target
Jack Jansen6655c4e1995-09-01 12:03:32 +000076 mgr.open(fss)
Jack Jansen82bfde91997-08-27 14:10:29 +000077 if target:
78 try:
79 mgr.Set_Current_Target(target)
80 except aetools.Error, arg:
81 print '**', file, target, 'Cannot select:', arg
Jack Jansen1023dff1996-02-21 15:28:49 +000082 try:
83 mgr.Make_Project()
Jack Jansenb9e5e141996-09-20 15:30:52 +000084 except aetools.Error, arg:
Jack Jansen82bfde91997-08-27 14:10:29 +000085 print '**', file, target, 'Failed:', arg
Jack Jansen6655c4e1995-09-01 12:03:32 +000086 mgr.Close_Project()
Jack Jansenf04fa721996-04-10 14:51:14 +000087## mgr.quit()
Jack Jansen6655c4e1995-09-01 12:03:32 +000088
89def buildapplet(top, dummy, list):
Jack Jansen0f00c5e1997-05-06 16:15:32 +000090 """Create python applets"""
Jack Jansen82bfde91997-08-27 14:10:29 +000091 template = BuildApplet.findtemplate()
Jack Jansen6655c4e1995-09-01 12:03:32 +000092 for src in list:
93 if src[-3:] != '.py':
94 raise 'Should end in .py', src
95 base = os.path.basename(src)
96 dst = os.path.join(top, base)[:-3]
97 src = os.path.join(top, src)
98 try:
99 os.unlink(dst)
100 except os.error:
101 pass
102 print 'Building applet', dst
Jack Jansen82bfde91997-08-27 14:10:29 +0000103 BuildApplet.process(template, src, dst)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000104
105def buildfat(top, dummy, list):
106 """Build fat binaries"""
107 for dst, src1, src2 in list:
108 dst = os.path.join(top, dst)
109 src1 = os.path.join(top, src1)
110 src2 = os.path.join(top, src2)
111 print 'Building fat binary', dst
112 cfmfile.mergecfmfiles((src1, src2), dst)
113
Jack Jansen675cda01997-09-09 13:57:15 +0000114def handle_dialog(filename):
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000115 """Handle selection dialog, return list of selected items"""
116 d = Dlg.GetNewDialog(DIALOG_ID, -1)
117 d.SetDialogDefaultItem(I_OK)
118 d.SetDialogCancelItem(I_CANCEL)
119 results = [0]*N_BUTTONS
120 while 1:
121 n = Dlg.ModalDialog(None)
122 if n == I_OK:
123 break
124 if n == I_CANCEL:
125 return []
Jack Jansen675cda01997-09-09 13:57:15 +0000126 if n == I_INC_BUILDNO:
127 incbuildno(filename)
128 continue
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000129 if n < len(results):
130 results[n] = (not results[n])
131 tp, h, rect = d.GetDialogItem(n)
132 h.as_Control().SetControlValue(results[n])
133 rv = []
134 for i in range(len(results)):
135 if results[i]:
136 rv.append(i)
137 return rv
Jack Jansen6655c4e1995-09-01 12:03:32 +0000138
139#
140# The build instructions. Entries are (routine, arg, list-of-files)
141# XXXX We could also include the builds for stdwin and such here...
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000142BUILD_DICT = {
Jack Jansen82bfde91997-08-27 14:10:29 +0000143I_CORE : (buildmwproject, "CWIE", [
144 (":build.mac:PythonCore.prj", "PythonCore"),
145 (":build.mac:Python.prj", "PythonFAT"),
146 (":build.mac:PythonApplet.prj", "PythonAppletFAT"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000147 ]),
148
149I_PPC_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000150 (":PlugIns:PlugIns.prj", "PlugIns.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000151 ]),
152
153I_68K_PLUGINS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000154 (":PlugIns:PlugIns.prj", "PlugIns.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000155 ]),
156
157I_68K_FULL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000158 (":build.macstand:PythonStandalone.prj", "Python68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000159 ]),
160
161I_68K_SMALL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000162 (":build.macstand:PythonStandSmall.prj", "PythonSmall68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000163 ]),
164
165I_PPC_FULL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000166 (":build.macstand:PythonStandalone.prj", "PythonStandalone"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000167 ]),
168
169I_PPC_SMALL : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000170 (":build.macstand:PythonStandSmall.prj", "PythonStandSmall"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000171 ]),
172
173I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000174 (":Extensions:Imaging:_imaging.prj", "_imaging.ppc"),
175 (":Extensions:Imaging:_tkinter.prj", "_tkinter.ppc"),
176 (":Extensions:NumPy:numpymodules.prj", "numpymodules.ppc"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000177 ]),
178
179I_68K_EXTENSIONS : (buildmwproject, "CWIE", [
Jack Jansen82bfde91997-08-27 14:10:29 +0000180 (":Extensions:Imaging:_imaging.prj", "_imaging.CFM68K"),
181 (":Extensions:Imaging:_tkinter.prj", "_tkinter.CFM68K"),
182 (":Extensions:NumPy:numpymodules.prj", "numpymodules.CFM68K"),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000183 ]),
184
185I_APPLETS : (buildapplet, None, [
Jack Jansen6655c4e1995-09-01 12:03:32 +0000186 ":Mac:scripts:EditPythonPrefs.py",
Jack Jansen82bfde91997-08-27 14:10:29 +0000187 ":Mac:scripts:BuildApplet.py",
188 ":Mac:scripts:ConfigurePython.py"
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000189 ]),
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000190}
Jack Jansenfaad9951997-09-01 15:37:07 +0000191
192def incbuildno(filename):
193 fp = open(filename)
194 line = fp.readline()
195 fp.close()
196
197 pat = regex.compile('#define BUILD \([0-9][0-9]*\)')
198 pat.match(line)
199 buildno = pat.group(1)
200 if not buildno:
201 raise 'Incorrect macbuildno.h line', line
202 new = string.atoi(buildno) + 1
203 fp = open(filename, 'w')
204 fp.write('#define BUILD %d\n'%new)
205 fp.close()
Jack Jansen6655c4e1995-09-01 12:03:32 +0000206
207def main():
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000208 try:
209 h = Res.OpenResFile('fullbuild.rsrc')
210 except Res.Error:
211 pass # Assume we already have acces to our own resource
212
Jack Jansen6655c4e1995-09-01 12:03:32 +0000213 dir, ok = macfs.GetDirectory('Python source folder:')
214 if not ok:
215 sys.exit(0)
216 dir = dir.as_pathname()
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000217
Jack Jansen675cda01997-09-09 13:57:15 +0000218 todo = handle_dialog(os.path.join(dir, MACBUILDNO))
219
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000220 instructions = []
221 for i in todo:
222 instructions.append(BUILD_DICT[i])
223
224 for routine, arg, list in instructions:
Jack Jansen8b4c9871997-05-07 15:52:12 +0000225 routine(dir, arg, list)
Jack Jansen0f00c5e1997-05-06 16:15:32 +0000226
Jack Jansen6655c4e1995-09-01 12:03:32 +0000227 print "All done!"
228 sys.exit(1)
229
230if __name__ == '__main__':
231 main()
232