targets/toolchain_makefile.py
changeset 572 c965548cb6f7
parent 571 427bf9130d12
child 573 f0c5fc74018d
equal deleted inserted replaced
571:427bf9130d12 572:c965548cb6f7
    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.PluginsRootInstance._getBuildPath())
    15 
    15 
    16     def SetBuildPath(self, buildpath):
    16     def SetBuildPath(self, buildpath):
    17         self.buildpath = buildpath
    17         if self.buildpath != buildpath:
       
    18             self.buildpath = buildpath
       
    19             self.md5key = None
    18 
    20 
    19     def GetBinaryCode(self):
    21     def GetBinaryCode(self):
    20         return None
    22         return None
    21 
    23 
    22     def _GetMD5FileName(self):
    24     def _GetMD5FileName(self):
    32                 return None
    34                 return None
    33 
    35 
    34     def build(self):
    36     def build(self):
    35         srcfiles= []
    37         srcfiles= []
    36         cflags = []
    38         cflags = []
       
    39         wholesrcdata = "" 
       
    40         print self.PluginsRootInstance.LocationCFilesAndCFLAGS
    37         for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
    41         for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
    38             wholesrcdata = "" 
       
    39             # Get CFiles list to give it to makefile
    42             # Get CFiles list to give it to makefile
    40             for CFile, CFLAGS in CFilesAndCFLAGS:
    43             for CFile, CFLAGS in CFilesAndCFLAGS:
    41                 CFileName = os.path.basename(CFile)
    44                 CFileName = os.path.basename(CFile)
    42                 wholesrcdata += open(CFile, "r").read()
    45                 wholesrcdata += open(CFile, "r").read()
    43                 srcfiles.append(CFileName)
    46                 srcfiles.append(CFileName)
    44                 if CFLAGS not in cflags:
    47                 if CFLAGS not in cflags:
    45                     cflags.append(CFLAGS)
    48                     cflags.append(CFLAGS)
    46                     
    49                         
    47             self.md5key = hashlib.md5(wholesrcdata).hexdigest()
    50         oldmd5 = self.md5key
    48             props = self.PluginsRootInstance.GetProjectProperties()
    51         self.md5key = hashlib.md5(wholesrcdata).hexdigest()
    49             self.md5key += '#'.join([props[key] for key in ['companyName',
    52         props = self.PluginsRootInstance.GetProjectProperties()
    50                                                             'projectName',
    53         self.md5key += '#'.join([props[key] for key in ['companyName',
    51                                                             'productName']])
    54                                                         'projectName',
    52             self.md5key += '#' #+','.join(map(str,time.localtime()))
    55                                                         'productName']])
    53             # Store new PLC filename based on md5 key
    56         self.md5key += '#' #+','.join(map(str,time.localtime()))
    54             f = open(self._GetMD5FileName(), "w")
    57         # Store new PLC filename based on md5 key
    55             f.write(self.md5key)
    58         f = open(self._GetMD5FileName(), "w")
    56             f.close()
    59         f.write(self.md5key)
    57         beremizcommand = {"src": ' '.join(srcfiles),
    60         f.close()
    58                           "cflags": ' '.join(cflags),
    61 
    59                           "md5": '"'+self.md5key+'"'
    62         if oldmd5 != self.md5key :
    60                          }
    63             beremizcommand = {"src": ' '.join(srcfiles),
    61         
    64                               "cflags": ' '.join(cflags),
    62         target = self.PluginsRootInstance.GetTarget().getcontent()["value"]
    65                               "md5": '"'+self.md5key+'"'
    63         command = target.getCommand().split(' ') +\
    66                              }
    64                   [target.getBuildPath()] +\
    67             
    65                   [arg % beremizcommand for arg in target.getArguments().split(' ')] +\
    68             target = self.PluginsRootInstance.GetTarget().getcontent()["value"]
    66                   target.getRule().split(' ')
    69             command = target.getCommand().split(' ') +\
    67         
    70                       [target.getBuildPath()] +\
    68         # Call Makefile to build PLC code and link it with target specific code
    71                       [arg % beremizcommand for arg in target.getArguments().split(' ')] +\
    69         status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger,
    72                       target.getRule().split(' ')
    70                                                    command).spin()
    73             
    71         if status :
    74             # Call Makefile to build PLC code and link it with target specific code
    72             self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n"))
    75             status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger,
    73             return False
    76                                                        command).spin()
    74         return True
    77             if status :
       
    78                 self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n"))
       
    79                 return False
       
    80             return True
       
    81         else :
       
    82             self.PluginsRootInstance.logger.write(_("Source didn't change, no build.\n"))
       
    83             return True
       
    84