targets/toolchain_makefile.py
changeset 717 1c23952dbde1
parent 691 bb340874f09e
child 722 a94f361fc42e
equal deleted inserted replaced
716:180e4a7d945c 717:1c23952dbde1
     5 import time
     5 import time
     6 
     6 
     7 includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
     7 includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
     8 
     8 
     9 class toolchain_makefile():
     9 class toolchain_makefile():
    10     def __init__(self, PluginsRootInstance):
    10     def __init__(self, ConfigTreeRootInstance):
    11         self.PluginsRootInstance = PluginsRootInstance
    11         self.ConfigTreeRootInstance = ConfigTreeRootInstance
    12         self.md5key = None 
    12         self.md5key = None 
    13         self.buildpath = None
    13         self.buildpath = None
    14         self.SetBuildPath(self.PluginsRootInstance._getBuildPath())
    14         self.SetBuildPath(self.ConfigTreeRootInstance._getBuildPath())
    15 
    15 
    16     def SetBuildPath(self, buildpath):
    16     def SetBuildPath(self, buildpath):
    17         if self.buildpath != buildpath:
    17         if self.buildpath != buildpath:
    18             self.buildpath = buildpath
    18             self.buildpath = buildpath
    19             self.md5key = None
    19             self.md5key = None
    58 
    58 
    59     def build(self):
    59     def build(self):
    60         srcfiles= []
    60         srcfiles= []
    61         cflags = []
    61         cflags = []
    62         wholesrcdata = "" 
    62         wholesrcdata = "" 
    63         for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
    63         for Location, CFilesAndCFLAGS, DoCalls in self.ConfigTreeRootInstance.LocationCFilesAndCFLAGS:
    64             # Get CFiles list to give it to makefile
    64             # Get CFiles list to give it to makefile
    65             for CFile, CFLAGS in CFilesAndCFLAGS:
    65             for CFile, CFLAGS in CFilesAndCFLAGS:
    66                 CFileName = os.path.basename(CFile)
    66                 CFileName = os.path.basename(CFile)
    67                 wholesrcdata += self.concat_deps(CFileName)
    67                 wholesrcdata += self.concat_deps(CFileName)
    68                 #wholesrcdata += open(CFile, "r").read()
    68                 #wholesrcdata += open(CFile, "r").read()
    70                 if CFLAGS not in cflags:
    70                 if CFLAGS not in cflags:
    71                     cflags.append(CFLAGS)
    71                     cflags.append(CFLAGS)
    72                         
    72                         
    73         oldmd5 = self.md5key
    73         oldmd5 = self.md5key
    74         self.md5key = hashlib.md5(wholesrcdata).hexdigest()
    74         self.md5key = hashlib.md5(wholesrcdata).hexdigest()
    75         props = self.PluginsRootInstance.GetProjectProperties()
    75         props = self.ConfigTreeRootInstance.GetProjectProperties()
    76         self.md5key += '#'.join([props[key] for key in ['companyName',
    76         self.md5key += '#'.join([props[key] for key in ['companyName',
    77                                                         'projectName',
    77                                                         'projectName',
    78                                                         'productName']])
    78                                                         'productName']])
    79         self.md5key += '#' #+','.join(map(str,time.localtime()))
    79         self.md5key += '#' #+','.join(map(str,time.localtime()))
    80         # Store new PLC filename based on md5 key
    80         # Store new PLC filename based on md5 key
    86             beremizcommand = {"src": ' '.join(srcfiles),
    86             beremizcommand = {"src": ' '.join(srcfiles),
    87                               "cflags": ' '.join(cflags),
    87                               "cflags": ' '.join(cflags),
    88                               "md5": '"'+self.md5key+'"'
    88                               "md5": '"'+self.md5key+'"'
    89                              }
    89                              }
    90             
    90             
    91             target = self.PluginsRootInstance.GetTarget().getcontent()["value"]
    91             target = self.ConfigTreeRootInstance.GetTarget().getcontent()["value"]
    92             command = target.getCommand().split(' ') +\
    92             command = target.getCommand().split(' ') +\
    93                       [target.getBuildPath()] +\
    93                       [target.getBuildPath()] +\
    94                       [arg % beremizcommand for arg in target.getArguments().split(' ')] +\
    94                       [arg % beremizcommand for arg in target.getArguments().split(' ')] +\
    95                       target.getRule().split(' ')
    95                       target.getRule().split(' ')
    96             
    96             
    97             # Call Makefile to build PLC code and link it with target specific code
    97             # Call Makefile to build PLC code and link it with target specific code
    98             status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger,
    98             status, result, err_result = ProcessLogger(self.ConfigTreeRootInstance.logger,
    99                                                        command).spin()
    99                                                        command).spin()
   100             if status :
   100             if status :
   101                 self.md5key = None
   101                 self.md5key = None
   102                 self.PluginsRootInstance.logger.write_error(_("C compilation failed.\n"))
   102                 self.ConfigTreeRootInstance.logger.write_error(_("C compilation failed.\n"))
   103                 return False
   103                 return False
   104             return True
   104             return True
   105         else :
   105         else :
   106             self.PluginsRootInstance.logger.write(_("Source didn't change, no build.\n"))
   106             self.ConfigTreeRootInstance.logger.write(_("Source didn't change, no build.\n"))
   107             return True
   107             return True
   108 
   108