Files
wine-access/tests/build_sh_orca_test.py
hjozwiak e920543dcb Update the build script to put the Orca extension into place.
Still need to do the symlinking yourself though.
2026-10-31 10:03:30 -04:00

109 lines
4.4 KiB
Python

"""Check build.sh installs the Orca extension only when Orca 51+ is present.
The real compile is replaced with a stub cmake and stub prerequisites, so
this runs without Wine. Orca itself is a stub whose --version output is
controlled per case; one case uses a PATH with no orca at all.
"""
from pathlib import Path
import os
import shutil
import stat
import subprocess
import tempfile
projectDir = Path(__file__).resolve().parents[1]
sourceFiles = sorted((projectDir / "orca/wine_access").glob("*.py"))
assert sourceFiles, "Orca extension sources missing"
PREREQUISITES = ["cmake", "make", "gcc", "g++", "pkg-config", "winegcc",
"wineg++", "widl", "x86_64-w64-mingw32-gcc",
"i686-w64-mingw32-gcc"]
REAL_TOOLS = ["dirname", "install", "rm"]
def write_stub(directory, name, body="#!/bin/sh\nexit 0\n"):
stub = directory / name
stub.write_text(body)
stub.chmod(0o755)
with tempfile.TemporaryDirectory(prefix="wine-access-build-sh-") as temporary:
temporary = Path(temporary)
def make_bin(orca_version):
"""A PATH directory with every tool build.sh needs, plus stub orca."""
binDir = Path(tempfile.mkdtemp(dir=temporary, prefix="bin-"))
for tool in REAL_TOOLS:
(binDir / tool).symlink_to(shutil.which(tool))
for tool in PREREQUISITES:
write_stub(binDir, tool)
if orca_version is not None:
write_stub(binDir, "orca",
"#!/bin/sh\n"
f'echo "Orca version {orca_version} (rev test), '
'AT-SPI2 version: 2.0"\n')
return binDir
def run_build_sh(binDir, prefix, *extra):
environment = {"PATH": str(binDir), "HOME": str(temporary / "home")}
result = subprocess.run(
["/bin/bash", str(projectDir / "build.sh"), *extra,
str(temporary / "build"), str(prefix)],
capture_output=True, text=True, env=environment)
assert result.returncode == 0, result.stdout + result.stderr
return result
def extension_dir(prefix):
return prefix / "share/wine-access/orca/wine_access"
# Orca 51 present: the shared copy is installed, identical to the
# sources, with the per-user link/approve commands printed. The user
# extension directory itself must not be created.
prefix = temporary / "prefix51"
result = run_build_sh(make_bin("51.2"), prefix)
for source in sourceFiles:
installed = extension_dir(prefix) / source.name
assert installed.read_bytes() == source.read_bytes(), installed
assert stat.S_IMODE(installed.stat().st_mode) == 0o644, installed
assert "orca --approve-extension wine_access" in result.stdout
assert f"ln -sT {extension_dir(prefix)}" in result.stdout
assert not (temporary / "home/.local/share/orca").exists()
# Removal with no orca on PATH still removes the extension files and
# the helper, and leaves unrelated files in place.
helper = prefix / "libexec/wine-access/wine-access.exe"
helper.parent.mkdir(parents=True)
helper.write_text("helper\n")
stray = extension_dir(prefix) / "keep.txt"
stray.write_text("keep\n")
run_build_sh(make_bin(None), prefix, "-r")
assert not helper.exists()
for source in sourceFiles:
assert not (extension_dir(prefix) / source.name).exists(), source
assert stray.read_text() == "keep\n"
# Removal also works when only the extension copy remains.
prefix = temporary / "prefixOnlyOrca"
run_build_sh(make_bin("51.2"), prefix)
result = run_build_sh(make_bin(None), prefix, "-r")
assert "No Wine Access installation" not in result.stdout
for source in sourceFiles:
assert not (extension_dir(prefix) / source.name).exists(), source
# Orca older than 51: the helper install still succeeds, but no
# extension copy is installed and the reason is reported.
prefix = temporary / "prefix50"
result = run_build_sh(make_bin("50.1"), prefix)
assert not extension_dir(prefix).exists()
assert "51" in result.stdout + result.stderr
# No orca at all: nothing Orca-related is installed or printed as
# an instruction.
prefix = temporary / "prefixNone"
result = run_build_sh(make_bin(None), prefix)
assert not extension_dir(prefix).exists()
assert "--approve-extension" not in result.stdout
print("PASS: build.sh installs and removes the Orca extension conditionally")