diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..8076eb6 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,34 @@ +# Repository Guidelines + +## Project Structure & Module Organization + +This standalone Winelib helper forwards Wine accessibility events and NVDA/Tolk requests to Cthulhu’s session D-Bus service. Root sources include `main.cpp` (RPC, MSAA, event forwarding), `list_view.cpp`, and native hooks in `menu_hook.c` and `edit_hook.c`. Shared contracts live in headers and `nvdaController.idl`; generated RPC files belong under `build/generated/`. `tests/` holds C/C++ fixtures and the Python integration runner. Arch packaging lives in `distro-packages/ArchLinux/wine-access-git/`. + +## Build, Test, and Development Commands + +Requirements: CMake 3.20+, Wine development tools, GLib/GIO, pkg-config, and x86_64 MinGW GCC. + +```sh +cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=winelib-toolchain.cmake +cmake --build build --parallel +xvfb-run -a ctest --test-dir build --output-on-failure +python3 tests/menu_integration.py --build-dir build +``` + +These configure, compile, run the MSAA state check, and exercise menus respectively. Integration tests require PyGObject, `dbus-run-session`, and a graphical display; use `xvfb-run -a` for a private display. + +`./build.sh` builds and installs to `$HOME/.local`; optional arguments specify build directory and installation prefix. For local operation, run `build/cthulhu-wine-access.exe` with Cthulhu’s D-Bus service active. Keep the executable, `.exe.so` sidecar, and hook DLL together. + +## Coding Style & Naming Conventions + +Follow existing style: two-space C/C++ indentation, four-space Python indentation, snake_case helper functions, camelCase local variables, and PascalCase structs. Preserve Windows API signatures and LGPL SPDX headers. C++ uses C++20; native hooks compile as C11 with `-Wall -Wextra`. No formatter is configured. Run `shellcheck build.sh` when editing that script. Use Wine Unicode APIs rather than Linux libc wide-character routines: Wine’s `wchar_t` is 16-bit. + +## Testing Guidelines + +CTest runs `tests/msaa_states_test.cpp`; integration assertions live in `tests/menu_integration.py`. Follow existing `*_fixture.c` and `*_test.cpp` names. Choose `--fixture edit`, `notepad`, `list`, or `winforms` for affected controls. Exercise editor lifecycle flags and `--fixture list --32-bit` where relevant; the latter needs i686 MinGW GCC. Run Xvfb checks sequentially. No numeric coverage threshold is configured. + +Recorded events do not prove audible speech or physical braille. Follow `tests/README.md` for live acceptance and regression procedures, including password exclusion and focus restoration. + +## Commit & Pull Request Guidelines + +Recent commits use short imperative subjects describing behavior. Keep changes scoped; describe the problem, fix, commands run, and remaining live checks. Link relevant issues when available. Read the README’s AI-assisted contributions policy, review the diff, and test affected existing workflows before submission. Human review and submission remain the contributor’s responsibility. diff --git a/README.md b/README.md index 91979ae..86f34ab 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Cthulhu-Go supervisor. Building requires an x86_64 Linux host with: - CMake 3.20 or newer; +- Make and native GCC/G++ (the script uses CMake's default Makefile generator); - `pkg-config` and the GLib/GIO development files; - Wine development tools: `winegcc`, `wineg++`, and `widl`; - `x86_64-w64-mingw32-gcc` to build the native menu hook DLL @@ -32,19 +33,33 @@ project yet; it needs a 32-bit Winegcc and 32-bit GLib/GIO development setup. ## Build -The convenience script builds in `./build` and installs to the per-user Cthulhu -libexec directory: +The convenience script builds in `./build`. Running it as a user installs to +`$HOME/.local/libexec/cthulhu/wine`; running it as root installs system wide to +`/usr/libexec/cthulhu/wine`: ```sh ./build.sh +sudo ./build.sh ``` +Before building, the script checks required tools and GIO development files. +If any are missing, it lists them with Arch Linux package names and an install +command, then exits without building. Other distributions need equivalent +development packages. Removal does not require these dependencies. + +Use `./build.sh -r` to remove the local installation, or +`sudo ./build.sh -r` to remove the system installation. If a user has no local +installation but a system installation exists, the script requests the latter +command without running sudo itself. Removal deletes only the three helper +files and leaves other directory contents untouched. + Alternative build and install locations may be supplied as positional arguments. The second argument is the installation prefix, not the final helper directory: ```sh ./build.sh /tmp/wine-access-build "$HOME/.local" +./build.sh -r /tmp/wine-access-build "$HOME/.local" ``` That installs the helper and its Winelib sidecar as: diff --git a/build.sh b/build.sh index 4af5ed0..2edc9ac 100755 --- a/build.sh +++ b/build.sh @@ -2,15 +2,114 @@ set -euo pipefail +usage() { + echo "Usage: $0 [-r] [build-directory [install-prefix]]" + echo "Build and install locally as a user, or system wide as root." + echo " -r Remove the installed helper instead of building." + echo " -h Show this help." +} + +removeInstalled=false +while getopts ':rh' option; do + case "$option" in + r) removeInstalled=true ;; + h) usage; exit 0 ;; + *) usage >&2; exit 2 ;; + esac +done +shift "$((OPTIND - 1))" +if (( $# > 2 )); then + usage >&2 + exit 2 +fi + projectDir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) buildDir=${1:-"$projectDir/build"} -prefix=${2:-"${HOME}/.local"} +systemPrefix=/usr +if (( EUID == 0 )); then + defaultPrefix=$systemPrefix +else + defaultPrefix="${HOME}/.local" +fi +prefix=${2:-"$defaultPrefix"} +installDir="${prefix%/}/libexec/cthulhu/wine" +installedFiles=(cthulhu-wine-access.exe cthulhu-wine-access.exe.so wine-access-menu.dll) + +has_installation() { + local candidateDir=$1 + local installedFile + for installedFile in "${installedFiles[@]}"; do + if [[ -e "$candidateDir/$installedFile" || -L "$candidateDir/$installedFile" ]]; then + return 0 + fi + done + return 1 +} + +if "$removeInstalled"; then + if has_installation "$installDir"; then + for installedFile in "${installedFiles[@]}"; do + rm -f -- "$installDir/$installedFile" + done + echo "Removed Wine Access from $installDir" + elif (( EUID != 0 && $# < 2 )) && has_installation "$systemPrefix/libexec/cthulhu/wine"; then + echo "Only a system-wide installation was found. Run: sudo ./build.sh -r" >&2 + exit 1 + else + echo "No Wine Access installation found in $installDir" + fi + exit 0 +fi + +check_prerequisites() { + local requirement tool package + local -a missingRequirements=() missingPackages=() + local -A seenPackages=() + local -a requirements=( + cmake:cmake make:make gcc:gcc g++:gcc pkg-config:pkgconf + winegcc:wine wineg++:wine widl:wine + x86_64-w64-mingw32-gcc:mingw-w64-gcc + ) + + for requirement in "${requirements[@]}"; do + tool=${requirement%%:*} + package=${requirement#*:} + if ! command -v "$tool" >/dev/null 2>&1; then + missingRequirements+=("$tool (Arch Linux package: $package)") + if [[ ! -v "seenPackages[$package]" ]]; then + missingPackages+=("$package") + seenPackages[$package]=1 + fi + fi + done + if command -v pkg-config >/dev/null 2>&1 && ! pkg-config --exists gio-2.0; then + missingRequirements+=("GIO development files, gio-2.0 (Arch Linux package: glib2)") + missingPackages+=(glib2) + fi + + if (( ${#missingRequirements[@]} > 0 )); then + echo "Missing build prerequisites:" >&2 + for requirement in "${missingRequirements[@]}"; do + echo " $requirement" >&2 + done + if ! command -v pkg-config >/dev/null 2>&1; then + echo "GIO development files cannot be checked until pkg-config is available." >&2 + fi + echo "On Arch Linux: sudo pacman -S --needed ${missingPackages[*]}" >&2 + echo "On other distributions, install the equivalent development packages." >&2 + return 1 + fi +} + +check_prerequisites cmake \ -S "$projectDir" \ -B "$buildDir" \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_TOOLCHAIN_FILE="$projectDir/winelib-toolchain.cmake" \ - -DCMAKE_INSTALL_PREFIX="$prefix" + -DCMAKE_INSTALL_PREFIX="$prefix" \ + -DCMAKE_INSTALL_LIBEXECDIR:PATH=libexec \ + -DWINE_ACCESS_INSTALL_DIR:PATH=libexec/cthulhu/wine cmake --build "$buildDir" --parallel cmake --install "$buildDir"