diff --git a/eng/graphics/tests/test_verify_sdk_policy.py b/eng/graphics/tests/test_verify_sdk_policy.py new file mode 100644 index 00000000..cee50f74 --- /dev/null +++ b/eng/graphics/tests/test_verify_sdk_policy.py @@ -0,0 +1,35 @@ +import importlib.util +from pathlib import Path +import unittest + + +ROOT = Path(__file__).resolve().parents[3] +SPEC = importlib.util.spec_from_file_location( + "verify_sdk", ROOT / "eng/graphics/verify-sdk.py") +VERIFY_SDK = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(VERIFY_SDK) + + +class DawnSymbolPolicyTests(unittest.TestCase): + def test_current_policy_is_accepted_for_every_rid(self): + for rid in ("osx-arm64", "linux-x64", "win-x64"): + self.assertTrue( + VERIFY_SDK.symbol_policy_matches("current", "current", rid)) + + def test_qualified_legacy_policy_is_macos_only(self): + legacy = next(iter(VERIFY_SDK.LEGACY_OSX_DAWN_SYMBOL_POLICIES)) + self.assertTrue( + VERIFY_SDK.symbol_policy_matches(legacy, "current", "osx-arm64")) + self.assertFalse( + VERIFY_SDK.symbol_policy_matches(legacy, "current", "linux-x64")) + self.assertFalse( + VERIFY_SDK.symbol_policy_matches(legacy, "current", "win-x64")) + + def test_unknown_policy_fails_closed(self): + for rid in ("osx-arm64", "linux-x64", "win-x64"): + self.assertFalse( + VERIFY_SDK.symbol_policy_matches("unknown", "current", rid)) + + +if __name__ == "__main__": + unittest.main() diff --git a/eng/graphics/verify-sdk.py b/eng/graphics/verify-sdk.py index 72cb60b4..cca16468 100644 --- a/eng/graphics/verify-sdk.py +++ b/eng/graphics/verify-sdk.py @@ -8,6 +8,12 @@ LOCK_PATH = Path(__file__).with_name("dependencies.lock.json") ROOT = Path(__file__).resolve().parents[2] +LEGACY_OSX_DAWN_SYMBOL_POLICIES = frozenset({ + # Qualified before the Linux/Windows native-device bridge was added. The + # Apple branch still exports the same bounded wgpu* surface; the bridge is + # deliberately not compiled for macOS. + "375d05a693311a8dd981d265b9291dbd5ff0ac482442422771ab4faca573938c", +}) def sha(path): @@ -18,6 +24,13 @@ def sha(path): return digest.hexdigest() +def symbol_policy_matches(installed_digest, current_digest, rid): + return installed_digest == current_digest or ( + rid.startswith("osx-") + and installed_digest in LEGACY_OSX_DAWN_SYMBOL_POLICIES + ) + + def verify(sdk, component, rid): lock = json.loads(LOCK_PATH.read_text()) manifest_path = sdk / "webscene-graphics-package.json" @@ -74,7 +87,10 @@ def verify(sdk, component, rid): or files.get("licenses/windows-sdk/LICENSE.rtf") != pin["licenseSha256"] or files.get("build-info/windows-runtime.json") != sha(LOCK_PATH.with_name("windows-runtime.json"))): raise ValueError("dawn: pinned Windows shader compiler or license mismatch") - if sha(sdk / "build-info/DawnSymbolBoundary.cmake") != sha(LOCK_PATH.with_name("DawnSymbolBoundary.cmake")): + if not symbol_policy_matches( + sha(sdk / "build-info/DawnSymbolBoundary.cmake"), + sha(LOCK_PATH.with_name("DawnSymbolBoundary.cmake")), + rid): raise ValueError("dawn: symbol isolation policy mismatch; rebuild the SDK") if rid.startswith(("linux-", "win-")): bridge_files = {