3 import hashlib, shutil |
3 import hashlib, shutil |
4 from toolchain_gcc import toolchain_gcc |
4 from toolchain_gcc import toolchain_gcc |
5 |
5 |
6 includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') |
6 includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') |
7 |
7 |
8 class toolchain_makefile(toolchain_gcc): |
8 class toolchain_makefile(): |
9 """ |
9 def __init__(self, PluginsRootInstance): |
10 This abstract class contains GCC specific code. |
10 self.PluginsRootInstance = PluginsRootInstance |
11 It cannot be used as this and should be inherited in a target specific |
11 self.md5key = None |
12 class such as target_linux or target_win32 |
12 self.buildpath = None |
13 """ |
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 |
14 |
43 |
15 def build(self): |
44 def build(self): |
16 srcfiles= [] |
45 srcfiles= [] |
17 cflags = [] |
46 cflags = [] |
18 for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: |
47 for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: |
19 # Get CFiles list to give it to makefile |
48 wholesrcdata = "" |
|
49 # Get CFiles list to give it to makefile |
20 for CFile, CFLAGS in CFilesAndCFLAGS: |
50 for CFile, CFLAGS in CFilesAndCFLAGS: |
21 CFileName = os.path.basename(CFile) |
51 CFileName = os.path.basename(CFile) |
|
52 wholesrcdata += open(CFile, "r").read() |
22 srcfiles.append(CFileName) |
53 srcfiles.append(CFileName) |
23 if CFLAGS not in cflags: |
54 if CFLAGS not in cflags: |
24 cflags.append(CFLAGS) |
55 cflags.append(CFLAGS) |
25 |
56 |
|
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() |
26 beremizcommand = {"src": ' '.join(srcfiles), |
62 beremizcommand = {"src": ' '.join(srcfiles), |
27 "cflags": ' '.join(cflags) |
63 "cflags": ' '.join(cflags), |
|
64 "md5": self.md5key |
28 } |
65 } |
29 |
66 |
30 target = self.getTarget().getcontent()["value"] |
67 target = self.getTarget().getcontent()["value"] |
31 command = target.getCommand().split(' ') +\ |
68 command = target.getCommand().split(' ') +\ |
32 [target.getBuildPath()] +\ |
69 [target.getBuildPath()] +\ |