Skip to content

ci: Ratchet platform conditionals in shared C/C++ files (#847) - #900

Merged
zackees merged 4 commits into
masterfrom
infra/platform-ifdef-ratchet
Oct 15, 2026
Merged

zackees merged 4 commits into
masterfrom
infra/platform-ifdef-ratchet

Conversation

@zackees

@zackees zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member

Fixes #848. Refs #847.

Adds ci/platform_ifdef_ratchet.py, ci/test_platform_ifdef_ratchet.py and ci/platform-ifdef-baseline.json (path to count), run by ./lint (lane lint, ci/local_gate.py).

  • Counts #if/#ifdef/#ifndef/#elif lines naming a platform macro (bare, defined(X), defined X, !defined(X), plain WIN32, TARGET_OS_*, ...) in tracked C/C++/ObjC under libobs/, frontend/, shared/, plugins/.
  • Skips files whose path marks a platform (path token as in ci_scope: windows, win, mac, osx, cocoa, apple, darwin, nix, linux, x11, wayland, pipewire, pulse, alsa, v4l2, freebsd, posix, ...; .m/.mm; platform-*), submodules, deps/, librtmp and rnnoise (vendored).
  • Fails when a file exceeds its baseline or a new file has any; prints the offending lines and says to move the code behind the facade. Decreases pass with a hint; --update rewrites the baseline.
  • Baseline today: 163 files, 569 conditionals (frontend 265, libobs 94, shared 51, plugins 159 after excluding vendored librtmp/rnnoise).

RED: 3bd61d3 (stub; 35 failures, 1 error) and 19ec8ed (bare/defined/WIN32 forms, 1 failure). GREEN: c94ec66 and 15494dd (15 tests pass).

Local gate: ./lint ok; ci-lint local-gate run passed (lint, rust-test, cross, tier2-linux), stamped 15494dd. No submodule pointer or workflow change.

Local-Gate: v1 tree=c67861cf88c28b80a72cfb326b94ac5808fb9de1 secs=1580 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1792100122,"gate":"rust/all/fmt","host":"linux-x86_64","key":"2e691e9eebf92e24923fc4933b2dbbbb2ba6f940e0708718eda59add3a11dca3","lane":"lint","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":44,"stamp":"8413a96e3dc68106eadcfd099dd54946","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"2e691e9eebf92e24923fc4933b2dbbbb2ba6f940e0708718eda59add3a11dca3","lane":"lint","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":44,"stamp":"ae74fb9aa33b45d6d6ccdcd729183f57","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"0d384545b3edfe38dcd7cef83a4c6b92eb6f5bb82ae952c711ef134c49b31d6a","lane":"rust-test","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":99,"stamp":"07eb723d00e456da039ce4f0010e3aac","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"2070e0e293d2964365b2f7742a070b8c79cff7b3c054efc9669f3e2f1c5197b3","lane":"cross","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":108,"stamp":"e8e3a5830955b73c46be917a4348c949","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"2070e0e293d2964365b2f7742a070b8c79cff7b3c054efc9669f3e2f1c5197b3","lane":"cross","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":108,"stamp":"28727c8af858e2db442caf642201cc48","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"2070e0e293d2964365b2f7742a070b8c79cff7b3c054efc9669f3e2f1c5197b3","lane":"cross","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":108,"stamp":"b4cb65ec34512aec8e714206066962c1","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"2070e0e293d2964365b2f7742a070b8c79cff7b3c054efc9669f3e2f1c5197b3","lane":"cross","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":108,"stamp":"7b3c080810d9b8f80a43024b6c495f6b","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"2070e0e293d2964365b2f7742a070b8c79cff7b3c054efc9669f3e2f1c5197b3","lane":"cross","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":108,"stamp":"f1c8f8a1d592b7994094bf1ff6f3813e","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"2070e0e293d2964365b2f7742a070b8c79cff7b3c054efc9669f3e2f1c5197b3","lane":"cross","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":108,"stamp":"fc67f8f0b99cc21483f4ac6f6544332b","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
Ci-Attestation: {"at":1792100122,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"0c19ede87a0bba12c02d4d4a73504326f4b52ebcfec57fb2106d9459e7586736","lane":"tier2-linux","parents":["19ec8edc121b9196bf29410bef909fa247aeed32"],"secs":1329,"stamp":"8811bc682786f754265a140cf5718516","tree":"c67861cf88c28b80a72cfb326b94ac5808fb9de1","v":1,"via":"run"}
@zackees

zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

From #897 / #911: please import platforms() from ci/platform_paths.py (added in #911) for the allowed-path check, instead of a separate PLATFORM_TOKENS, so the lint and ci_scope.py agree on what a platform file is. One concrete difference: maintainer policy is that POSIX files (*-posix.c, unix/, libobs/util/platform-nix.c) belong to Linux and macOS. The goal is that core files have no platform defines at all, with the baseline grandfathering only today's offenders.

Merged via the queue into master with commit 1dae626 Oct 15, 2026
21 checks passed
@zackees

zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Maintainer policy (#897), restated for this lint:

  • #ifdef scanning is for enforcement only. This lint scans for platform defines to keep them out of core code. CI scoping (ci_scope.py, ci: Scope platform jobs by path alone; POSIX reaches Linux and macOS #911) is path-only and never scans.
  • Platform defines are allowed only in platform files and platform subdirectories, meaning the paths for which ci/platform_paths.platforms(path) (from ci: Scope platform jobs by path alone; POSIX reaches Linux and macOS #911) is not None. Please import it rather than keeping a separate token list, so the lint and the scoper can't drift apart.
  • Every other file is core. Its baseline count is the grandfathered maximum and may only go down. A core file not in the baseline may have zero platform conditionals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ci: ratchet lint for platform conditionals in shared C/C++ (#847 step 1)

1 participant