Skip to content

[FIX] Preserve git commit hash in Homebrew and tarball-based builds#2266

Merged
cfsmp3 merged 1 commit intoCCExtractor:masterfrom
x15sr71:fix/build-provenance-tarball
Apr 18, 2026
Merged

[FIX] Preserve git commit hash in Homebrew and tarball-based builds#2266
cfsmp3 merged 1 commit intoCCExtractor:masterfrom
x15sr71:fix/build-provenance-tarball

Conversation

@x15sr71
Copy link
Copy Markdown
Contributor

@x15sr71 x15sr71 commented Apr 14, 2026

In raising this pull request, I confirm the following (please check boxes):

Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Repro instructions:

Homebrew

brew install ccextractor
ccextractor --version
# Git commit: Unknown  ← every macOS user sees this

Problem

Tarball-based builds (Homebrew, or any manual build from the released source tarball) have no .git directory at build time. The existing logic in pre-build.sh calls git rev-parse HEAD unconditionally — when .git is absent, this fails silently:

$ brew install ccextractor && ccextractor --version
Version: 0.96.5
Git commit: Unknown  ← broken

Every user installing via Homebrew or building from the released source tarball loses build provenance entirely.

Fix

Add explicit override path at the metadata generation point (pre-build.sh), not post-build output patching.

  • mac/pre-build.sh, linux/pre-build.sh
    Check GIT_COMMIT_HASH_OVERRIDE env var first. If set, use it directly. Otherwise fall through to existing git logic unchanged.

  • mac/build.command, linux/build
    New -commit-hash <value> argument exports GIT_COMMIT_HASH_OVERRIDE for pre-build.sh. Matches existing -system-libs pattern.

  • src/CMakeLists.txt
    GIT_COMMIT_HASH CMake CACHE STRING for -DGIT_COMMIT_HASH=<value>. Falls through to git when empty. Placed after BASE_PROJ_DIR definition.

  • Source builds unaffected — override only taken when explicitly provided.

Testing

1. Normal source build (unchanged):

cd build && cmake ../src && ./ccextractor --version
Git commit: 6f0b781491fa7d6e646ce9a4c714bd5f1f7100c4  → real SHA

2. Tarball simulation (no .git, no override):

cd mac && mv ../.git ../.git.bak && bash pre-build.sh
Git command not present, trying folder approach
Commit: Unknown  → correct fallback

3. Override injection:

cd mac && GIT_COMMIT_HASH_OVERRIDE="v0.96.6" bash pre-build.sh
# Using injected commit hash: v0.96.6
# Commit: v0.96.6  → override works

4. Full Homebrew end-to-end (production path):

## Local tap with modified formula calling:
./build.command -system-libs -commit-hash v0.96.6
brew install local/test/ccextractor
ccextractor --version
Version: 0.96.5
Git commit: v0.96.6  → FIXED

Next step: Once this merges and a new release is cut, a Homebrew-core PR will add "-commit-hash", "v#{version}" to the formula's install block — at which point every future Homebrew bottle will carry the correct build provenance automatically.

@ccextractor-bot
Copy link
Copy Markdown
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit ad4886e...:
Report Name Tests Passed
Broken 9/13
CEA-708 1/14
DVB 2/7
DVD 3/3
DVR-MS 2/2
General 22/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 77/86
Teletext 20/21
WTV 13/13
XDS 31/34

Your PR breaks these cases:

  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 8e8229b88b...
  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2...
  • ccextractor --autoprogram --out=ttxt --latin1 99e5eaafdc...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 7aad20907e...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65...
  • ccextractor --autoprogram --out=ttxt --latin1 01509e4d27...
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b...
  • ccextractor --out=spupng c83f765c66...
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --autoprogram --out=ttxt --xds --latin1 --ucla 85058ad37e...
  • ccextractor --autoprogram --out=srt --latin1 --ucla b22260d065...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 7f41299cc7...

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=ttxt --latin1 132d7df7e9..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 b22260d065..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

@ccextractor-bot
Copy link
Copy Markdown
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit ad4886e...:
Report Name Tests Passed
Broken 9/13
CEA-708 1/14
DVB 3/7
DVD 3/3
DVR-MS 2/2
General 22/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 81/86
Teletext 20/21
WTV 13/13
XDS 31/34

Your PR breaks these cases:

  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 8e8229b88b...
  • ccextractor --autoprogram --out=ttxt --latin1 132d7df7e9...
  • ccextractor --autoprogram --out=ttxt --latin1 99e5eaafdc...
  • ccextractor --autoprogram --out=srt --latin1 b22260d065...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 7aad20907e...
  • ccextractor --autoprogram --out=ttxt --latin1 01509e4d27...
  • ccextractor --autoprogram --out=ttxt --xds --latin1 --ucla 85058ad37e...
  • ccextractor --autoprogram --out=srt --latin1 --ucla b22260d065...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 7f41299cc7...

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --out=spupng c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

@cfsmp3 cfsmp3 merged commit a3ac701 into CCExtractor:master Apr 18, 2026
20 of 22 checks passed
@x15sr71 x15sr71 deleted the fix/build-provenance-tarball branch April 18, 2026 18:27
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.

3 participants