Skip to content

Commit e98b885

Browse files
Merge pull request #404 from SceneTech/fix/sdk-tool-bytecode-403
Keep installed SDK packaging tools immutable
2 parents 51f7138 + ce684a2 commit e98b885

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎eng/sdk/test-installed-macos-bundle-audit.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def main():
4444
if not installed.is_file():
4545
relative = installed.relative_to(prefix)
4646
raise RuntimeError(f"installed SDK surface is missing {relative}")
47+
installed_before = {
48+
path.relative_to(prefix).as_posix(): path.read_bytes()
49+
for path in prefix.rglob("*") if path.is_file()
50+
}
4751

4852
bundle = work / "Fixture.app"
4953
macos = bundle / "Contents/MacOS"
@@ -101,6 +105,19 @@ def main():
101105
"--maximum-audit-entries", "10000",
102106
"--maximum-audit-evidence-bytes", str(64 * 1024),
103107
], stdout=subprocess.DEVNULL)
108+
installed_after = {
109+
path.relative_to(prefix).as_posix(): path.read_bytes()
110+
for path in prefix.rglob("*") if path.is_file()
111+
}
112+
if installed_after != installed_before:
113+
added = sorted(set(installed_after) - set(installed_before))
114+
changed = sorted(
115+
path for path in set(installed_after) & set(installed_before)
116+
if installed_after[path] != installed_before[path]
117+
)
118+
raise RuntimeError(
119+
f"installed SDK mutated during packaging: added={added}, changed={changed}"
120+
)
104121
final_architectures = run(
105122
["xcrun", "lipo", "-archs", str(extension)], capture_output=True
106123
).stdout.split()

‎eng/sdk/test-macos-bundle-audit.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import json
77
import os
88
from pathlib import Path
9+
import shutil
10+
import subprocess
911
import sys
1012
import tempfile
1113
import time
@@ -397,6 +399,32 @@ def test_packager_runs_audit_before_outer_signature(self):
397399
"--maximum-audit-entries", "--maximum-audit-evidence-bytes"):
398400
self.assertIn(option, source)
399401

402+
def test_packager_import_does_not_mutate_installed_tools(self):
403+
with tempfile.TemporaryDirectory(prefix="webscene immutable tools ") as temporary:
404+
tools = Path(temporary) / "share/webscene/tools"
405+
tools.mkdir(parents=True)
406+
for name in ("package_macos.py", "audit_macos_bundle.py"):
407+
shutil.copy2(ROOT / "src/WebScene.Sdk/tools" / name, tools / name)
408+
before = {
409+
path.relative_to(tools).as_posix(): path.read_bytes()
410+
for path in tools.rglob("*") if path.is_file()
411+
}
412+
started = time.monotonic()
413+
for _ in range(100):
414+
completed = subprocess.run(
415+
[sys.executable, str(tools / "package_macos.py"), "--help"],
416+
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
417+
text=True, timeout=10)
418+
self.assertEqual(completed.returncode, 0, completed.stderr)
419+
elapsed = time.monotonic() - started
420+
after = {
421+
path.relative_to(tools).as_posix(): path.read_bytes()
422+
for path in tools.rglob("*") if path.is_file()
423+
}
424+
self.assertEqual(after, before)
425+
self.assertFalse(any(path.name == "__pycache__" for path in tools.rglob("*")))
426+
self.assertLess(elapsed, 15.0)
427+
400428
def test_single_architecture_normalization_is_atomic_and_idempotent(self):
401429
extension_relative = "Contents/PlugIns/sample.node"
402430
self.fixture.extension.write_bytes(b"\xca\xfe\xba\xbf" + bytes(range(128)))

‎src/WebScene.Sdk/tools/package_macos.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import platform
77
import shutil
88
import subprocess
9+
import sys
10+
11+
# Installed SDK tools are immutable inputs. Prevent the adjacent module import
12+
# below from materializing __pycache__ inside an otherwise verified SDK.
13+
sys.dont_write_bytecode = True
914

1015
from audit_macos_bundle import (
1116
DEFAULT_MAXIMUM_ENTRIES,

0 commit comments

Comments
 (0)