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