mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 23:28:34 +01:00
Step 8 (Option A of docs/dev/unified-binaries.md). The main.rs of komorebi-windows, komorebi-linux and komorebi-macos becomes daemon.rs of the library (pub fn run; komorebi:: paths are crate:: paths now, the inner attributes and the unit tests move with it), and their [[bin]] is gone, so each is a library only. The new package komorebi (komorebi-daemon/, version 0.1.42) is the one binary: its main calls komorebi_windows::daemon::run, komorebi_linux::daemon::run or komorebi_macos::daemon::run by cfg_select! on the target OS, through target-gated dependencies (one key per library, cargo allows one path per key), and forwards the features deadlock_detection and schemars. The binary name komorebi now comes from exactly one package. The four KDE integration tests that run the binary (no_kwin, socket, hot_reload, version) move to komorebi-daemon/tests/linux_*.rs; the version test compares with the KDE version crate, since the package version is now shared. Old names: komorebi-windows, komorebi-linux and komorebi-macos still build, as libraries (no binary any more: use -p komorebi). The flakes build -p komorebi with the KDE and macOS packages, the source filters take komorebi-daemon (manifest, main.rs, linux tests), the Windows filter leaves its linux tests out, deny.toml clarify entries gain komorebi, the release workflow's cargo wix and the justfile version lookup name komorebi, tools/fast-check checks -p komorebi on KDE and macOS. Behaviour: the same code runs, the same binary name; the Windows executable is rebuilt from the library (BEHAVIOUR for the e2e gate: the Windows e2e must run). Gates run: Windows clippy --all-targets -D warnings PASS; KDE check; macOS fake-CC check of -p komorebi -p komorebi-macos PASS (type check only); KDE cargo test -p komorebi -p komorebi-linux -p komorebic -p komorebi-client -p komorebi-hotkeys -p komorebi-core: 903 passed, 0 failed (the four moved tests and the unit test of daemon.rs included); CLI docs oracle identical x3; bar schema harness identical both bars; kde-closure-check ok; nix evaluation of the root and both nested flakes PASS; by evaluation an edit of komorebi/src/daemon.rs changes the Windows derivations only, of the KDE daemon.rs kfde only, of the macOS one neither (the shared komorebi-daemon/src/main.rs changes all, as expected). Not run: nix builds, VM, e2e, any Mac run.
95 lines
3.5 KiB
Rust
95 lines
3.5 KiB
Rust
#![cfg(target_os = "linux")]
|
|
//! `komorebi` connects to KWin unless it is told to run against the in-memory desktop, says
|
|
//! what went wrong when it cannot, and then leaves the socket of a komorebi that is running
|
|
//! alone.
|
|
|
|
use std::os::unix::net::UnixListener;
|
|
use std::os::unix::net::UnixStream;
|
|
use std::path::Path;
|
|
use std::process::Command;
|
|
use std::process::Stdio;
|
|
use std::time::Duration;
|
|
|
|
/// A bus that is not there, so that a test never reaches the KWin of the session it runs in
|
|
const NO_BUS: &str = "unix:path=/nonexistent/komorebi-test.bus";
|
|
|
|
/// A runtime directory of the test's own, made empty, which is also its home: komorebi makes
|
|
/// its log directory in the home and its data directory in the runtime directory, and binds its
|
|
/// socket there with `--fake-backend`, before anything else, so the user's are kept out of it,
|
|
/// and it is writable where the user's home is not (the nix sandbox). /tmp: short enough for a
|
|
/// unix socket path on macOS.
|
|
fn runtime(test: &str) -> String {
|
|
let runtime = format!("/tmp/komorebi-no-kwin-{test}-{}", std::process::id());
|
|
let _ = std::fs::remove_dir_all(&runtime);
|
|
std::fs::create_dir_all(&runtime).unwrap();
|
|
runtime
|
|
}
|
|
|
|
#[test]
|
|
fn without_a_session_bus_komorebi_exits_with_an_error_naming_it() {
|
|
let runtime = runtime("bus");
|
|
let output = Command::new(env!("CARGO_BIN_EXE_komorebi"))
|
|
.env("DBUS_SESSION_BUS_ADDRESS", NO_BUS)
|
|
.env("XDG_RUNTIME_DIR", &runtime)
|
|
.env("HOME", &runtime)
|
|
.env_remove("XDG_DATA_HOME")
|
|
.output()
|
|
.expect("komorebi runs");
|
|
let _ = std::fs::remove_dir_all(&runtime);
|
|
|
|
assert_eq!(output.status.code(), Some(1));
|
|
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
assert!(
|
|
stderr.contains("could not connect to the session bus as org.komorebi.Bridge"),
|
|
"{stderr}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn without_kwin_komorebi_leaves_the_socket_it_finds_alone() {
|
|
let runtime = runtime("socket");
|
|
let socket = Path::new(&runtime).join("komorebi").join("komorebi.sock");
|
|
std::fs::create_dir_all(socket.parent().unwrap()).unwrap();
|
|
// the socket of the komorebi that is running
|
|
let running = UnixListener::bind(&socket).unwrap();
|
|
|
|
let output = Command::new(env!("CARGO_BIN_EXE_komorebi"))
|
|
.env("DBUS_SESSION_BUS_ADDRESS", NO_BUS)
|
|
.env("XDG_RUNTIME_DIR", &runtime)
|
|
.env("HOME", &runtime)
|
|
.env_remove("XDG_DATA_HOME")
|
|
.output()
|
|
.expect("komorebi runs");
|
|
|
|
let still_there = UnixStream::connect(&socket).is_ok();
|
|
drop(running);
|
|
let _ = std::fs::remove_dir_all(&runtime);
|
|
|
|
assert_eq!(output.status.code(), Some(1));
|
|
assert!(still_there, "the socket of the running komorebi was taken");
|
|
}
|
|
|
|
#[test]
|
|
fn with_the_fake_backend_komorebi_runs_without_a_session_bus() {
|
|
let runtime = runtime("fake");
|
|
let mut daemon = Command::new(env!("CARGO_BIN_EXE_komorebi"))
|
|
.args(["--fake-backend", "--log-level", "error"])
|
|
.env("DBUS_SESSION_BUS_ADDRESS", NO_BUS)
|
|
.env("XDG_RUNTIME_DIR", &runtime)
|
|
.env("HOME", &runtime)
|
|
.env_remove("XDG_DATA_HOME")
|
|
.stdout(Stdio::null())
|
|
.stderr(Stdio::null())
|
|
.spawn()
|
|
.expect("komorebi runs");
|
|
|
|
std::thread::sleep(Duration::from_millis(1500));
|
|
let exited = daemon.try_wait().expect("komorebi can be waited for");
|
|
|
|
daemon.kill().expect("komorebi can be stopped");
|
|
daemon.wait().expect("komorebi can be waited for");
|
|
let _ = std::fs::remove_dir_all(&runtime);
|
|
assert!(exited.is_none(), "komorebi exited: {exited:?}");
|
|
}
|