Skip to content

COMP: Skip dot-directories when scanning for ITK modules - #6709

Open
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-module-scan-skip-dot-dirs
Open

COMP: Skip dot-directories when scanning for ITK modules#6709
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-module-scan-skip-dot-dirs

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Jul 26, 2026

Copy link
Copy Markdown
Member

itk_module_load_dag() uses GLOB_RECURSE, which matches itk-module.cmake at any depth. Any nested source tree under the ITK checkout is therefore absorbed as a set of duplicate modules and built as if it were part of the project.

Nesting a second tree inside a project is a widespread convention, and it almost always lives under a dot-directory. On one affected workstation this produced 984 discovered modules where 204 exist, and the duplicates broke the build outright.

Why dot-directories, specifically

Dot-directories are the near-universal convention for content that is not project source: version-control internals, tool and editor state, language environments, and caches. A checkout of ITK — or of anything containing */*/*/itk-module.cmake — commonly ends up inside one:

Paradigm Typical location
Secondary git worktree trees .worktrees/<branch>/, or a tool-managed directory
Editor / IDE / agent state .vscode/, .idea/, .vs/, and similar
Language & package environments .pixi/, .venv/, .tox/, .conda/
Build and download caches .cache/, .ExternalData/

This is not hypothetical for ITK. ITK's own documented build tool creates .pixi/ inside the source tree — 3.3 GB on the machine where this was found — and .gitignore already declares .pixi and .idea as non-source. The module scan simply does not honor the same convention that the rest of the project already assumes.

The failure is also easy to misread, because the duplicates are built against the outer tree's configuration. A nested checkout on an older branch fails in ways that look like a defect in the tree you are actually working on:

FAILED: .<dot-dir>/<nested-tree>/Modules/Numerics/FEM/src/CMakeFiles/ITKFEM.dir/....o
vnl/algo/vnl_svd.h:13:6: error: #error "vnl/algo/vnl_svd.h is deprecated; migrate to itk::Math::SVD"

The path is the giveaway, but it is easy to miss in a full log, and ninja stops there — a plain ninja in that tree could not complete.

Fix
list(FILTER meta EXCLUDE REGEX "(^|/)\\.")

Scoped deliberately narrowly:

  • Matches a dot only at the start of a path component, so directory names that merely contain a dot (ITK.Something) are unaffected.
  • The glob is RELATIVE "${ITK_SOURCE_DIR}", so an ITK checkout that itself lives under a dot-path (/home/user/.cache/src/ITK) is unaffected — the absolute prefix is stripped before matching.
  • ITK ships no itk-module.cmake under any dot-directory, so nothing in-project is excluded.
Validation

Verified on a tree containing four nested checkouts:

Check Result
Modules discovered before 984
Excluded by the filter 780
Excluded that were not a nested checkout 0 (no false positives)
Modules discovered after 204
Modules/Remote/* retained 10 of 10

Behavioral check with ITK_FUTURE_LEGACY_REMOVE=ON, ITK_LEGACY_REMOVE=ON, Module_ITKReview=ON, 10 remote modules enabled:

  • before: 314 nested targets, ninja -k 0 failed
  • after: 0 nested targets, ninja -k 0 exits 0 with zero failures

Had the filter dropped a real module, that build would have failed to link.

Remote modules are unaffected

In-tree: remotes are always fetched to ${ITK_SOURCE_DIR}/Modules/Remote/${_name} (CMake/ITKModuleRemote.cmake), a path the regex cannot match. All 10 enabled remotes are retained above.

Standalone: a remote module built on its own against an installed ITK never reaches this code. ITKModuleEnablement is included only from ITK's top-level CMakeLists.txt and is not installed for downstream consumers, so a module using find_package(ITK REQUIRED) + itk_module_impl() never calls itk_module_load_dag().

@github-actions github-actions Bot added type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots labels Jul 26, 2026
GLOB_RECURSE matches itk-module.cmake at any depth, so a nested source
tree under a dot-directory is absorbed as a set of duplicate modules.
Dot-directories hold tool state by convention -- git worktrees, editor
and agent directories, and environment or cache trees such as the
in-source .pixi directory created by ITK's own build tooling -- and
.gitignore already declares several of them non-source.

One affected tree reported 984 modules where 204 exist, and failed
building the stale duplicates.
@hjmjohnson
hjmjohnson force-pushed the comp-module-scan-skip-dot-dirs branch from 1be0e9a to c20bdff Compare July 26, 2026 15:52
@hjmjohnson
hjmjohnson marked this pull request as ready for review July 26, 2026 16:03
@greptile-apps

greptile-apps Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR narrows ITK module discovery to ignore module metadata beneath dot-prefixed directories.

  • Filters relative itk-module.cmake paths before constructing the module dependency graph.
  • Preserves ordinary in-tree and fetched remote modules while avoiding nested tool-state checkouts.

Confidence Score: 5/5

The PR appears safe to merge with no actionable defects identified.

The filter operates on paths relative to the source root, excludes only dot-prefixed path components, and leaves the repository’s standard and fetched remote module layouts discoverable.

T-Rex T-Rex Logs

What T-Rex did

  • The initial configure attempt failed with exit code 1 because Module_ITKTrexDotModuleFixture:BOOL=OFF appeared in CMakeCache.txt.
  • After adjustments, the configure and generate steps completed with exit code 0, and an explicit assertion confirmed Module_ITKTrexDotModuleFixture was absent.
  • A positive-control nested fixture produced Module_ITKTrexNormalModuleFixture:BOOL=OFF.
  • Remote retention validation confirmed that all 19 remote .remote.cmake declarations had corresponding _REMOTE_COMPLIANCE_LEVEL cache entries.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
CMake/ITKModuleEnablement.cmake Adds a correctly scoped path-component filter to module discovery; no supported module layout or remote-module destination is excluded.

Reviews (1): Last reviewed commit: "COMP: Skip dot-directories when scanning..." | Re-trigger Greptile

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, it would be good if someone else reviewed too.

@hjmjohnson
hjmjohnson requested a review from thewtex July 26, 2026 19:16
@hjmjohnson hjmjohnson self-assigned this Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants