425
|
1 |
import os, re, operator
|
|
2 |
from wxPopen import ProcessLogger
|
|
3 |
import hashlib, shutil
|
|
4 |
from toolchain_gcc import toolchain_gcc
|
|
5 |
|
|
6 |
includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*')
|
|
7 |
|
508
|
8 |
class toolchain_makefile():
|
|
9 |
def __init__(self, PluginsRootInstance):
|
|
10 |
self.PluginsRootInstance = PluginsRootInstance
|
|
11 |
self.md5key = None
|
|
12 |
self.buildpath = None
|
|
13 |
self.SetBuildPath(self.PluginsRootInstance._getBuildPath())
|
|
14 |
|
|
15 |
def getTarget(self):
|
|
16 |
target = self.PluginsRootInstance.BeremizRoot.getTargetType()
|
|
17 |
if target.getcontent() is None:
|
|
18 |
target = self.PluginsRootInstance.GetDefaultTarget()
|
|
19 |
return target
|
|
20 |
|
|
21 |
def SetBuildPath(self, buildpath):
|
|
22 |
self.buildpath = buildpath
|
|
23 |
self.exe_path = os.path.join(self.buildpath, "ArmPLC_rom.bin")
|
|
24 |
self.md5_path = os.path.join(self.buildpath, "ArmPLC.md5")
|
|
25 |
|
|
26 |
def GetBinaryCode(self):
|
|
27 |
try:
|
|
28 |
return open(self.exe_path, "rb").read()
|
|
29 |
except Exception, e:
|
|
30 |
return None
|
|
31 |
|
|
32 |
def _GetMD5FileName(self):
|
|
33 |
return os.path.join(self.buildpath, "lastbuildPLC.md5")
|
|
34 |
|
|
35 |
def GetBinaryCodeMD5(self):
|
|
36 |
if self.md5key is not None:
|
|
37 |
return self.md5key
|
|
38 |
else:
|
|
39 |
try:
|
|
40 |
return open(self._GetMD5FileName(), "r").read()
|
|
41 |
except Exception, e:
|
|
42 |
return None
|
425
|
43 |
|
|
44 |
def build(self):
|
|
45 |
srcfiles= []
|
|
46 |
cflags = []
|
|
47 |
for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
|
508
|
48 |
wholesrcdata = ""
|
|
49 |
# Get CFiles list to give it to makefile
|
425
|
50 |
for CFile, CFLAGS in CFilesAndCFLAGS:
|
|
51 |
CFileName = os.path.basename(CFile)
|
508
|
52 |
wholesrcdata += open(CFile, "r").read()
|
425
|
53 |
srcfiles.append(CFileName)
|
|
54 |
if CFLAGS not in cflags:
|
|
55 |
cflags.append(CFLAGS)
|
|
56 |
|
508
|
57 |
self.md5key = hashlib.md5(wholesrcdata).hexdigest()
|
|
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 |
|
|
67 |
target = self.getTarget().getcontent()["value"]
|
|
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
|