"""Stand-ins and helpers that the tests of simplex_build share.""" import contextlib import io import pathlib import struct import zipfile from unittest import mock from . import ( android, apk_zip, apple, buildroot, cli, common, desktop, dmg, docker, ios, link_without_rpaths, linux, macho, macos, nix, openssl, smoke, windows, ) MODULES = ( common, apk_zip, buildroot, apple, docker, nix, desktop, dmg, openssl, android, link_without_rpaths, linux, macho, macos, windows, ios, smoke, cli, ) REPO_ROOT = pathlib.Path(__file__).resolve().parents[2] class Names: """The names of all simplex_build modules, as the single script had them.""" def __getattr__(self, name): for module in MODULES: if hasattr(module, name): return getattr(module, name) raise AttributeError(name) build_script = Names() @contextlib.contextmanager def patch_all(name, new=mock.DEFAULT, **kwargs): """Patches name, with one object, in every module that defines or imports it.""" value = mock.MagicMock(**kwargs) if new is mock.DEFAULT else new with contextlib.ExitStack() as stack: for module in MODULES: if hasattr(module, name): stack.enter_context(mock.patch.object(module, name, value)) yield value Arch, Step, Target = build_script.Arch, build_script.Step, build_script.Target JAMMY, NOBLE, JAMMY_ARM, NOBLE_ARM = build_script.DESKTOP_IMAGES UTF8_FLAG = 0x800 GITHUB = {"GITHUB_ACTIONS": "true"} XCODE_DEVELOPER = pathlib.Path("/Applications/Xcode_26.6.app/Contents/Developer") APKSIGNER_PADDING = struct.pack(" keychain-access-groups $(AppIdentifierPrefix)chat.simplex.app """ class FakeApple: """Stands in for run() with Apple's tools: codesign stores and returns entitlements, otool returns OTOOL.""" def __init__(self, tamper=False): self.commands = [] self.signed = {} self.tamper = tamper def __call__(self, args, cwd=None, env=None, input=None, check=True, capture=False, title=None): args = [str(a) for a in args] self.commands.append(args) stdout = "" if args[0] == "codesign" and "--entitlements" in args and "-d" not in args: text = pathlib.Path(args[args.index("--entitlements") + 1]).read_text() self.signed[args[-1]] = text.replace("5NN7GUYB6T", "XXXX") if self.tamper else text elif args[0] == "codesign" and "-d" in args: stdout = self.signed[args[-1]] elif args[0] == "otool": stdout = OTOOL return mock.Mock(returncode=0, stdout=stdout) PBXPROJ = """ A1 /* libHSsimplex-chat-6.5.0.0-Old.a */ = {isa = PBXBuildFile; fileRef = B1 /* libHSsimplex-chat-6.5.0.0-Old.a */; }; A2 /* libHSsimplex-chat-6.5.0.0-Old-ghc9.6.3.a */ = {isa = PBXBuildFile; fileRef = B2 /* libHSsimplex-chat-6.5.0.0-Old-ghc9.6.3.a */; }; B1 /* libHSsimplex-chat-6.5.0.0-Old.a */ = {path = "libHSsimplex-chat-6.5.0.0-Old.a"; }; B2 /* libHSsimplex-chat-6.5.0.0-Old-ghc9.6.3.a */ = {path = "libHSsimplex-chat-6.5.0.0-Old-ghc9.6.3.a"; }; C1 /* libHSsimplex-chat-6.5.0.0-Old.a in Frameworks */, C2 /* libHSsimplex-chat-6.5.0.0-Old-ghc9.6.3.a in Frameworks */, D1 /* libHSsimplex-chat-6.5.0.0-Old.a */, D2 /* libHSsimplex-chat-6.5.0.0-Old-ghc9.6.3.a */, """