from wxPopen import ProcessLogger
includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*')
This abstract class contains GCC specific code.
It cannot be used as this and should be inherited in a target specific
class such as target_linux or target_win32
def __init__(self, PuginsRootInstance):
self.PuginsRootInstance = PuginsRootInstance
self.logger = PuginsRootInstance.logger
self.exe = PuginsRootInstance.GetProjectName() + self.extension
self.buildpath = PuginsRootInstance._getBuildPath()
self.exe_path = os.path.join(self.buildpath, self.exe)
return open(self.exe_path, "rb").read()
def _GetMD5FileName(self):
return os.path.join(self.buildpath, "lastbuildPLC.md5")
def GetBinaryCodeMD5(self):
if self.md5key is not None:
return open(self._GetMD5FileName(), "r").read()
def check_and_update_hash_and_deps(self, bn):
# Get latest computed hash and deps
oldhash, deps = self.srcmd5.get(bn,(None,[]))
src = open(os.path.join(self.buildpath, bn)).read()
newhash = hashlib.md5(src).hexdigest()
match = (oldhash == newhash)
# update direct dependencies
for l in src.splitlines():
res = includes_re.match(l)
if os.path.exists(os.path.join(self.buildpath, depfn)):
#print bn + " depends on "+depfn
# store that hashand deps
self.srcmd5[bn] = (newhash, deps)
# TODO detect cicular deps.
return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match)
# Retrieve toolchain user parameters
toolchain_params = self.PuginsRootInstance.BeremizRoot.getTargetType().getcontent()["value"]
self.compiler = toolchain_params.getCompiler()
self._CFLAGS = toolchain_params.getCFLAGS()
self.linker = toolchain_params.getLinker()
self._LDFLAGS = toolchain_params.getLDFLAGS()
######### GENERATE OBJECT FILES ########################################
for Location, CFilesAndCFLAGS, DoCalls in self.PuginsRootInstance.LocationCFilesAndCFLAGS:
self.logger.write("Plugin : " + self.PuginsRootInstance.GetChildByIECLocation(Location).GetCurrentName() + " " + str(Location)+"\n")
self.logger.write("PLC :\n")
for CFile, CFLAGS in CFilesAndCFLAGS:
bn = os.path.basename(CFile)
obn = os.path.splitext(bn)[0]+".o"
objectfilename = os.path.splitext(CFile)[0]+".o"
match = self.check_and_update_hash_and_deps(bn)
self.logger.write(" [pass] "+bn+" -> "+obn+"\n")
self.logger.write(" [CC] "+bn+" -> "+obn+"\n")
status, result, err_result = ProcessLogger(
"\"%s\" -c \"%s\" -o \"%s\" %s %s"%
(self.compiler, CFile, objectfilename, self._CFLAGS, CFLAGS)
self.logger.write_error("C compilation of "+ bn +" failed.\n")
objs.append(objectfilename)
######### GENERATE library FILE ########################################
# Link all the object files into one binary file
self.logger.write("Linking :\n")
listobjstring = '"' + '" "'.join(objs) + '"'
ALLldflags = ' '.join(self.CustomLDFLAGS+self.PuginsRootInstance.LDFLAGS+[self._LDFLAGS])
self.logger.write(" [CC] " + ' '.join(obns)+" -> " + self.exe + "\n")
status, result, err_result = ProcessLogger(
"\"%s\" %s -o \"%s\" %s"%
# Calculate md5 key and get data for the new created PLC
data=self.GetBinaryCode()
self.md5key = hashlib.md5(data).hexdigest()
# Store new PLC filename based on md5 key
f = open(self._GetMD5FileName(), "w")
self.logger.write(" [pass] " + ' '.join(obns)+" -> " + self.exe + "\n")