edouard@571: import os, re edouard@571: from wxPopen import ProcessLogger edouard@571: import hashlib edouard@571: edouard@571: import time edouard@571: edouard@571: includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') edouard@571: edouard@571: class toolchain_makefile(): edouard@571: def __init__(self, PluginsRootInstance): edouard@571: self.PluginsRootInstance = PluginsRootInstance edouard@571: self.md5key = None edouard@571: self.buildpath = None edouard@571: self.SetBuildPath(self.PluginsRootInstance._getBuildPath()) edouard@571: edouard@571: def SetBuildPath(self, buildpath): edouard@572: if self.buildpath != buildpath: edouard@572: self.buildpath = buildpath edouard@572: self.md5key = None edouard@571: edouard@571: def GetBinaryCode(self): edouard@571: return None edouard@571: edouard@571: def _GetMD5FileName(self): edouard@571: return os.path.join(self.buildpath, "lastbuildPLC.md5") edouard@571: edouard@571: def GetBinaryCodeMD5(self): edouard@571: if self.md5key is not None: edouard@571: return self.md5key edouard@571: else: edouard@571: try: edouard@571: return open(self._GetMD5FileName(), "r").read() edouard@571: except IOError, e: edouard@571: return None edouard@571: edouard@571: def build(self): edouard@571: srcfiles= [] edouard@571: cflags = [] edouard@572: wholesrcdata = "" edouard@572: print self.PluginsRootInstance.LocationCFilesAndCFLAGS edouard@571: for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: edouard@571: # Get CFiles list to give it to makefile edouard@571: for CFile, CFLAGS in CFilesAndCFLAGS: edouard@571: CFileName = os.path.basename(CFile) edouard@571: wholesrcdata += open(CFile, "r").read() edouard@571: srcfiles.append(CFileName) edouard@571: if CFLAGS not in cflags: edouard@571: cflags.append(CFLAGS) edouard@572: edouard@572: oldmd5 = self.md5key edouard@572: self.md5key = hashlib.md5(wholesrcdata).hexdigest() edouard@572: props = self.PluginsRootInstance.GetProjectProperties() edouard@572: self.md5key += '#'.join([props[key] for key in ['companyName', edouard@572: 'projectName', edouard@572: 'productName']]) edouard@572: self.md5key += '#' #+','.join(map(str,time.localtime())) edouard@572: # Store new PLC filename based on md5 key edouard@572: f = open(self._GetMD5FileName(), "w") edouard@572: f.write(self.md5key) edouard@572: f.close() edouard@572: edouard@572: if oldmd5 != self.md5key : edouard@572: beremizcommand = {"src": ' '.join(srcfiles), edouard@572: "cflags": ' '.join(cflags), edouard@572: "md5": '"'+self.md5key+'"' edouard@572: } edouard@572: edouard@572: target = self.PluginsRootInstance.GetTarget().getcontent()["value"] edouard@572: command = target.getCommand().split(' ') +\ edouard@572: [target.getBuildPath()] +\ edouard@572: [arg % beremizcommand for arg in target.getArguments().split(' ')] +\ edouard@572: target.getRule().split(' ') edouard@572: edouard@572: # Call Makefile to build PLC code and link it with target specific code edouard@572: status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger, edouard@572: command).spin() edouard@572: if status : edouard@572: self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n")) edouard@572: return False edouard@572: return True edouard@572: else : edouard@572: self.PluginsRootInstance.logger.write(_("Source didn't change, no build.\n")) edouard@572: return True edouard@572: