Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ci/libobs_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def compile_args(args: list[str]) -> list[str]:
if arg in ("-o", "-MF", "-MT", "-MQ"):
skip = True
continue
if arg in ("-c", "-MD", "-MMD") or arg.startswith(("-o", "/Fo", "/Fd", "-MF")):
# GCC's ccache integration adds this preprocessing-output flag. It
# does not change objects, but lets -M load a built PCH and omit its
# headers: restore (before the PCH exists) and store then disagree.
# Always scan the textual header closure, including when a PCH exists.
if arg in ("-c", "-MD", "-MMD", "-fpch-preprocess") or arg.startswith(("-o", "/Fo", "/Fd", "-MF")):
continue
out.append(arg)
return out
Expand Down
49 changes: 49 additions & 0 deletions ci/test_libobs_modules_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import importlib.util
import json
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
Expand All @@ -31,6 +32,9 @@
SPEC.loader.exec_module(mods)

CC = shutil.which("cc") or shutil.which("gcc") or shutil.which("clang")
GCC = CC and "Free Software Foundation" in subprocess.run(
[CC, "--version"], capture_output=True, text=True, check=True
).stdout


def fake_tree(base: Path, build_name: str, launcher: str | None = None, target_suffix: str = "") -> tuple[Path, Path]:
Expand Down Expand Up @@ -87,6 +91,51 @@ def test_launcher_and_probe_name_do_not_change_the_key(self):
_, probed = fake_tree(self.tmp, "b2", launcher="zccache", target_suffix="-keyprobe")
self.assertEqual(self.keys(plain, source), self.keys(probed, source))

def pch_tree(self):
source, build = fake_tree(self.tmp, "b")
header = source / "libobs" / "pch-only.h"
header.write_text("#define PCH_VALUE 1\n")
pch = source / "libobs" / "pch.h"
pch.write_text('#include "pch-only.h"\n')
database = build / "compile_commands.json"
entries = json.loads(database.read_text())
entries[1]["arguments"][1:1] = ["-fpch-preprocess", "-include", str(pch)]
database.write_text(json.dumps(entries))
return source, build, header, pch

def compile_pch(self, source, build, pch):
subprocess.run(
[CC, f"-I{source}/libobs", f"-I{build}/config", "-O2", "-x", "c-header", str(pch), "-o", str(pch) + ".gch"],
capture_output=True, text=True, check=True,
)

@unittest.skipUnless(GCC, "requires GCC PCH dependency behavior")
def test_building_a_pch_does_not_change_the_key(self):
source, build, _, pch = self.pch_tree()
before = self.keys(build, source)
self.compile_pch(source, build, pch)
self.assertEqual(before, self.keys(build, source))

@unittest.skipUnless(GCC, "requires GCC PCH dependency behavior")
def test_a_built_pch_does_not_hide_header_edits(self):
source, build, header, pch = self.pch_tree()
self.compile_pch(source, build, pch)
before = self.keys(build, source)
header.write_text("#define PCH_VALUE 2\n")
after = self.keys(build, source)
self.assertNotEqual(before["graphics"], after["graphics"])
self.assertEqual(before["core"], after["core"])

@unittest.skipUnless(GCC, "requires GCC preprocessing flag")
def test_pch_preprocessing_flag_does_not_change_the_key(self):
source, build, _, _ = self.pch_tree()
hosted = self.keys(build, source)
database = build / "compile_commands.json"
entries = json.loads(database.read_text())
entries[1]["arguments"].remove("-fpch-preprocess")
database.write_text(json.dumps(entries))
self.assertEqual(hosted, self.keys(build, source))


MANIFESTS = {
# libobs-rust -> obs-a (normal) -> obs-b (build, via the workspace);
Expand Down
Loading