# HG changeset patch # User Edouard Tisserant # Date 1720085044 -7200 # Node ID 69d161fc2e0812bcc4b92efce4f25c572350d384 # Parent 74035ea6792ca2c6b2e713d63ef75c16df84d62a GCC BUILD: Prevent Memory Error when compiling huge projects. Also deleted dead code. diff -r 74035ea6792c -r 69d161fc2e08 targets/toolchain_gcc.py --- 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 @@ -38,6 +38,18 @@ includes_re = re.compile(r'\s*#include\s*["<]([^">]*)[">].*') +def compute_file_md5(filetocheck): + hasher = hashlib.md5() + with open(filetocheck, 'rb') as afile: + while True: + buf = afile.read(65536) + if len(buf) > 0: + hasher.update(buf) + else: + break + return hasher.hexdigest() + + class toolchain_gcc(object): """ This abstract class contains GCC specific code. @@ -136,9 +148,9 @@ # Get latest computed hash and deps oldhash, deps = self.srcmd5.get(bn, (None, [])) # read source - src = open(os.path.join(self.buildpath, bn)).read() + src = os.path.join(self.buildpath, bn) # compute new hash - newhash = hashlib.md5(src.encode()).hexdigest() + newhash = compute_file_md5(src) # compare match = (oldhash == newhash) if not match: @@ -256,7 +268,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")