Skip to content

core: embed git SHA as build-time constant#170

Open
webern wants to merge 2 commits into
mainfrom
git-sha-build-const
Open

core: embed git SHA as build-time constant#170
webern wants to merge 2 commits into
mainfrom
git-sha-build-const

Conversation

@webern

@webern webern commented Jun 14, 2026

Copy link
Copy Markdown
Owner

What

Adds mx::core::gitSha -- a C++ const char* const holding the git commit the library was built
from. Unclean trees get a -dirty suffix (any modified tracked file or any untracked file); builds
outside a git checkout (e.g. an exported source archive) get "unknown".

Why this shape

The capture must survive a rebuild that bypasses the Makefile. A configure-time capture
(execute_process / configure_file) freezes the SHA into the generated project and goes stale the
moment HEAD moves, because an IDE rebuild (Xcode/Ninja/Make) never re-runs CMake. So the capture is a
build step baked into the project (cmake/GitSha.cmake, run via cmake -P); it re-checks git every
build. copy_if_different rewrites the generated TU only when the value actually changed, so
incremental builds stay warm and only that one TU recompiles on a new SHA.

Declaration (Version.h) and definition (Version.cpp.in -> generated GitSha.cpp under the build
tree) are split so consumers that include the header never recompile on a SHA change.

Files

  • src/private/mx/core/Version.h -- the gitSha declaration
  • src/private/mx/core/Version.cpp.in -- build-time template
  • cmake/GitSha.cmake -- the capture + copy-if-different script
  • CMakeLists.txt -- mx_git_sha custom target, wires the TU into mx_core

Verification

  • Full mx_core builds and links the symbol under the pinned GCC-14 toolchain
    (_ZN2mx4core6gitShaE in libmx_core.a).
  • Native AppleClang: the generated TU compiles, links, and prints the SHA.
  • Fallbacks confirmed: no git -> unknown; clean tree -> no suffix; untracked file alone ->
    -dirty.
  • copy_if_different leaves the TU mtime unchanged when the SHA is unchanged (no needless rebuild).

@github-actions

Copy link
Copy Markdown

gen-quality gen/

gen-quality: 84.5 / 100   (floor 84.5, +0.0)

  structure     86.5  x0.50   [fn 90.5 / file 82.6]
  cyclomatic    88.4  x0.25
  cognitive     76.6  x0.25

  409 functions across 31 files, 7702 lines (largest file 1044)
  max cc 56  max cognitive 44  max fn loc 152

Worst offenders (top 5 per axis; full lists in score.json):
  cyclomatic gen/xsd/analyze.py:311     report                             56
  cyclomatic gen/plates/build.py:956    _validate_config_against_ir        35
  cyclomatic gen/press/context.py:145   plate_context                      34
  cyclomatic gen/__main__.py:46         _ir                                23
  cyclomatic gen/tests/test_ir.py:102   _check_references                  20
  cognitive  gen/xsd/analyze.py:311     report                             44
  cognitive  gen/ir/resolve.py:119      flat_elements                      40
  cognitive  gen/tests/test_ir.py:102   _check_references                  38
  cognitive  gen/press/context.py:145   plate_context                      37
  cognitive  gen/xsd/analyze.py:207     _sccs                              37
  size       gen/xsd/analyze.py:311     report                             152
  size       gen/press/context.py:145   plate_context                      96
  size       gen/plates/build.py:533    _value_plate                       89
  size       gen/plates/build.py:956    _validate_config_against_ir        89
  size       gen/ir/resolve.py:119      flat_elements                      78

Commit 6a76395dddcec8cf8e76db930bba17a3b28cabb7.

@github-actions

Copy link
Copy Markdown

Coverage report

Core-dev coverage src/private/mx/core/

Metric Coverage Covered / Total
Lines 77.9% 28505 / 36590
Functions 74.4% 6354 / 8542
Branches 50.7% 22645 / 44673

API coverage src/private/mx/{api,impl,utility}/

Metric Coverage Covered / Total
Lines 68.7% 4734 / 6895
Functions 53.5% 1507 / 2816
Branches 40.3% 3851 / 9562

Core HTML report | API HTML report

Commit 6a76395dddcec8cf8e76db930bba17a3b28cabb7.

Base automatically changed from musicxml-4.0 to master June 14, 2026 18:36
webern added 2 commits June 14, 2026 20:40
Add mx::core::gitSha, a C++ const carrying the commit the library was
built from (a -dirty suffix marks an unclean tree, "unknown" marks a
build outside any checkout). Capture runs as a build step via
cmake/GitSha.cmake, not at configure time, so the value stays correct
when an IDE rebuild (Xcode, Ninja, Make) bypasses the Makefile and
never re-runs CMake. copy_if_different rewrites the generated TU only
on change, keeping incremental builds warm.
Every file mx writes now carries
<software>https://github.com/webern/mx version=SHA</software> in its
<encoding>. The logic is a hand-written core wrapper,
serializeWithAttribution, that stamps a copy of the typed model (so the
generated serializer places identification/encoding in their
schema-correct slots) and dedupes by URL prefix: re-writing a file from
any mx version replaces the prior stamp instead of accumulating.

DocumentManager's write path routes through the wrapper; the raw
generated serialize() stays pure, so corert and validate are untouched.
The api read path drops mx's own stamp from EncodingData.software, and
the api-roundtrip harness strips it before comparison. AttributionTest
covers placement, user-software preservation, and cross-version dedup.
@webern webern force-pushed the git-sha-build-const branch from 53cd487 to d7a72b0 Compare June 14, 2026 18:46
@github-actions

Copy link
Copy Markdown

gen-quality gen/

gen-quality: 84.5 / 100   (floor 84.5, +0.0)

  structure     86.5  x0.50   [fn 90.5 / file 82.6]
  cyclomatic    88.4  x0.25
  cognitive     76.6  x0.25

  409 functions across 31 files, 7702 lines (largest file 1044)
  max cc 56  max cognitive 44  max fn loc 152

Worst offenders (top 5 per axis; full lists in score.json):
  cyclomatic gen/xsd/analyze.py:311     report                             56
  cyclomatic gen/plates/build.py:956    _validate_config_against_ir        35
  cyclomatic gen/press/context.py:145   plate_context                      34
  cyclomatic gen/__main__.py:46         _ir                                23
  cyclomatic gen/tests/test_ir.py:102   _check_references                  20
  cognitive  gen/xsd/analyze.py:311     report                             44
  cognitive  gen/ir/resolve.py:119      flat_elements                      40
  cognitive  gen/tests/test_ir.py:102   _check_references                  38
  cognitive  gen/press/context.py:145   plate_context                      37
  cognitive  gen/xsd/analyze.py:207     _sccs                              37
  size       gen/xsd/analyze.py:311     report                             152
  size       gen/press/context.py:145   plate_context                      96
  size       gen/plates/build.py:533    _value_plate                       89
  size       gen/plates/build.py:956    _validate_config_against_ir        89
  size       gen/ir/resolve.py:119      flat_elements                      78

Commit 9b1bedfb62c9c7272702898679378a37be133181.

@github-actions

Copy link
Copy Markdown

Coverage report

Core-dev coverage src/private/mx/core/

Metric Coverage Covered / Total
Lines 77.9% 28539 / 36619
Functions 74.4% 6360 / 8547
Branches 50.7% 22672 / 44725

API coverage src/private/mx/{api,impl,utility}/

Metric Coverage Covered / Total
Lines 68.7% 4735 / 6896
Functions 54.8% 1475 / 2692
Branches 40.3% 3850 / 9558

Core HTML report | API HTML report

Commit 9b1bedfb62c9c7272702898679378a37be133181.

@webern

webern commented Jun 14, 2026

Copy link
Copy Markdown
Owner Author

@copilot rebase

Copilot AI commented Jun 14, 2026

Copy link
Copy Markdown

@copilot rebase

I attempted to rebase onto origin/master, but this environment can only push fast-forward updates via report_progress, so the required non-fast-forward (force) push was rejected. If you want, I can instead do a fast-forwardable merge origin/master update on this branch.

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