Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(packaging): distinguish Mach-O identity from linked libraries

rubenluetke10-beep5b2a92af715b
diff --git a/scripts/prepare_browser_wheelhouse.py b/scripts/prepare_browser_wheelhouse.py
index c7f02ea80d..cb9dbb2781 100644
--- a/scripts/prepare_browser_wheelhouse.py
+++ b/scripts/prepare_browser_wheelhouse.py
@@ -47,6 +47,18 @@ def run(argv: list[str], **kwargs) -> subprocess.CompletedProcess:
)
+def unbundled_libraries(links: str, identities: str) -> list[str]:
+ # otool -L includes LC_ID_DYLIB (the module's own install name) as well
+ # as LC_LOAD_DYLIB entries. Only actual imported libraries need checking.
+ own_names = {line.strip() for line in identities.splitlines()[1:] if line.strip()}
+ dependencies = [line.strip().split(" ", 1)[0] for line in links.splitlines()[1:]]
+ return [
+ path
+ for path in dependencies
+ if path not in own_names and not path.startswith(("/usr/lib/", "/System/Library/"))
+ ]
+
+
def main() -> int:
if sys.platform != "darwin" or platform.machine().lower() not in {"x86_64", "amd64"}:
print("Browser wheelhouse is only needed on Intel macOS")
@@ -94,13 +106,13 @@ def main() -> int:
binary = Path(scratch) / Path(name).name
binary.write_bytes(archive.read(name))
links = run(["otool", "-L", str(binary)], capture_output=True).stdout
+ identities = run(["otool", "-D", str(binary)], capture_output=True).stdout
print(links, flush=True)
- for line in links.splitlines()[1:]:
- dependency = line.strip().split(" ", 1)[0]
- if not dependency.startswith(("/usr/lib/", "/System/Library/")):
- raise RuntimeError(
- f"Cryptography wheel links a non-system shared library: {dependency}"
- )
+ outside = unbundled_libraries(links, identities)
+ if outside:
+ raise RuntimeError(
+ f"Cryptography wheel links non-system shared libraries: {outside}"
+ )
(assets / "requirements-bundled.lock").write_text(
add_wheel_hash(lock, built[0]), encoding="utf-8"
)
diff --git a/tests/unit/packaging/test_browser_wheelhouse.py b/tests/unit/packaging/test_browser_wheelhouse.py
index b8c41a0591..440e13e835 100644
--- a/tests/unit/packaging/test_browser_wheelhouse.py
+++ b/tests/unit/packaging/test_browser_wheelhouse.py
@@ -5,7 +5,20 @@ import hashlib
import pytest
from jarvis.society.browser import install
-from scripts.prepare_browser_wheelhouse import add_wheel_hash
+from scripts.prepare_browser_wheelhouse import add_wheel_hash, unbundled_libraries
+
+
+def test_macho_identity_is_not_an_external_library():
+ identity = "@rpath/cryptography.hazmat.bindings._rust.abi3.so"
+ links = (
+ "_rust.abi3.so:\n"
+ f"\t{identity} (compatibility version 0.0.0, current version 0.0.0)\n"
+ "\t/usr/lib/libiconv.2.dylib (compatibility version 7.0.0)\n"
+ "\t/usr/lib/libSystem.B.dylib (compatibility version 1.0.0)\n"
+ )
+ assert unbundled_libraries(links, f"_rust.abi3.so:\n{identity}\n") == []
+ links += "\t@rpath/libssl.3.dylib (compatibility version 3.0.0)\n"
+ assert unbundled_libraries(links, f"_rust.abi3.so:\n{identity}\n") == ["@rpath/libssl.3.dylib"]
def test_built_wheel_adds_its_digest_without_changing_other_pins(tmp_path):