Files
benilla-octo/crates/benilla-formats/tests/project_folder.rs
T
Sam SungandClaude Opus 5.5 6633a11d60 A dev build of a crate on top of benilla finds its install, benilla-config/ and .probe-identity in its own folder, which its build stamp hands in, not in cargo's checkout of benilla (#504)
A dev build finds its project folder, where its `WoW` link, `benilla-config/` and `.probe-identity` live, from its launcher, not from a benilla crate's own `CARGO_MANIFEST_DIR`. For a crate built on top of benilla, where benilla is a git dependency, that manifest dir is cargo's checkout of benilla.

- `benilla_buildstamp::emit()` stamps `BENILLA_PROJECT_DIR`, the launcher's workspace root (the nearest folder up holding `Cargo.lock`), only when the launcher's `dev` feature is on. A player build stamps it empty and carries no source path. The shims pass it in as `BuildId::project_dir`.
- `benilla_formats::project_folder` is the one home for the folder. Each entry point records the stamped folder once, before anything resolves from it. The install's dev rung, the state folder (which keeps its step from a linked worktree to the primary checkout) and the probe identity all read it. With nothing recorded (a test, an example, a tool) it is benilla's checkout, as before, and in a player build it is `None`.
- Live `assets/ui` and the addon corpus stay on benilla's own source.
- The example launcher's header now says a dev build of a crate on top keeps these in its own folder.
- The comment above the stamp's resource names the build banner, the stamp's reader beside the panel footer.

Fixes #494
Fixes #493

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 14:55:24 +07:00

46 lines
1.8 KiB
Rust

//! A launcher's recorded project folder is where a dev build looks for the install, in place of
//! benilla's checkout, while the addon corpus stays benilla's. Recording is process-wide and every
//! test resolves through it, so this one test has a file, and so a process, of its own.
use std::path::Path;
#[test]
fn a_recorded_launcher_folder_is_where_a_dev_build_looks() {
let tmp = std::env::temp_dir().join(format!("benilla-project-{}", std::process::id()));
std::fs::create_dir_all(&tmp).unwrap();
// This process's own environment: `WOW_DATA=` would empty the ladder, and an override would
// move the corpus.
std::env::remove_var("WOW_DATA");
std::env::remove_var("BENILLA_ADDON_CORPUS");
let checkout = Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.unwrap();
// A player build's stamp is empty and records nothing.
benilla_formats::set_project_folder("");
if cfg!(feature = "dev") {
assert_eq!(benilla_formats::project_folder(), Some(checkout));
}
benilla_formats::set_project_folder(tmp.to_str().unwrap());
benilla_formats::set_project_folder("/a/later/call/changes/nothing");
if cfg!(feature = "dev") {
assert_eq!(benilla_formats::project_folder(), Some(tmp.as_path()));
let c = benilla_formats::candidates();
assert_eq!(c.first(), Some(&tmp.join("WoW/Data")), "{c:?}");
assert!(
!c.contains(&checkout.join("WoW/Data")),
"benilla's checkout is still looked in for the install: {c:?}"
);
assert_eq!(
benilla_formats::addon_corpus_candidates(),
vec![checkout.join("wow-addons-vanilla")],
"the corpus is benilla's whoever the launcher is"
);
} else {
assert_eq!(benilla_formats::project_folder(), None);
}
std::fs::remove_dir_all(&tmp).ok();
}