Skip to content

BUG: Do not compile NrrdIO's sampleIO.c demo into the library#6655

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-nrrdio-drop-sampleio-demo
Jul 17, 2026
Merged

BUG: Do not compile NrrdIO's sampleIO.c demo into the library#6655
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-nrrdio-drop-sampleio-demo

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Jul 17, 2026

Copy link
Copy Markdown
Member

sampleIO.c is NrrdIO's usage demo and defines main(). Compiling it into libITKNrrdIO makes the library export main(), so downstream executables that link ITK's NrrdIO alongside gtest_main can silently resolve to the demo instead of their own entry point — on ITK 6.0.0 this silently deleted 17 BRAINSTools unit tests from a passing suite (413 → 396). One-line removal; ITK builds no executable from this file.

This is the minimal unblock for ITKv6 downstreams. The durable fix is upstream in NrrdIO (nrrdio_SRCS derived from NrrdIO_Srcs.txt rather than kept as a second hand-written copy), which a future re-vendor picks up.

Symptom — a GTest binary that was silently NrrdIO's demoIO

The executables build and run. They are simply the wrong program:

$ ImageCalculatorUtilsGTest --gtest_list_tests      # ITK 6.0.0, before
(from Teem 2.0.0, early 2026)
demoIO: trouble reading "--gtest_list_tests":
[nrrd] nrrdLoad: fopen("--gtest_list_tests","rb") failed

gtest_discover_tests runs the binary at build time to enumerate tests, receives Teem's banner instead of a test list, parses zero, and registers nothing. ctest then reports 396 tests passed — success, with 17 tests absent rather than failing. Nothing errors or warns at any layer.

$ nm -g libITKNrrdIO-6.0.a | grep ' T _main'
sampleIO.c.o: T _main            # ITK 6.0.0  -- a library defining main()
                                 # ITK 5.4.6  -- no match

ITK 5.4.6 is unaffected because its vendored list predates the change.

Why sampleIO.c is not library code

Three artifacts already vendored beside CMakeLists.txt say so:

file says
0-README.txt:93 "Tiny little command-line program demonstrating the basic NrrdIO API."
sample-GNUmakefile:56,74 ALL = libNrrdIO.a sampleIO — two separate products; sampleIO : sampleIO.c ... -L. -lNrrdIO links against the library
NrrdIO_Srcs.txt 41 Teem-extracted sources; omits sampleIO.c

Only nrrdio_SRCS in CMakeLists.txt listed it — and that is the list the build executes. git grep sampleIO confirms ITK has no add_executable for it; it built as nothing but an archive member.

It entered ITK via 9f0a5d3 (ENH: Update NrrdIO from upstream), inherited from NrrdIO's own hand-maintained list.

Verification (local, BRAINSTools against ITK main)

BRAINSTools 767ba471 built against ITK main, this change the only variable:

check before after
libITKNrrdIO-6.0.a main() definitions 1 0
ImageCalculatorUtilsGTest --gtest_list_tests Teem demoIO banner Running main() from gtest_main.cc, 16 tests
registered tests (ctest -N) 396 413 — matches ITK 5.4.6 exactly

Found by a downstream build testbed that builds ITK consumers against a changed ITK; not visible to ITK's own CI, which does not build BRAINSTools' GTest suite.

sampleIO.c is NrrdIO's usage demo and defines main(). Compiling it into
libITKNrrdIO makes the library export main(), so a downstream executable
linking ITK's NrrdIO alongside another main() (e.g. gtest_main) can
silently resolve to the demo instead of its own entry point.

Observed in BRAINSTools on ITK 6.0.0: GoogleTest executables became
NrrdIO's demoIO, so gtest_discover_tests enumerated zero tests and 17
unit tests silently vanished from a passing suite (413 -> 396). No error
at any layer; ITK 5.4.6 was unaffected because its vendored list predates
the change.

Three artifacts already vendored beside CMakeLists.txt describe this file
as a program rather than library code:

  0-README.txt:93      "Tiny little command-line program demonstrating
                        the basic NrrdIO API."
  sample-GNUmakefile   ALL = libNrrdIO.a sampleIO
                       sampleIO : sampleIO.c ... -L. -lNrrdIO
  NrrdIO_Srcs.txt      41 sources; omits sampleIO.c

Only nrrdio_SRCS listed it. It entered ITK via 9f0a5d3 (ENH: Update
NrrdIO from upstream); nothing in ITK builds it as an executable.

This is the minimal unblock for ITKv6 downstreams. The durable fix is
upstream in NrrdIO, where nrrdio_SRCS is now derived from NrrdIO_Srcs.txt
rather than maintained as a second hand-written copy; a future re-vendor
picks that up and this line does not return.

Verified with BRAINSTools 767ba471 built against ITK main, the only
variable being this change:

  libITKNrrdIO-6.0.a main() definitions   1 -> 0
  ImageCalculatorUtilsGTest               demoIO -> gtest_main, 16 tests
  registered tests                        396 -> 413 (matches ITK 5.4.6)

Tool-Assisted: Claude Code (claude-opus-4-8)
  Role: root-cause analysis, cross-project bisection
  Contribution: traced the zero-test discovery to a main() exported by
    libITKNrrdIO and identified sampleIO.c as its source.
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:ThirdParty Issues affecting the ThirdParty module labels Jul 17, 2026

@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.

This problem is hilarious, despite being real.

@hjmjohnson
hjmjohnson marked this pull request as ready for review July 17, 2026 13:19
@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the NrrdIO demo source from the library build. The main changes are:

  • Drops sampleIO.c from nrrdio_SRCS in Modules/ThirdParty/NrrdIO/src/NrrdIO/CMakeLists.txt.
  • Keeps the vendored CMake library source list aligned with NrrdIO_Srcs.txt.
  • Prevents the sampleIO demo program's main() from being compiled into ITKNrrdIO.

Confidence Score: 5/5

This PR is safe to merge with minimal risk.

The change is a one-line removal from a vendored CMake source list, and the surrounding vendored metadata confirms sampleIO.c is a standalone demo executable source rather than library code.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • The T-Rex reviewer examined the general contract validation proof set, noting the build-time transcripts and tool state, static validation findings about sampleIO.c, and the GNUmake dry-run results showing the library and sampleIO compilation order.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
Modules/ThirdParty/NrrdIO/src/NrrdIO/CMakeLists.txt Removes sampleIO.c from the NrrdIO library source list so the vendored library no longer compiles the demo program's main() into ITKNrrdIO.

Reviews (1): Last reviewed commit: "BUG: Do not compile NrrdIO's sampleIO.c ..." | Re-trigger Greptile

@hjmjohnson
hjmjohnson merged commit 350ae6b into InsightSoftwareConsortium:main Jul 17, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ThirdParty Issues affecting the ThirdParty module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances 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