targets/toolchain_makefile.py
changeset 1649 3291024e00da
parent 1575 de2da05089ea
child 1709 1e8900fc8ddb
equal deleted inserted replaced
1648:6431f26aa501 1649:3291024e00da
    27 import hashlib
    27 import hashlib
    28 
    28 
    29 import time
    29 import time
    30 
    30 
    31 includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
    31 includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
    32 
       
    33 
       
    34 if os.name == 'nt':
       
    35     # on windows, desktop shortcut launches Beremiz.py
       
    36     # with working dir set to mingw/bin.
       
    37     # then we prefix CWD to PATH in order to ensure that
       
    38     # commands invoked from Makefiles will first resolve
       
    39     # to here.
       
    40     os.environ["PATH"] = os.getcwd()+';'+os.environ["PATH"]
       
    41 
    32 
    42 class toolchain_makefile():
    33 class toolchain_makefile():
    43     def __init__(self, CTRInstance):
    34     def __init__(self, CTRInstance):
    44         self.CTRInstance = CTRInstance
    35         self.CTRInstance = CTRInstance
    45         self.md5key = None 
    36         self.md5key = None 
   102                 if CFLAGS not in cflags:
    93                 if CFLAGS not in cflags:
   103                     cflags.append(CFLAGS)
    94                     cflags.append(CFLAGS)
   104                         
    95                         
   105         oldmd5 = self.md5key
    96         oldmd5 = self.md5key
   106         self.md5key = hashlib.md5(wholesrcdata).hexdigest()
    97         self.md5key = hashlib.md5(wholesrcdata).hexdigest()
   107         props = self.CTRInstance.GetProjectProperties()
    98 
   108         self.md5key += '#'.join([props[key] for key in ['companyName',
       
   109                                                         'projectName',
       
   110                                                         'productName']])
       
   111         self.md5key += '#' #+','.join(map(str,time.localtime()))
       
   112         # Store new PLC filename based on md5 key
    99         # Store new PLC filename based on md5 key
   113         f = open(self._GetMD5FileName(), "w")
   100         f = open(self._GetMD5FileName(), "w")
   114         f.write(self.md5key)
   101         f.write(self.md5key)
   115         f.close()
   102         f.close()
   116 
   103 
   120                               "cflags": ' '.join(cflags),
   107                               "cflags": ' '.join(cflags),
   121                               "md5": self.md5key,
   108                               "md5": self.md5key,
   122                               "buildpath": self.buildpath
   109                               "buildpath": self.buildpath
   123                              }
   110                              }
   124             
   111             
   125             command = [ token % beremizcommand for token in target.getCommand().split(' ')]
   112             # clean sequence of multiple whitespaces 
       
   113             cmd = re.sub(r"[ ]+", " ", target.getCommand())
       
   114 
       
   115             command = [ token % beremizcommand for token in cmd.split(' ')]
   126 
   116 
   127             # Call Makefile to build PLC code and link it with target specific code
   117             # Call Makefile to build PLC code and link it with target specific code
   128             status, result, err_result = ProcessLogger(self.CTRInstance.logger,
   118             status, result, err_result = ProcessLogger(self.CTRInstance.logger,
   129                                                        command).spin()
   119                                                        command).spin()
   130             if status :
   120             if status :