Skip to content

fix: resolve --api-headers relative patterns from CWD not include roots#29

Merged
Malcolmnixon merged 5 commits into
mainfrom
fix/api-headers-cwd-relative-patterns
Jun 19, 2026
Merged

fix: resolve --api-headers relative patterns from CWD not include roots#29
Malcolmnixon merged 5 commits into
mainfrom
fix/api-headers-cwd-relative-patterns

Conversation

@Malcolmnixon

Copy link
Copy Markdown
Member

The requirement ApiMarkCpp-CppGenerator-SupportAbsoluteAndRelativeHeader Patterns was authored incorrectly, stating that relative patterns should be expanded against each PublicIncludeRoot. The user guide specifies CWD. This caused a pattern like 'include/**' to be joined onto each --includes path, producing doubled paths that match nothing.

Fixes:

  • Correct the requirement: relative patterns resolve from CWD
  • Fix ExpandExplicitPatterns() to resolve relative patterns from CWD with a single expansion per pattern (not one per include root)
  • Update CppGeneratorOptions.ApiHeaderPatterns XML docs
  • Update design and verification docs for cpp-generator

Add two new tests using non-root-agnostic CWD-relative patterns that would have failed with the old include-root expansion:

  • CwdRelativePattern_OnlyMatchingFilesDocumented
  • CwdRelativeExclusionPattern_ExcludesMatchingFiles

The requirement ApiMarkCpp-CppGenerator-SupportAbsoluteAndRelativeHeader
Patterns was authored incorrectly, stating that relative patterns should
be expanded against each PublicIncludeRoot. The user guide specifies CWD.
This caused a pattern like 'include/**' to be joined onto each --includes
path, producing doubled paths that match nothing.

Fixes:
- Correct the requirement: relative patterns resolve from CWD
- Fix ExpandExplicitPatterns() to resolve relative patterns from CWD
  with a single expansion per pattern (not one per include root)
- Update CppGeneratorOptions.ApiHeaderPatterns XML docs
- Update design and verification docs for cpp-generator

Add two new tests using non-root-agnostic CWD-relative patterns that
would have failed with the old include-root expansion:
- CwdRelativePattern_OnlyMatchingFilesDocumented
- CwdRelativeExclusionPattern_ExcludesMatchingFiles

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 17:15

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.

Pull request overview

This PR corrects C++ --api-headers glob resolution so that relative patterns are interpreted from the current working directory (CWD) (as documented in the user guide), rather than being expanded under each PublicIncludeRoots entry, which previously produced incorrect doubled paths.

Changes:

  • Update CppGenerator pattern handling to resolve relative ApiHeaderPatterns from CWD (single expansion per pattern).
  • Update XML docs for CppGeneratorOptions.ApiHeaderPatterns / PublicIncludeRoots to reflect CWD-based relative pattern semantics.
  • Update requirements, design, verification docs, and add new integration tests covering CWD-relative include/exclude patterns.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Adds new tests for CWD-relative include and exclusion patterns.
src/ApiMark.Cpp/CppGeneratorOptions.cs Updates option XML documentation to state relative patterns resolve from CWD.
src/ApiMark.Cpp/CppGenerator.cs Changes explicit-pattern expansion logic to base relative patterns on CWD.
docs/verification/api-mark-cpp/cpp-generator.md Documents verification scenarios for CWD-relative patterns.
docs/reqstream/api-mark-cpp/cpp-generator.yaml Corrects requirement text and adds tests covering the behavior.
docs/design/api-mark-cpp/cpp-generator.md Updates design description of pattern resolution behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ApiMark.Cpp/CppGenerator.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
- GlobFileCollector now treats absolute paths with no glob metacharacters
  as literal file paths (include if exists) rather than silently skipping
- Updated CppGeneratorTests ApiHeaderPatterns tests to use correct
  absolute/CWD-relative patterns rather than root-agnostic ** prefixes
- Added GlobFileCollector tests for literal path behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Comment thread src/ApiMark.Core/GlobFileCollector.cs
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
…bFileCollector

- Add WorkingDirectory property to CppGeneratorOptions (nullable, defaults
  to Directory.GetCurrentDirectory() at parse time, matching VhdlGeneratorOptions)
- CppGenerator.CollectHeaderFiles uses WorkingDirectory, eliminating the need
  to mutate the process working directory in tests
- Remove ExpandExplicitPatterns — GlobFileCollector already resolves relative
  patterns natively via its workingDirectory parameter
- GlobFileCollector.ParsePattern: replace Path.IsPathRooted with
  Path.IsPathFullyQualified so Windows rooted-but-not-fully-qualified paths
  (e.g. C:foo.h, \foo.h) resolve against workingDirectory rather than entering
  the absolute literal-path fast path incorrectly
- Update GlobFileCollector literal-path doc comment to reflect the corrected
  absolute-path classification
- Remove SetCurrentDirectory/previousCwd/try/finally from all ApiHeaderPatterns
  tests; set WorkingDirectory = FixturePaths.GetFixtureIncludeDir() instead
- Add GlobFileCollectorTests for non-canonical literal path normalization and
  wrong-extension literal exclusion no-op

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread docs/design/api-mark-cpp/cpp-generator.md
Comment thread docs/design/api-mark-cpp/cpp-generator.md Outdated
Comment thread src/ApiMark.Cpp/CppGeneratorOptions.cs Outdated
…c indentation

- docs/design/api-mark-cpp/cpp-generator.md: update Parse() execution steps to
  reflect that patterns are forwarded directly to GlobFileCollector (not via the
  now-deleted ExpandExplicitPatterns); remove the ExpandExplicitPatterns method
  section entirely
- src/ApiMark.Cpp/CppGeneratorOptions.cs: fix accidental extra indentation in
  PublicIncludeRoots XML doc comment

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Comment thread test/ApiMark.Cpp.Tests/CppGeneratorTests.cs Outdated
Set WorkingDirectory to the parent of the fixture include directory so that
relative patterns contain an 'include/' prefix (e.g. include/fixtures/SampleClass.h).
Under the old include-root expansion bug these patterns would have been joined
onto the include root, producing a doubled path (include/include/...) that
matches nothing — making the tests genuine regression detectors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@Malcolmnixon Malcolmnixon merged commit 93b106a into main Jun 19, 2026
16 checks passed
@Malcolmnixon Malcolmnixon deleted the fix/api-headers-cwd-relative-patterns branch June 19, 2026 00:52
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.

2 participants