2000-09-22 20:26:55 -03:00
|
|
|
import cwxmlgen
|
|
|
|
import cwtalker
|
2000-09-22 20:54:07 -03:00
|
|
|
import os
|
2001-08-25 09:15:04 -03:00
|
|
|
from Carbon import AppleEvents
|
2003-03-21 08:55:38 -04:00
|
|
|
import Carbon.File
|
2000-09-22 20:26:55 -03:00
|
|
|
|
2001-01-23 18:35:22 -04:00
|
|
|
def mkproject(outputfile, modulename, settings, force=0, templatename=None):
|
2000-09-22 20:26:55 -03:00
|
|
|
#
|
|
|
|
# Copy the dictionary
|
|
|
|
#
|
|
|
|
dictcopy = {}
|
|
|
|
for k, v in settings.items():
|
|
|
|
dictcopy[k] = v
|
|
|
|
#
|
2001-12-14 10:31:15 -04:00
|
|
|
# Generate the XML for the project
|
2000-09-22 20:26:55 -03:00
|
|
|
#
|
|
|
|
dictcopy['mac_projectxmlname'] = outputfile + '.xml'
|
|
|
|
dictcopy['mac_exportname'] = os.path.split(outputfile)[1] + '.exp'
|
2001-01-23 18:35:22 -04:00
|
|
|
if not dictcopy.has_key('mac_dllname'):
|
|
|
|
dictcopy['mac_dllname'] = modulename + '.ppc.slb'
|
|
|
|
if not dictcopy.has_key('mac_targetname'):
|
|
|
|
dictcopy['mac_targetname'] = modulename + '.ppc'
|
2001-12-14 10:31:15 -04:00
|
|
|
|
2001-01-23 18:35:22 -04:00
|
|
|
xmlbuilder = cwxmlgen.ProjectBuilder(dictcopy, templatename=templatename)
|
2000-09-22 20:26:55 -03:00
|
|
|
xmlbuilder.generate()
|
2001-01-21 18:23:13 -04:00
|
|
|
if not force:
|
2001-01-22 11:38:40 -04:00
|
|
|
# We do a number of checks and all must succeed before we decide to
|
|
|
|
# skip the build-project step:
|
|
|
|
# 1. the xml file must exist, and its content equal to what we've generated
|
|
|
|
# 2. the project file must exist and be newer than the xml file
|
|
|
|
# 3. the .exp file must exist
|
2001-01-21 18:23:13 -04:00
|
|
|
if os.path.exists(dictcopy['mac_projectxmlname']):
|
|
|
|
fp = open(dictcopy['mac_projectxmlname'])
|
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
|
|
|
if data == dictcopy["tmp_projectxmldata"]:
|
2001-01-22 11:38:40 -04:00
|
|
|
if os.path.exists(outputfile) and \
|
|
|
|
os.stat(outputfile)[os.path.ST_MTIME] > os.stat(dictcopy['mac_projectxmlname'])[os.path.ST_MTIME]:
|
|
|
|
if os.path.exists(outputfile + '.exp'):
|
|
|
|
return
|
2000-09-22 20:26:55 -03:00
|
|
|
fp = open(dictcopy['mac_projectxmlname'], "w")
|
2000-09-22 20:54:07 -03:00
|
|
|
fp.write(dictcopy["tmp_projectxmldata"])
|
2000-09-22 20:26:55 -03:00
|
|
|
fp.close()
|
|
|
|
#
|
|
|
|
# Generate the export file
|
|
|
|
#
|
|
|
|
fp = open(outputfile + '.exp', 'w')
|
|
|
|
fp.write('init%s\n'%modulename)
|
2000-12-03 18:39:09 -04:00
|
|
|
if dictcopy.has_key('extraexportsymbols'):
|
|
|
|
for sym in dictcopy['extraexportsymbols']:
|
|
|
|
fp.write('%s\n'%sym)
|
2000-09-22 20:26:55 -03:00
|
|
|
fp.close()
|
|
|
|
#
|
|
|
|
# Generate the project from the xml
|
|
|
|
#
|
2000-09-24 18:56:43 -03:00
|
|
|
makeproject(dictcopy['mac_projectxmlname'], outputfile)
|
|
|
|
|
|
|
|
def makeproject(xmlfile, projectfile):
|
2000-09-22 20:26:55 -03:00
|
|
|
cw = cwtalker.MyCodeWarrior(start=1)
|
|
|
|
cw.send_timeout = AppleEvents.kNoTimeOut
|
2003-03-21 08:55:38 -04:00
|
|
|
xmlfss = Carbon.File.FSSpec(xmlfile)
|
|
|
|
prjfss = Carbon.File.FSSpec(projectfile)
|
2000-09-22 20:26:55 -03:00
|
|
|
cw.my_mkproject(prjfss, xmlfss)
|
2002-06-26 17:35:18 -03:00
|
|
|
cw.Close_Project()
|
2000-09-22 20:26:55 -03:00
|
|
|
|
|
|
|
def buildproject(projectfile):
|
|
|
|
cw = cwtalker.MyCodeWarrior(start=1)
|
|
|
|
cw.send_timeout = AppleEvents.kNoTimeOut
|
2003-03-21 08:55:38 -04:00
|
|
|
prjfss = Carbon.File.FSSpec(projectfile)
|
2000-09-22 20:26:55 -03:00
|
|
|
cw.open(prjfss)
|
|
|
|
cw.Make_Project() # XXX Should set target
|
2000-11-19 17:51:06 -04:00
|
|
|
cw.Close_Project()
|
2000-09-22 20:26:55 -03:00
|
|
|
|
|
|
|
def cleanproject(projectfile):
|
|
|
|
cw = cwtalker.MyCodeWarrior(start=1)
|
|
|
|
cw.send_timeout = AppleEvents.kNoTimeOut
|
2003-03-21 08:55:38 -04:00
|
|
|
prjfss = Carbon.File.FSSpec(projectfile)
|
2000-09-22 20:26:55 -03:00
|
|
|
cw.open(prjfss)
|
|
|
|
cw.Remove_Binaries()
|
|
|
|
|