Preserve include-only files in FileDeck COPY output - #5333
Open
kriben wants to merge 1 commit into
Open
Conversation
An include file containing only INCLUDE statements contributes no keywords to the parsed deck, so it never becomes a FileDeck block. When dumping with OutputMode::COPY, include_block skipped past such files while walking up the include tree, writing the INCLUDE statements for all leaf files directly into the main .DATA file and flattening the include hierarchy. Create the include-only parent file in the output directory when it is first needed, write the child's INCLUDE statement into it, and continue up the tree so the parent itself is included from its own parent. Also skip include_block when the block's output stream was already open, since such a file has already been included from its parent once; previously this wrote an INCLUDE with an empty file name when a file was split into multiple blocks by a nested include.
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Preserves the include hierarchy in FileDeck::OutputMode::COPY by recreating “include-only” wrapper files in the output and ensuring nested includes are written into the correct parent wrapper instead of flattening into the root deck.
Changes:
- Add a regression test that exercises include-only wrapper files and validates reload equivalence after
COPYdump. - Update
FileDeck::include_block()to create/include parent wrapper files that contain onlyINCLUDEstatements. - Avoid calling
include_block()when the output stream was already open (prevents emitting anINCLUDEwith an empty name).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/parser/ScheduleRestartTests.cpp | Adds regression test and file I/O helpers validating wrapper includes are preserved during COPY dump. |
| opm/input/eclipse/Deck/FileDeck.cpp | Implements wrapper-file recreation and guards repeated include emission when output is already open. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+485
to
+486
| auto rel_path = fs::proximate(parent, this->input_directory); | ||
| auto parent_output = fs::path(output_dir) / rel_path; |
Comment on lines
+485
to
+494
| auto rel_path = fs::proximate(parent, this->input_directory); | ||
| auto parent_output = fs::path(output_dir) / rel_path; | ||
| touch_file(parent_output); | ||
| parent_output = fs::canonical(parent_output); | ||
|
|
||
| auto& parent_stream = context.open_file(parent, parent_output); | ||
| INCLUDE(parent_stream, fs::proximate(current_output, output_dir).generic_string()); | ||
|
|
||
| current_file = parent; | ||
| current_output = parent_output.generic_string(); |
| fs::create_directories(dir); | ||
| } | ||
|
|
||
| std::ofstream {file} << contents; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An include file containing only INCLUDE statements contributes no keywords to the parsed deck, so it never becomes a FileDeck block. When dumping with OutputMode::COPY, include_block skipped past such files while walking up the include tree, writing the INCLUDE statements for all leaf files directly into the main .DATA file and flattening the include hierarchy.
Create the include-only parent file in the output directory when it is first needed, write the child's INCLUDE statement into it, and continue up the tree so the parent itself is included from its own parent. Also skip include_block when the block's output stream was already open, since such a file has already been included from its parent once; previously this wrote an INCLUDE with an empty file name when a file was split into multiple blocks by a nested include.