1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
import subprocess
from pathlib import Path
import pytest
from briefcase.console import LogLevel
from briefcase.exceptions import BriefcaseCommandError
from ...utils import create_file
@pytest.mark.parametrize("verbose", [True, False])
def test_lipo_dylib(dummy_command, verbose, tmp_path, capsys):
"""A binary library can be merged with lipo."""
if verbose:
dummy_command.console.verbosity = LogLevel.VERBOSE
# Create 3 source binaries.
create_file(tmp_path / "source-1/path/to/file.dylib", "dylib-1")
create_file(tmp_path / "source-2/path/to/file.dylib", "dylib-2")
create_file(tmp_path / "source-3/path/to/file.dylib", "dylib-3")
# Merge the libraries
dummy_command.lipo_dylib(
Path("path/to/file.dylib"),
tmp_path / "target",
[
tmp_path / "source-1",
tmp_path / "source-2",
tmp_path / "source-3",
],
)
# Lipo was invoked with three sources
dummy_command.tools.subprocess.run.assert_called_once_with(
[
"lipo",
"-create",
"-output",
tmp_path / "target/path/to/file.dylib",
tmp_path / "source-1/path/to/file.dylib",
tmp_path / "source-2/path/to/file.dylib",
tmp_path / "source-3/path/to/file.dylib",
],
check=True,
)
# The target directory exists.
assert (tmp_path / "target/path/to").is_dir()
# Output only happens if in debug mode
output = capsys.readouterr().out.split("\n")
assert len(output) == (2 if verbose else 1)
@pytest.mark.parametrize("verbose", [True, False])
def test_lipo_dylib_partial(dummy_command, verbose, tmp_path, capsys):
"""If a source doesn't have the library, it isn't included in the merge."""
if verbose:
dummy_command.console.verbosity = LogLevel.VERBOSE
# Create 2 source binaries. Source-2 doesn't have the binary.
create_file(tmp_path / "source-1/path/to/file.dylib", "dylib-1")
create_file(tmp_path / "source-3/path/to/file.dylib", "dylib-3")
# Merge the libraries
dummy_command.lipo_dylib(
Path("path/to/file.dylib"),
tmp_path / "target",
[
tmp_path / "source-1",
tmp_path / "source-3",
],
)
# Lipo was invoked with three sources
dummy_command.tools.subprocess.run.assert_called_once_with(
[
"lipo",
"-create",
"-output",
tmp_path / "target/path/to/file.dylib",
tmp_path / "source-1/path/to/file.dylib",
tmp_path / "source-3/path/to/file.dylib",
],
check=True,
)
# The target directory exists.
assert (tmp_path / "target/path/to").is_dir()
# Output only happens if in debug mode
output = capsys.readouterr().out.split("\n")
assert len(output) == (2 if verbose else 1)
@pytest.mark.parametrize("verbose", [True, False])
def test_lipo_dylib_merge_error(dummy_command, verbose, tmp_path, capsys):
"""If the merge process fails, an exception is raised."""
if verbose:
dummy_command.console.verbosity = LogLevel.VERBOSE
# Create 3 source binaries.
create_file(tmp_path / "source-1/path/to/file.dylib", "dylib-1")
create_file(tmp_path / "source-2/path/to/file.dylib", "dylib-2")
create_file(tmp_path / "source-3/path/to/file.dylib", "dylib-3")
# lipo raises an exception.
dummy_command.tools.subprocess.run.side_effect = subprocess.CalledProcessError(
returncode=-1, cmd="lipo..."
)
# Merge the libraries. This raises an exception:
with pytest.raises(
BriefcaseCommandError,
match=r"Unable to create fat library for path[/\\]to[/\\]file\.dylib",
):
dummy_command.lipo_dylib(
Path("path/to/file.dylib"),
tmp_path / "target",
[
tmp_path / "source-1",
tmp_path / "source-2",
tmp_path / "source-3",
],
)
# Lipo was invoked with three sources
dummy_command.tools.subprocess.run.assert_called_once_with(
[
"lipo",
"-create",
"-output",
tmp_path / "target/path/to/file.dylib",
tmp_path / "source-1/path/to/file.dylib",
tmp_path / "source-2/path/to/file.dylib",
tmp_path / "source-3/path/to/file.dylib",
],
check=True,
)
# The target directory exists.
assert (tmp_path / "target/path/to").is_dir()
# Output only happens if in debug mode
output = capsys.readouterr().out.split("\n")
assert len(output) == (2 if verbose else 1)
|