author | edouard |
Thu, 17 Feb 2011 10:11:04 +0100 | |
changeset 571 | 427bf9130d12 |
parent 546 | 093a20ea5ffc |
child 572 | c965548cb6f7 |
permissions | -rwxr-xr-x |
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
1 |
import os, re |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
2 |
from wxPopen import ProcessLogger |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
3 |
import hashlib |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
4 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
5 |
import time |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
6 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
7 |
includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
8 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
9 |
class toolchain_makefile(): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
10 |
def __init__(self, PluginsRootInstance): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
11 |
self.PluginsRootInstance = PluginsRootInstance |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
12 |
self.md5key = None |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
13 |
self.buildpath = None |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
14 |
self.SetBuildPath(self.PluginsRootInstance._getBuildPath()) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
15 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
16 |
def SetBuildPath(self, buildpath): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
17 |
self.buildpath = buildpath |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
18 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
19 |
def GetBinaryCode(self): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
20 |
return None |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
21 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
22 |
def _GetMD5FileName(self): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
23 |
return os.path.join(self.buildpath, "lastbuildPLC.md5") |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
24 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
25 |
def GetBinaryCodeMD5(self): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
26 |
if self.md5key is not None: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
27 |
return self.md5key |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
28 |
else: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
29 |
try: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
30 |
return open(self._GetMD5FileName(), "r").read() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
31 |
except IOError, e: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
32 |
return None |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
33 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
34 |
def build(self): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
35 |
srcfiles= [] |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
36 |
cflags = [] |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
37 |
for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
38 |
wholesrcdata = "" |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
39 |
# Get CFiles list to give it to makefile |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
40 |
for CFile, CFLAGS in CFilesAndCFLAGS: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
41 |
CFileName = os.path.basename(CFile) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
42 |
wholesrcdata += open(CFile, "r").read() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
43 |
srcfiles.append(CFileName) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
44 |
if CFLAGS not in cflags: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
45 |
cflags.append(CFLAGS) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
46 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
47 |
self.md5key = hashlib.md5(wholesrcdata).hexdigest() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
48 |
props = self.PluginsRootInstance.GetProjectProperties() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
49 |
self.md5key += '#'.join([props[key] for key in ['companyName', |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
50 |
'projectName', |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
51 |
'productName']]) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
52 |
self.md5key += '#' #+','.join(map(str,time.localtime())) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
53 |
# Store new PLC filename based on md5 key |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
54 |
f = open(self._GetMD5FileName(), "w") |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
55 |
f.write(self.md5key) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
56 |
f.close() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
57 |
beremizcommand = {"src": ' '.join(srcfiles), |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
58 |
"cflags": ' '.join(cflags), |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
59 |
"md5": '"'+self.md5key+'"' |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
60 |
} |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
61 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
62 |
target = self.PluginsRootInstance.GetTarget().getcontent()["value"] |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
63 |
command = target.getCommand().split(' ') +\ |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
64 |
[target.getBuildPath()] +\ |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
65 |
[arg % beremizcommand for arg in target.getArguments().split(' ')] +\ |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
66 |
target.getRule().split(' ') |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
67 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
68 |
# Call Makefile to build PLC code and link it with target specific code |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
69 |
status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger, |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
70 |
command).spin() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
71 |
if status : |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
72 |
self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n")) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
73 |
return False |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
546
diff
changeset
|
74 |
return True |