Skip to content

Preserve include-only files in FileDeck COPY output - #5333

Open
kriben wants to merge 1 commit into
OPM:masterfrom
CeetronSolutions:filedeck-copy-include-only
Open

Preserve include-only files in FileDeck COPY output#5333
kriben wants to merge 1 commit into
OPM:masterfrom
CeetronSolutions:filedeck-copy-include-only

Conversation

@kriben

@kriben kriben commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@bska
bska requested a lite review from Copilot September 7, 2026 14:35
@bska bska added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Sep 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 COPY dump.
  • Update FileDeck::include_block() to create/include parent wrapper files that contain only INCLUDE statements.
  • Avoid calling include_block() when the output stream was already open (prevents emitting an INCLUDE with 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants