67 lines
3.4 KiB
Python
67 lines
3.4 KiB
Python
"""Redistributable preparation tests; no native builds or GPU execution."""
|
|||
|
|
from pathlib import Path
|
||
|
|
import tempfile
|
||
|
|
import unittest
|
||
|
|
|
||
|
|
from build_runtime import bundle_windows_crt, WINDOWS_CRT_FILES
|
||
|
|
|
||
|
|
|
||
|
|
class CrtTests(unittest.TestCase):
|
||
|
|
def fixture(self, directory):
|
||
|
|
root = Path(directory)
|
||
|
|
installation = root / "Visual Studio"
|
||
|
|
auxiliary = installation / "VC/Auxiliary/Build"
|
||
|
|
auxiliary.mkdir(parents=True)
|
||
|
|
(auxiliary / "Microsoft.VCRedistVersion.default.txt").write_text("14.44.35112")
|
||
|
|
(auxiliary / "Microsoft.VCToolsVersion.default.txt").write_text("14.44.35207")
|
||
|
|
source = installation / "VC/Redist/MSVC/14.44.35112/x64/Microsoft.VC143.CRT"
|
||
|
|
source.mkdir(parents=True)
|
||
|
|
for name in WINDOWS_CRT_FILES:
|
||
|
|
(source / name).write_bytes(name.encode())
|
||
|
|
(source / "unlisted-debug.dll").write_bytes(b"do not distribute")
|
||
|
|
build = root / "build"
|
||
|
|
(build / "Release").mkdir(parents=True)
|
||
|
|
(build / "CMakeCache.txt").write_text(f"CMAKE_GENERATOR_INSTANCE:INTERNAL={installation}\n")
|
||
|
|
return build, source, auxiliary
|
||
|
|
|
||
|
|
def test_copies_only_fixed_unmodified_release_files_and_public_provenance(self):
|
||
|
|
with tempfile.TemporaryDirectory() as directory:
|
||
|
|
build, source, _ = self.fixture(directory)
|
||
|
|
bundle_windows_crt(build)
|
||
|
|
for name in WINDOWS_CRT_FILES:
|
||
|
|
self.assertEqual((build / "Release" / name).read_bytes(), (source / name).read_bytes())
|
||
|
|
self.assertFalse((build / "Release/unlisted-debug.dll").exists())
|
||
|
|
notice = (build / "Release/MSVC-REDISTRIBUTION.txt").read_text(encoding="utf-8")
|
||
|
|
self.assertIn("14.44.35112", notice)
|
||
|
|
self.assertIn("https://learn.microsoft.com/", notice)
|
||
|
|
self.assertNotIn(directory, notice)
|
||
|
|
|
||
|
|
def test_missing_or_mismatched_crt_preserves_existing_files(self):
|
||
|
|
with tempfile.TemporaryDirectory() as directory:
|
||
|
|
build, source, auxiliary = self.fixture(directory)
|
||
|
|
existing = build / "Release/msvcp140.dll"
|
||
|
|
existing.write_bytes(b"previous CRT")
|
||
|
|
(source / "vcruntime140.dll").unlink()
|
||
|
|
with self.assertRaisesRegex(RuntimeError, "redistributable is missing"):
|
||
|
|
bundle_windows_crt(build)
|
||
|
|
self.assertEqual(existing.read_bytes(), b"previous CRT")
|
||
|
|
(auxiliary / "Microsoft.VCRedistVersion.default.txt").write_text("14.43.12345")
|
||
|
|
with self.assertRaisesRegex(RuntimeError, "does not match"):
|
||
|
|
bundle_windows_crt(build)
|
||
|
|
self.assertEqual(existing.read_bytes(), b"previous CRT")
|
||
|
|
|
||
|
|
def test_custom_toolset_compiler_mismatch_rejects_before_copy(self):
|
||
|
|
with tempfile.TemporaryDirectory() as directory:
|
||
|
|
build, _, _ = self.fixture(directory)
|
||
|
|
with (build / "CMakeCache.txt").open("a") as stream:
|
||
|
|
stream.write("CMAKE_CACHE_MAJOR_VERSION:INTERNAL=4\nCMAKE_CACHE_MINOR_VERSION:INTERNAL=2\nCMAKE_CACHE_PATCH_VERSION:INTERNAL=0\n")
|
||
|
|
compiler = build / "CMakeFiles/4.2.0/CMakeCXXCompiler.cmake"
|
||
|
|
compiler.parent.mkdir(parents=True)
|
||
|
|
compiler.write_text('set(CMAKE_CXX_COMPILER_VERSION "19.45.12345")\n')
|
||
|
|
with self.assertRaisesRegex(RuntimeError, "actual selected compiler"):
|
||
|
|
bundle_windows_crt(build)
|
||
|
|
self.assertFalse((build / "Release/msvcp140.dll").exists())
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|