Skip to content

Conversation

devin-ai-integration[bot]
Copy link

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:

  • Modified ProjectController.py to pass the MD5 hash to the debug.c template
  • Updated debug.c.j2 template to declare char plc_program_md5[] = "{{ debug.md5 }}";
  • Renamed the variable from md5[] to plc_program_md5[] in both debug.c and the program.st comment wrapper

Review & Testing Checklist for Human

  • Verify debug.c contains plc_program_md5 variable: Generate debug.c from a test project and confirm the variable is present with correct MD5 value
  • Check MD5 consistency: Ensure the MD5 in debug.c matches the MD5 embedded in program.st comments
  • Test variable name change impact: Search codebase/downstream projects for references to the old md5[] variable name - the rename could break things
  • End-to-end workflow test: Run the full pipeline (XML → ST → debug generation) to verify everything works

Recommended Test Plan

# Generate ST from XML
python xml2st.py --generate-st path/to/plc.xml

# Generate debug files
python xml2st.py --generate-debug program.st VARIABLES.csv

# Verify debug.c contains: char plc_program_md5[] = "...";
grep "plc_program_md5" debug.c

# Verify program.st contains the same MD5 in comments
grep "plc_program_md5" program.st

Notes

- 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>
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link

coderabbitai bot commented Oct 17, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit 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 @coderabbitai help to get the list of available commands and usage tips.

@thiagoralves thiagoralves requested a review from Copilot October 17, 2025 02:15
Copy link

@Copilot Copilot AI left a 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.


# 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
Copy link

Copilot AI Oct 17, 2025

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.

Suggested change
c_debug = 'char plc_program_md5[] = "' + MD5 + '";\n' + debug_text
c_debug = debug_text

Copilot uses AI. Check for mistakes.

Comment on lines +166 to +167
if MD5 is None:
raise ("Error building project: md5 object is null\n")
Copy link

Copilot AI Oct 17, 2025

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.

Suggested change
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()
Copy link

Copilot AI Oct 17, 2025

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().

Suggested change
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.

@thiagoralves thiagoralves merged commit 408f9ef into development Oct 17, 2025
7 checks passed
@thiagoralves thiagoralves deleted the devin/1760666774-add-md5-to-debug-c branch October 17, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant