Skip to content

ci: Scope macOS and Windows jobs by hunk content (Refs #698, #700) - #898

Merged
zackees merged 2 commits into
masterfrom
ci/698-platform-scope
Oct 15, 2026
Merged

zackees merged 2 commits into
masterfrom
ci/698-platform-scope

Conversation

@zackees

@zackees zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member

Refs #698, #700. Wine for Windows is not used (#696).

What changes

ci/ci_scope.py now also reads git diff -U0 (new ci/scope_content.py):

  1. tests.d: a test/cmocka/tests.d/*.cmake registration reaches macOS/Windows only if it mentions that platform (OS_MACOS, APPLE, WIN32, MSVC, PLATFORM_ID, .m/.mm) and reaches both if it adds a .cpp/.hpp test (ci: A new C++ cmocka test skips the macOS and Windows Tier 2 jobs that compile it #610 kept). Plain .c tests stay Linux-only. test/cmocka/CMakeLists.txt and .cpp/.hpp tests stay shared.
  2. Rust: rust/*/src/platform/{macos,windows,unix}* already mapped exactly via the path tokens; now pinned by tests. platform/mod.rs stays shared.
  3. Hunk content: in shared C/C++/ObjC/CMake files a hunk that names a platform macro, or sits in an open #if/if() block selecting a platform (negations and #else branches included), turns that platform on. Undecidable means off (Linux covers it, release gate covers the rest).

Unchanged: ci-full label, pushes, merge queue, release gate, and the shared prefixes (.github/, cmake/common/, cmake/finders/, libobs/cmake/, root CMake files). I did not narrow those: every platform consumes them and I found no testable Linux-only subset. Docs: docs/ci-tooling.md and the ci_scope.py docstring.

RED / GREEN

  • RED commit (tests only): 14 of 16 tests error against the old scope() (no hunk input); log at obs-studio-extern/ciscope-red.log.
  • GREEN: cd ci && uv run python -m unittest test_ci_scope.py -> Ran 16 tests ... OK. ./lint ok. ci-lint local-gate run passed and stamped (the first run hit test_v4l2_busy_signal failing in Tier 2, unrelated to this Python-only change; it passed on re-run).

Before / after: last 40 first-parent commits on master (1627828 and back)

before after
macOS jobs run 29 / 40 15 / 40
Windows jobs run 29 / 40 18 / 40

Remaining runs are mostly real: .github/, libobs/CMakeLists.txt, .cpp cmocka tests (frontend), or hunks naming _WIN32 and similar.

…efs #698, #700)

Local-Gate: v1 tree=1b5cdebd6a812e60effb482d9b884f8e4e3e0276 secs=1315 lanes=lint:reused@9033feaf1063,rust-test:reused@ee29c75b7e89,cross:reused@482ec24d598e,tier2-linux:run
Ci-Attestation: {"at":1792098828,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9033feaf106317cc0d081be1860f2e01bae0a703638a87a59532d0b3c96561a4","lane":"lint","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"a155fd03fa3b0e3b5bb7ac88881ee96b","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9033feaf106317cc0d081be1860f2e01bae0a703638a87a59532d0b3c96561a4","lane":"lint","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"817b747dc45ad33f80e660a15fbf1fc3","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"ee29c75b7e89d02ff106fb39322b380c76147e8cbc736858fc9295a4dc68d3c1","lane":"rust-test","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"597a34920978ceee70d1249eeb8b47e7","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"482ec24d598e324e115a31ff0350174380cd4ad3ce772ac39856a8142f74f2c2","lane":"cross","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"493fb3ce4e65bc97cb8386afd100b0a2","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"482ec24d598e324e115a31ff0350174380cd4ad3ce772ac39856a8142f74f2c2","lane":"cross","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"7c64c3c9cfdb1984f34e778e407302e9","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"482ec24d598e324e115a31ff0350174380cd4ad3ce772ac39856a8142f74f2c2","lane":"cross","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"6155e8870a2a09cabfc149cf29b00d43","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"482ec24d598e324e115a31ff0350174380cd4ad3ce772ac39856a8142f74f2c2","lane":"cross","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"464efca235570ff26189da66d0ff023a","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"482ec24d598e324e115a31ff0350174380cd4ad3ce772ac39856a8142f74f2c2","lane":"cross","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"5df0901864e4d47931d2bed1a1e203a7","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792098828,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"482ec24d598e324e115a31ff0350174380cd4ad3ce772ac39856a8142f74f2c2","lane":"cross","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":null,"stamp":"9f6f9dee3f5eb143fd6235b7e8e0232e","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"reused"}
Ci-Attestation: {"at":1792100148,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"73ed9a2a211c929930364aa4a706d4fae6cc47355b6b5e30682e11f0cda2a6f6","lane":"tier2-linux","parents":["2a6197562f7059b5da6704e06576e29fbf0bf923"],"secs":1314,"stamp":"33e54448cf627348d932631e5d37a1ad","tree":"1b5cdebd6a812e60effb482d9b884f8e4e3e0276","v":1,"via":"run"}
@zackees

zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

This also implements #896 (start native jobs for edits inside platform #if blocks), under #897.

@zackees
zackees enabled auto-merge October 15, 2026 21:36
@zackees
zackees added this pull request to the merge queue Oct 15, 2026
@zackees

zackees commented Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

Review from #897 (keystone meta). This PR also covers #896, so I filed no competing PR.

Bug: #else of a Linux/Unix conditional is macOS+Windows code, but scopes to nothing

_complement only knows macOS and Windows, and Linux/BSD macros aren't recognized, so:

block before the hunk now should be
#ifdef __linux__ … #else {} macos, windows
#ifndef __linux__ {} macos, windows
CMake if(OS_LINUX) … else() {} macos, windows
#ifdef _WIN32 / #elif defined(__APPLE__) / #else {} {} (unchanged)
#if FOO … #else {} {} (unchanged)

There are 90 Linux/BSD-keyed conditionals in libobs/frontend/shared/plugins. Real example: frontend/components/ColorSourceToolbar.cpp:63. A fix that adds a third "nix" member to the universe and filters it out of the result (all 16 existing tests still pass):

patch
diff --git a/ci/scope_content.py b/ci/scope_content.py
index 19774f4c5..f2863c300 100644
--- a/ci/scope_content.py
+++ b/ci/scope_content.py
@@ -23,6 +23,12 @@ C_MAC = re.compile(r"\b(?:__APPLE__|TARGET_OS_\w+|OS_MACOS)\b")
 C_WIN = re.compile(r"\b(?:_WIN32|_WIN64|WIN32|_MSC_VER|OS_WINDOWS)\b")
 CMAKE_MAC = re.compile(r"\b(?:OS_MACOS|APPLE)\b|PLATFORM_ID:[^>]*\bDarwin\b")
 CMAKE_WIN = re.compile(r"\b(?:OS_WINDOWS|WIN32|MSVC)\b|PLATFORM_ID:[^>]*\bWindows\b")
+# Neither macOS nor Windows: only matters for the branches that exclude it
+# (`#else` of `#ifdef __linux__`, `#ifndef __linux__`), which are theirs.
+NIX = "nix"
+C_NIX = re.compile(r"\b(?:__linux__|__linux|__unix__|__FreeBSD__|__DragonFly__|__OpenBSD__|__NetBSD__|OS_LINUX|OS_FREEBSD|OS_POSIX)\b")
+CMAKE_NIX = re.compile(r"\b(?:OS_LINUX|OS_FREEBSD|OS_OPENBSD|OS_POSIX)\b|PLATFORM_ID:[^>]*\b(?:Linux|FreeBSD)\b")
+ALL = frozenset((MAC, WIN, NIX))
 
 C_SUFFIXES = (".c", ".h", ".cpp", ".hpp", ".cc", ".cxx", ".hh", ".m", ".mm")
 C_DIRECTIVE = re.compile(r"^\s*#\s*(ifdef|ifndef|if|elif|else|endif)\b(.*)")
@@ -39,11 +45,11 @@ def kind_of(path: str) -> str | None:
 
 
 def _patterns(kind: str):
-    return (C_MAC, C_WIN) if kind == "c" else (CMAKE_MAC, CMAKE_WIN)
+    return (C_MAC, C_WIN, C_NIX) if kind == "c" else (CMAKE_MAC, CMAKE_WIN, CMAKE_NIX)
 
 
 def mentions(text: str, kind: str) -> set[str]:
-    mac, win = _patterns(kind)
+    mac, win, _ = _patterns(kind)
     found = set()
     if mac.search(text):
         found.add(MAC)
@@ -55,20 +61,16 @@ def mentions(text: str, kind: str) -> set[str]:
 def selected(cond: str, kind: str, negated: bool = False) -> set[str]:
     """Platforms a branch with this condition can select."""
     out: set[str] = set()
-    for platform, pattern in zip((MAC, WIN), _patterns(kind)):
-        other = WIN if platform == MAC else MAC
+    for platform, pattern in zip((MAC, WIN, NIX), _patterns(kind)):
         for m in pattern.finditer(cond):
             neg = negated or bool(NEG_BEFORE.search(cond[: m.start()]))
-            out.add(other if neg else platform)
+            out |= ALL - {platform} if neg else {platform}
     return out
 
 
 def _complement(platforms: set[str]) -> set[str]:
-    if platforms == {MAC}:
-        return {WIN}
-    if platforms == {WIN}:
-        return {MAC}
-    return set()
+    """What an `#else` selects after branches that named `platforms`."""
+    return set(ALL - platforms) if platforms else set()
 
 
 @dataclass
@@ -99,7 +101,7 @@ def enclosing(lines: list[str], kind: str) -> set[str]:
     out: set[str] = set()
     for block in stack:
         out |= block.current
-    return out
+    return out - {NIX}
 
 
 @dataclass

Please add RED tests for the first three rows.

Measured effect (proof for #897)

I replayed this branch's scope() over the last 120 successful Pull runs (each PR's diff, with files read at the PR head):

before with #898
runs that start macOS+Windows 92 / 120 58 / 120
native runner-minutes over the 34 runs dropped 865 0 (median 25 per PR)
  • Most of the drop comes from test/cmocka/tests.d/*.cmake registrations: 77 of the PRs that triggered native jobs did so only because of them.
  • Wall time: since ci: Run Tier 2 Linux ctest with -j4 #837, Linux Tier 2 (~13 min) is the critical path, so a PR that skips native finishes about 0–3 min sooner. The real win is runner-minutes and less macOS queue pressure when many agents share runners. The patch above doesn't change these numbers.
  • Single-platform routing works in the replay: fix/pipe-shell-argv0 (rust/obs-util/src/platform/unix/) → macOS only, and fix/obs-enum-outputs-removal and fix/slideshow-manual-empty-clear → Windows only. Port PRs such as port/platform-cocoa still start both, because they also touch libobs/cmake/ (a shared prefix), which is now the largest remaining trigger after .cpp cmocka tests.

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.

1 participant