author | Edouard TISSERANT <edouard.tisserant@gmail.com> |
Wed, 23 Dec 2009 22:23:02 +0100 | |
changeset 532 | a822b0b64252 |
parent 521 | 02cb9e5fb6f6 |
child 536 | 9b77aabf3d36 |
permissions | -rwxr-xr-x |
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
508
diff
changeset
|
1 |
import os, re |
425 | 2 |
from wxPopen import ProcessLogger |
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
508
diff
changeset
|
3 |
import hashlib |
425 | 4 |
|
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
5 |
import time |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
6 |
|
425 | 7 |
includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') |
8 |
||
508 | 9 |
class toolchain_makefile(): |
10 |
def __init__(self, PluginsRootInstance): |
|
11 |
self.PluginsRootInstance = PluginsRootInstance |
|
12 |
self.md5key = None |
|
13 |
self.buildpath = None |
|
14 |
self.SetBuildPath(self.PluginsRootInstance._getBuildPath()) |
|
15 |
||
16 |
def SetBuildPath(self, buildpath): |
|
17 |
self.buildpath = buildpath |
|
18 |
self.exe_path = os.path.join(self.buildpath, "ArmPLC_rom.bin") |
|
19 |
self.md5_path = os.path.join(self.buildpath, "ArmPLC.md5") |
|
20 |
||
21 |
def GetBinaryCode(self): |
|
22 |
try: |
|
23 |
return open(self.exe_path, "rb").read() |
|
24 |
except Exception, e: |
|
25 |
return None |
|
26 |
||
27 |
def _GetMD5FileName(self): |
|
28 |
return os.path.join(self.buildpath, "lastbuildPLC.md5") |
|
29 |
||
30 |
def GetBinaryCodeMD5(self): |
|
31 |
if self.md5key is not None: |
|
32 |
return self.md5key |
|
33 |
else: |
|
34 |
try: |
|
35 |
return open(self._GetMD5FileName(), "r").read() |
|
36 |
except Exception, e: |
|
37 |
return None |
|
425 | 38 |
|
39 |
def build(self): |
|
40 |
srcfiles= [] |
|
41 |
cflags = [] |
|
42 |
for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: |
|
508 | 43 |
wholesrcdata = "" |
44 |
# Get CFiles list to give it to makefile |
|
425 | 45 |
for CFile, CFLAGS in CFilesAndCFLAGS: |
46 |
CFileName = os.path.basename(CFile) |
|
508 | 47 |
wholesrcdata += open(CFile, "r").read() |
425 | 48 |
srcfiles.append(CFileName) |
49 |
if CFLAGS not in cflags: |
|
50 |
cflags.append(CFLAGS) |
|
51 |
||
508 | 52 |
self.md5key = hashlib.md5(wholesrcdata).hexdigest() |
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
53 |
props = self.PluginsRootInstance.GetProjectProperties() |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
54 |
self.md5key += '|'.join([props[key] for key in ['companyName', |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
55 |
'projectName', |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
56 |
'productName']]) |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
57 |
self.md5key += '|'+','.join(map(str,time.localtime())) |
508 | 58 |
# Store new PLC filename based on md5 key |
59 |
f = open(self._GetMD5FileName(), "w") |
|
60 |
f.write(self.md5key) |
|
61 |
f.close() |
|
425 | 62 |
beremizcommand = {"src": ' '.join(srcfiles), |
508 | 63 |
"cflags": ' '.join(cflags), |
64 |
"md5": self.md5key |
|
425 | 65 |
} |
66 |
||
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
508
diff
changeset
|
67 |
target = self.PluginsRootInstance.GetTarget().getcontent()["value"] |
425 | 68 |
command = target.getCommand().split(' ') +\ |
69 |
[target.getBuildPath()] +\ |
|
70 |
[arg % beremizcommand for arg in target.getArguments().split(' ')] +\ |
|
71 |
target.getRule().split(' ') |
|
72 |
||
73 |
# Call Makefile to build PLC code and link it with target specific code |
|
74 |
status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger, |
|
75 |
command).spin() |
|
76 |
if status : |
|
77 |
self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n")) |
|
78 |
return False |
|
79 |
return True |