author | laurent |
Fri, 04 Jun 2010 13:47:02 +0200 | |
changeset 553 | d071efd2a94b |
parent 546 | 093a20ea5ffc |
child 571 | 427bf9130d12 |
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 |
||
19 |
def GetBinaryCode(self): |
|
538
ad05f27222cd
Moved LPC specific code from toolchain_makefile into LPC target, added FROM_BEREMIZ variable to tell LPC's makefile it is invoked from here.
edouard
parents:
536
diff
changeset
|
20 |
return None |
508 | 21 |
|
22 |
def _GetMD5FileName(self): |
|
23 |
return os.path.join(self.buildpath, "lastbuildPLC.md5") |
|
24 |
||
25 |
def GetBinaryCodeMD5(self): |
|
26 |
if self.md5key is not None: |
|
27 |
return self.md5key |
|
28 |
else: |
|
29 |
try: |
|
30 |
return open(self._GetMD5FileName(), "r").read() |
|
31 |
except Exception, e: |
|
32 |
return None |
|
425 | 33 |
|
34 |
def build(self): |
|
35 |
srcfiles= [] |
|
36 |
cflags = [] |
|
37 |
for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: |
|
508 | 38 |
wholesrcdata = "" |
39 |
# Get CFiles list to give it to makefile |
|
425 | 40 |
for CFile, CFLAGS in CFilesAndCFLAGS: |
41 |
CFileName = os.path.basename(CFile) |
|
508 | 42 |
wholesrcdata += open(CFile, "r").read() |
425 | 43 |
srcfiles.append(CFileName) |
44 |
if CFLAGS not in cflags: |
|
45 |
cflags.append(CFLAGS) |
|
46 |
||
508 | 47 |
self.md5key = hashlib.md5(wholesrcdata).hexdigest() |
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
48 |
props = self.PluginsRootInstance.GetProjectProperties() |
536 | 49 |
self.md5key += '#'.join([props[key] for key in ['companyName', |
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
50 |
'projectName', |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
510
diff
changeset
|
51 |
'productName']]) |
536 | 52 |
self.md5key += '#'+','.join(map(str,time.localtime())) |
508 | 53 |
# Store new PLC filename based on md5 key |
54 |
f = open(self._GetMD5FileName(), "w") |
|
55 |
f.write(self.md5key) |
|
56 |
f.close() |
|
425 | 57 |
beremizcommand = {"src": ' '.join(srcfiles), |
508 | 58 |
"cflags": ' '.join(cflags), |
546 | 59 |
"md5": '"'+self.md5key+'"' |
425 | 60 |
} |
61 |
||
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
508
diff
changeset
|
62 |
target = self.PluginsRootInstance.GetTarget().getcontent()["value"] |
425 | 63 |
command = target.getCommand().split(' ') +\ |
64 |
[target.getBuildPath()] +\ |
|
65 |
[arg % beremizcommand for arg in target.getArguments().split(' ')] +\ |
|
66 |
target.getRule().split(' ') |
|
67 |
||
68 |
# Call Makefile to build PLC code and link it with target specific code |
|
69 |
status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger, |
|
70 |
command).spin() |
|
71 |
if status : |
|
72 |
self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n")) |
|
73 |
return False |
|
74 |
return True |