From 6779e201d6b23e865facf3ea0c3bbbdd206149c5 Mon Sep 17 00:00:00 2001 From: vakaobr <15154330+vakaobr@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:53:49 -0300 Subject: [PATCH] e2e: under Wine, stage the test title under the target directory's drive path CARGO_TARGET_TMPDIR is the host's path when the tests are built for Windows on macOS or Linux (`/Users/...`). The test process runs under Wine, where a path starting with `/` is a folder of the current drive: from a shell in the home folder (Y: in CrossOver) `/Users/me/...` is `Y:\Users\me\...`, the home folder's own `Users`. So the game and data folders landed outside the target directory and were never removed, and the drives XCL mounts from the data path did not resolve: the test title's `storage: save folder + persistent local storage` (pls dir S:\) and `XPersistentLocalStorage: a drive root` checks failed. target_tmpdir() asks Wine for the drive path of a `/`-path (kernel32's wine_get_dos_file_name). On Windows kernel32 has no such export and the path is used as it is. Measured under CrossOver 26.3 on macOS, test_title_runs_and_game_folder_is_untouched on main 68a284a: both checks fail without this and pass with it, and the run's folder is in the target directory and removed afterwards (without it, it was left in ~/Users//...). --- crates/xcl/tests/e2e.rs | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/xcl/tests/e2e.rs b/crates/xcl/tests/e2e.rs index 027638eee7..a4e084dd13 100644 --- a/crates/xcl/tests/e2e.rs +++ b/crates/xcl/tests/e2e.rs @@ -64,6 +64,42 @@ impl Drop for TempDir { } } +/// `CARGO_TARGET_TMPDIR` as this process can use it. Built under Wine (macOS, Linux) it is the +/// host's path, `/…`, which Windows reads as a folder of the current drive (`/Users/…` from a +/// shell in the home folder is `Y:\Users\…`, the home folder's own `Users`): the test's files +/// land outside the target directory, and the drives XCL mounts from that path (`S:` for +/// persistent local storage) do not resolve. Wine's `wine_get_dos_file_name` gives its drive path. +fn target_tmpdir() -> PathBuf { + let tmp = env!("CARGO_TARGET_TMPDIR"); + if tmp.starts_with('/') { + if let Some(dos) = wine_dos_path(tmp) { + return dos; + } + } + PathBuf::from(tmp) +} + +/// Wine's DOS path for the host path `unix` (None on Windows, where kernel32 has no such export). +fn wine_dos_path(unix: &str) -> Option { + use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress}; + use windows_sys::Win32::System::Memory::{GetProcessHeap, HeapFree}; + let unix = std::ffi::CString::new(unix).ok()?; + // SAFETY: kernel32 is loaded and both names are NUL-terminated; Wine's export takes a + // NUL-terminated host path and returns a NUL-terminated wide string from the process heap. + unsafe { + let f = GetProcAddress(GetModuleHandleA(c"kernel32.dll".as_ptr() as *const u8), c"wine_get_dos_file_name".as_ptr() as *const u8)?; + let f: unsafe extern "system" fn(*const std::ffi::c_char) -> *mut u16 = std::mem::transmute(f); + let w = f(unix.as_ptr()); + if w.is_null() { + return None; + } + let len = (0..).take_while(|&i| *w.add(i) != 0).count(); + let dos = String::from_utf16_lossy(std::slice::from_raw_parts(w, len)); + HeapFree(GetProcessHeap(), 0, w as *const std::ffi::c_void); + Some(PathBuf::from(dos)) + } +} + fn temp_dir(prefix: &str) -> TempDir { static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); let nanos = std::time::SystemTime::now() @@ -71,8 +107,7 @@ fn temp_dir(prefix: &str) -> TempDir { .unwrap() .as_nanos(); let seq = NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - let path = Path::new(env!("CARGO_TARGET_TMPDIR")) - .join(format!("{prefix}-{}-{nanos}-{seq}", std::process::id())); + let path = target_tmpdir().join(format!("{prefix}-{}-{nanos}-{seq}", std::process::id())); let _ = std::fs::remove_dir_all(&path); std::fs::create_dir_all(&path).unwrap(); TempDir(path)