--- a/targets/toolchain_gcc.py Wed Jul 03 11:44:01 2024 +0200
+++ b/targets/toolchain_gcc.py Thu Jul 04 11:24:04 2024 +0200
@@ -36,6 +36,18 @@
includes_re = re.compile(r'\s*#include\s*["<]([^">]*)[">].*')
+def compute_file_md5(filetocheck): + with open(filetocheck, 'rb') as afile: + buf = afile.read(65536) + return hasher.hexdigest() class toolchain_gcc(object):
This abstract class contains GCC specific code.
@@ -103,6 +115,7 @@
def append_cfile_deps(self, src, deps):
+ src = open(os.path.join(self.buildpath, src), "r").read() for l in src.splitlines():
res = includes_re.match(l)
@@ -110,23 +123,13 @@
if os.path.exists(os.path.join(self.buildpath, depfn)):
- def concat_deps(self, bn):
- src = open(os.path.join(self.buildpath, bn), "r").read()
- # update direct dependencies
- self.append_cfile_deps(src, deps)
- # TODO detect cicular deps.
- return reduce(operator.concat, map(self.concat_deps, deps), src)
def check_and_update_hash_and_deps(self, bn):
# Get latest computed hash and deps
oldhash, deps = self.srcmd5.get(bn, (None, []))
- src = open(os.path.join(self.buildpath, bn)).read()
+ src = os.path.join(self.buildpath, bn) - newhash = hashlib.md5(src).hexdigest()
+ newhash = compute_file_md5(src) match = (oldhash == newhash)
@@ -140,15 +143,6 @@
# TODO detect cicular deps.
return reduce(operator.and_, map(self.check_and_update_hash_and_deps, deps), match)
- def calc_source_md5(self):
- for _Location, CFilesAndCFLAGS, _DoCalls in self.CTRInstance.LocationCFilesAndCFLAGS:
- # Get CFiles list to give it to makefile
- for CFile, _CFLAGS in CFilesAndCFLAGS:
- CFileName = os.path.basename(CFile)
- wholesrcdata += self.concat_deps(CFileName)
- return hashlib.md5(wholesrcdata).hexdigest()
# Retrieve compiler and linker
self.compiler = self.getCompiler()
@@ -225,7 +219,7 @@
self.CTRInstance.logger.write(" [pass] " + ' '.join(obns)+" -> " + self.bin + "\n")
# Calculate md5 key and get data for the new created PLC
- self.md5key = hashlib.md5(open(self.bin_path, "rb").read()).hexdigest()
+ self.md5key = compute_file_md5(self.bin_path) # Store new PLC filename based on md5 key
f = open(self._GetMD5FileName(), "w")