-
Notifications
You must be signed in to change notification settings - Fork 1
Add MD5 checksum to debug.c as plc_program_md5 char array #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MD5 checksum to debug.c as plc_program_md5 char array #19
Conversation
- Modified ProjectController.py to pass MD5 to debug.c template - Updated debug.c.j2 template to declare plc_program_md5[] char array - Changed variable name from md5[] to plc_program_md5[] for consistency - MD5 checksum is now embedded in both program.st and debug.c files Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds an MD5 checksum exposure to debug.c via a plc_program_md5 char array while renaming the previously used md5[] symbol, and passes the hash through the template rendering pipeline.
- Injects MD5 into Jinja template (debug.c.j2) and into the dynamically constructed c_debug string.
- Computes MD5 once earlier in Generate_embedded_plc_debugger and passes it into template context.
- Renames exported checksum symbol to plc_program_md5.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
templates/debug.c.j2 | Adds plc_program_md5 declaration into generated C source. |
ProjectController.py | Computes MD5 earlier, passes it to template, and prepends plc_program_md5 again to c_debug output. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
ProjectController.py
Outdated
|
||
# Add MD5 value to debug.cpp file | ||
c_debug = 'char md5[] = "' + MD5 + '";\n' + debug_text | ||
c_debug = 'char plc_program_md5[] = "' + MD5 + '";\n' + debug_text |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable plc_program_md5 is now declared twice: once inside the template (templates/debug.c.j2 line 30) and again here when prepending to c_debug, leading to a duplicate definition (and potential multiple symbol or redefinition error in the embedded block). Remove one of the declarations—either drop the line in the template and keep this prepend (if program.st embedding depends on it), or keep the template line and change this to just c_debug = debug_text.
c_debug = 'char plc_program_md5[] = "' + MD5 + '";\n' + debug_text | |
c_debug = debug_text |
Copilot uses AI. Check for mistakes.
if MD5 is None: | ||
raise ("Error building project: md5 object is null\n") |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hexdigest() call always returns a 32-character string, so MD5 can never be None; additionally raise ("...") is invalid in Python 3 because a string is not an exception instance or class (will raise a TypeError if executed). Remove the unreachable conditional and, if a safeguard is still desired, raise a concrete exception type (e.g. raise RuntimeError("Failed to compute MD5")) after validating inputs earlier.
if MD5 is None: | |
raise ("Error building project: md5 object is null\n") |
Copilot uses AI. Check for mistakes.
def Generate_embedded_plc_debugger(self, st_file): | ||
dvars, externs, enums = self.Generate_plc_debug_cvars() | ||
|
||
MD5 = hashlib.md5(open(st_file, "rb").read()).hexdigest() |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is opened without a context manager, relying on garbage collection to close the descriptor; wrap it in with open(st_file, "rb") as f: to ensure timely resource release: with open(st_file, "rb") as f: MD5 = hashlib.md5(f.read()).hexdigest().
MD5 = hashlib.md5(open(st_file, "rb").read()).hexdigest() | |
with open(st_file, "rb") as f: | |
MD5 = hashlib.md5(f.read()).hexdigest() |
Copilot uses AI. Check for mistakes.
Add MD5 checksum to debug.c as plc_program_md5 char array
Summary
This PR modifies the debug code generation to embed the MD5 checksum in the debug.c file as a
char plc_program_md5[]
array, in addition to the existing embedding in program.st. The MD5 is calculated from the ST file content when--generate-debug
is called.Changes:
ProjectController.py
to pass the MD5 hash to the debug.c templatedebug.c.j2
template to declarechar plc_program_md5[] = "{{ debug.md5 }}";
md5[]
toplc_program_md5[]
in both debug.c and the program.st comment wrapperReview & Testing Checklist for Human
md5[]
variable name - the rename could break thingsRecommended Test Plan
Notes