ENH: Auto-compute ITK_VERSION_TWEAK from git commit date (supersedes #6667)#6676
ENH: Auto-compute ITK_VERSION_TWEAK from git commit date (supersedes #6667)#6676hjmjohnson wants to merge 1 commit into
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
382f3cc to
812b6a7
Compare
blowekamp
left a comment
There was a problem hiding this comment.
This looks like the implementation I was suggesting.
The "ComputeVersionTweak" script should be implemented in CMake and not python to avoid a core ITK build dependency on modern Python.
Also consider how forked versions of ITK can manage this upstream version. It may be beneficial to have a git_archival.txt file take priority over the git repo information. This way a fork could commit the archive file from when the forked occurred? There may be other ways to support upstream versioning and forked versioning, but additional consideration is needed.
Are there other caveats to this approach?
928f59d to
c6b9100
Compare
|
Reworked in c6b9100. Two force-pushes: the first ( Python dependency removed.
Verified resolution order
Full ITK reconfigure: Other caveats — the ones I think are real, stated plainly rather than buried:
Happy to take (1) further — e.g. warning at configure time when the tweak resolves to 0 in something that looks like a git checkout — if you think that is worth the noise. |
|
@blowekamp The fixup based on your request has been completed. |
Caveat #1 would not occur with the earlier suggested DATE method. The date of the last commit should still be in the .git_archive.txt file and the shallow commits. ( Note: when referencing SimpleITK I did not mean to suggest switching to the method of number of commits in SimpelTK). Regarding caveat #2 and #3, the versioning would only be "valid" for release and main branches. I think either method can work, it is just a matter of accepting and mitigating the limitation of such an automatic versioning system. |
Set the fourth (tweak) version component at configure time to the YYYYMMDD date of the most recent commit, instead of a hand-edited date. The computation is pure CMake, so a native build gains no interpreter dependency: `.git_archival.txt` is read first, so an exported tarball -- or a fork that commits a substituted file -- pins the date it declares, and a working tree falls through to `git log`, which succeeds even in a shallow or tagless clone. ITK_VERSION_TWEAK and ITK_VERSION_FULL are exported through ITKConfig.cmake for downstream between-tag gating. The value never reaches itkConfigure.h, so the daily change cannot invalidate ccache. Supersedes the manual-file approach of InsightSoftwareConsortium#6667. Co-Authored-By: Bradley Lowekamp <321061+blowekamp@users.noreply.github.com>
c6b9100 to
2e2c3bd
Compare
|
Thank you — that's the right refinement, and it makes the whole thing better. Swapped to the date method in You were right that caveat #1 was self-inflicted. The resolution order and the fork-pinning behavior you asked for are unchanged; only the value's provenance moved:
Still pure CMake, and the tweak still reaches only Agreed on your framing for the remaining limitations: the version is meaningful on |
Auto-computes
ITK_VERSION_TWEAKat configure time as theYYYYMMDDdate of the most recent commit, replacing the hand-edited date file of #6667. Addresses @blowekamp's request that the tweak be "automatically determined from the last commit on the main branch or similarly" and uses the.git_archival.txt/ setuptools-scm mechanism he pointed to for tarball reliability.The computation is pure CMake — a native build gains no interpreter dependency.
Supersedes #6667. Only one of the two should merge.
How it works
CMake/itkVersionTweak.cmake(included right afterproject()) resolves the date in this order, then setsITK_VERSION_TWEAK/ITK_VERSION_FULL:.git_archival.txtfirst, so an archive — or a fork that commits a substituted file — pins the date it declares. The file is only accepted when itsnode-dateis actually substituted, so this repository's committed$Format:$placeholder is ignored.git log -1 --format=%cd --date=shortin a working tree. Unlikegit describe, this succeeds in a shallow or tagless clone.0when neither is available..gitattributesmarks.git_archival.txtasexport-substand overrides the blanket.git* export-ignoreso the file actually ships ingit archivetarballs.ITK_VERSION_TWEAKandITK_VERSION_FULLare exported throughITKConfig.cmake;ITKConfigVersion.cmakegains a four-componentPACKAGE_VERSIONwhile still matching three-componentfind_package(ITK 6.0.0 EXACT)requests.No manual file edits are ever required — the tweak advances with every commit.
Resolution order, verified
git log→ today's dategit archivetarball, no.gitnode-date→ same date.gitpresent--depth 1 --no-tags)git log→ same dateccache safety
The changing date must never trigger a full rebuild. It reaches only
ITKConfig.cmake(a downstreamfind_packageartifact, not compiled). The compileditkConfigure.hkeepsMAJOR/MINOR/PATCHandITK_VERSION_STRING = "6.0"— verified to contain no tweak — so recomputing the tweak on reconfigure does not invalidate any translation unit.Caveats
Per @blowekamp's review refinement, switching from commit count to commit date removes the shallow-clone caveat entirely — the date survives
--depth 1 --no-tags, and is also carried by.git_archival.txt. What remains:ITK_VERSION_FULLdistinguishes days, not individual commits.mainand release branches only.git archive) tarball with no.gitstill reports 0.Local validation
cmake -Pagainst real and synthesized trees, including a genuinegit clone --depth 1 --no-tags(resolves to the commit date, not 0).ITKConfigVersionmatching with aYYYYMMDDtweak:6.0.0→exact, four-component exact→exact, older date→compatible, newer date→incompatible,5.4.0→compatible.itkConfigure.h.incontains noTWEAK/VERSION_FULL.pre-commit run --all-filesclean.Relative to #6667
#6667 required a maintainer to run
BumpVersionTweak.pyand commitCMake/itkVersion.cmakeon every migration/API change, with aYYYYMMDDvalue. This PR produces the sameYYYYMMDDshape automatically, removing that manual burden entirely, and drops the associated AGENTS.md / git-commits.md policy text. The known tarball failure mode is handled by.git_archival.txtrather than accepted. The unrelated "Python 3.11 wrapped floor" migration note that #6667 accumulated during triage is intentionally left out of this focused PR.