diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 896e50a..037713f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -493,15 +493,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 - # Pinned major version: formatting output can differ across releases. - - name: Check formatting + # Run the TapHouse pre-commit hook — the same pinned clang-format + # developers get from `pre-commit install` (.pre-commit-config.yaml), so + # local and CI share one version AND one file scope (all C/C++ minus + # third_party) by construction. pipx is preinstalled on the runner. + - name: Check formatting (pre-commit) run: | - sudo apt-get update -q && sudo apt-get install -y -q clang-format-18 - clang-format-18 --dry-run --Werror \ - include/srt/*.h include/srt/detail/*.h \ - bench/*.cpp bench/icount/*.cpp bench/compare/*.cpp \ - tools/capi/*.cpp tools/qemu_insn_plugin/*.c \ - tests/*.cpp tests/support/*.h examples/*.cpp platform/*.c + pipx install pre-commit + pre-commit run --all-files --show-diff-on-failure # The book (book/) quotes library code via mdBook anchor includes; this # gate makes a refactor that orphans an excerpt fail CI, the same diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b392057 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,23 @@ +# Canonical Tap House pre-commit config — the single source of truth for the +# Tap family's local formatting hook. Distributed to every Tap repo by +# scripts/sync.sh (alongside .clang-format / .clang-tidy / STYLE.md) and kept +# honest by the drift-check workflow, so every repo runs the SAME hook at the +# SAME pinned clang-format version. +# +# Why the pin matters: an ad-hoc hook using each machine's own clang-format +# would format differently than CI and be worse than none. The `rev` below is +# the Tap-wide clang-format version — bump it HERE, re-sync, and every repo +# (and its CI, which runs `pre-commit run --all-files`) moves together. +# +# Adopt in a consumer repo: +# 1. taphouse/scripts/sync.sh /path/to/your-repo # copies this file in +# 2. cd your-repo && pre-commit install # once per clone +# Thereafter `git commit` formats staged C/C++ before it can be pushed, so the +# clang-format CI gate can never fail on a local commit again. +repos: + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.3 # Tap-wide clang-format version (matches CI) + hooks: + - id: clang-format + types_or: [c, c++] + exclude: '^third_party/' # vendored sources are formatted upstream, never by us diff --git a/scripts/book_figures_trace.cpp b/scripts/book_figures_trace.cpp index a229c55..d4bc3d7 100644 --- a/scripts/book_figures_trace.cpp +++ b/scripts/book_figures_trace.cpp @@ -19,26 +19,25 @@ int main(int argc, char** argv) { if (argc < 5) { - std::fprintf(stderr, "usage: %s pullBlock pushBlock ppm seconds [dropStart dropDur]\n", - argv[0]); + std::fprintf(stderr, "usage: %s pullBlock pushBlock ppm seconds [dropStart dropDur]\n", argv[0]); return 2; } const std::size_t pullBlock = static_cast(std::atol(argv[1])); const std::size_t pushBlock = static_cast(std::atol(argv[2])); - const double ppm = std::atof(argv[3]); - const double seconds = std::atof(argv[4]); - const double dropStart = argc > 5 ? std::atof(argv[5]) : -1.0; - const double dropDur = argc > 6 ? std::atof(argv[6]) : 0.0; + const double ppm = std::atof(argv[3]); + const double seconds = std::atof(argv[4]); + const double dropStart = argc > 5 ? std::atof(argv[5]) : -1.0; + const double dropDur = argc > 6 ? std::atof(argv[6]) : 0.0; srt::Config cfg; cfg.channels = 1; srt::AsyncSampleRateConverter conv(cfg); - const double fsOut = cfg.sampleRateHz; - const double fsIn = fsOut * (1.0 + ppm * 1e-6); // producer's crystal + const double fsOut = cfg.sampleRateHz; + const double fsIn = fsOut * (1.0 + ppm * 1e-6); // producer's crystal std::vector in(pushBlock), out(pullBlock); - double tPush = 0.0, tPull = 0.0, phase = 0.0; + double tPush = 0.0, tPull = 0.0, phase = 0.0; const double dPhase = 2.0 * std::numbers::pi * 997.0 / fsIn; std::puts("t,fill,state,ppm,underruns"); while (tPull < seconds) { @@ -56,8 +55,8 @@ int main(int argc, char** argv) { conv.pull(out.data(), pullBlock); tPull += static_cast(pullBlock) / fsOut; const srt::Status s = conv.status(); - std::printf("%.6f,%.2f,%d,%.2f,%llu\n", tPull, s.fifoFillFrames, static_cast(s.state), - s.ppm, static_cast(s.underruns)); + std::printf("%.6f,%.2f,%d,%.2f,%llu\n", tPull, s.fifoFillFrames, static_cast(s.state), s.ppm, + static_cast(s.underruns)); } return 0; }