--- a/ProjectController.py Fri Oct 29 10:27:31 2021 +0200
+++ b/ProjectController.py Fri Oct 29 11:49:22 2021 +0200
@@ -36,6 +36,7 @@
from datetime import datetime
from weakref import WeakKeyDictionary
from functools import reduce
@@ -277,6 +278,9 @@
self.debug_status = PlcStatus.Stopped
+ self.IECcodeDigest = None + self.LastBuiltIECcodeDigest = None @@ -779,21 +783,27 @@
_("Error in ST/IL/SFC code generator :\n%s\n") % errors[0])
- plc_file = open(self._getIECcodepath(), "w")
# Add ST Library from confnodes
- plc_file.write(self.GetLibrariesSTCode())
- if os.path.isfile(self._getIECrawcodepath()):
- plc_file.write(open(self._getIECrawcodepath(), "r").read())
- plc_file = open(self._getIECcodepath(), "r")
- for dummy in plc_file.readlines():
- self.ProgramOffset += 1
- plc_file = open(self._getIECcodepath(), "a")
- plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
+ IECCodeContent = self.GetLibrariesSTCode() + IECrawcodepath = self._getIECrawcodepath() + if os.path.isfile(IECrawcodepath): + IECCodeContent += open(IECrawcodepath, "r").read() + "\n" + # Compute offset before ST resulting of transformation from user POUs + self.ProgramOffset = IECCodeContent.count("\n") + IECCodeContent += open(self._getIECgeneratedcodepath(), "r").read() + with open(self._getIECcodepath(), "w") as plc_file: + plc_file.write(IECCodeContent) + hasher.update(IECCodeContent) + self.IECcodeDigest = hasher.hexdigest() def _Compile_ST_to_SoftPLC(self):
@@ -802,6 +812,10 @@
self.logger.write_error(_("matiec installation is not found\n"))
+ if self.LastBuiltIECcodeDigest == self.IECcodeDigest: + self.logger.write(_("IEC program did no change, not re-compiling into C code.\n")) self.logger.write(_("Compiling IEC Program into C code...\n"))
buildpath = self._getBuildPath()
buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\"" % (
@@ -889,6 +903,9 @@
self.PLCGeneratedCFiles = C_files
self.plcCFLAGS = '"-I%s" -Wno-unused-function' % self.iec2c_cfg.getLibCPath()
+ self.LastBuiltIECcodeDigest = self.IECcodeDigest