Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/victory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ fn show_config() -> Result<()> {
);
println!("game_dir : {}", status(&cfg.game_dir));
println!("cache_dir : {}", cfg.cache_dir.display());
println!("data_dir : {}", cfg.data_dir.display());
for t in &cfg.test_titles {
println!("test_title : {}", status(&Some(t.clone())));
}
for p in cfg
.game_dir
.iter()
.chain(&cfg.test_titles)
.chain([&cfg.cache_dir])
.chain([&cfg.cache_dir, &cfg.data_dir])
{
if let Err(e) = victory_core::ensure_outside_repo(p) {
println!("POLICY VIOLATION: {e}");
Expand Down
32 changes: 25 additions & 7 deletions apps/victory/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ use victory_shader::{io, resource};

use crate::shader::{MAX_FILE, Source, sources};

/// Resolved `VICTORY_EMIT_DUMP` folder, refused if it points inside a VIctory
/// source tree (enforcing `docs/asset-policy.md`).
fn emit_dump_dir() -> Option<&'static Path> {
static DIR: std::sync::OnceLock<Option<PathBuf>> = std::sync::OnceLock::new();
DIR.get_or_init(|| {
let dir = PathBuf::from(std::env::var_os("VICTORY_EMIT_DUMP")?);
if let Err(e) = victory_core::ensure_outside_repo(&dir) {
eprintln!("refusing VICTORY_EMIT_DUMP: {e}");
return None;
}
Some(dir)
})
.as_deref()
}

#[derive(Default)]
struct Tally {
containers: usize,
Expand Down Expand Up @@ -422,14 +437,14 @@ fn check(
}
// `VICTORY_EMIT_DUMP` with `--list`: every emitted shader as a file.
if t.list
&& let Ok(dir) = std::env::var("VICTORY_EMIT_DUMP")
&& let Some(dir) = emit_dump_dir()
{
let name: String = label()
.chars()
.map(|c| if c.is_ascii_alphanumeric() { c } else { '_' })
.collect();
let _ = std::fs::write(
format!("{dir}/{}.dxil", &name[name.len().saturating_sub(100)..]),
dir.join(format!("{}.dxil", &name[name.len().saturating_sub(100)..])),
&shader.dxil,
);
}
Expand Down Expand Up @@ -466,22 +481,25 @@ fn check(
.find(|l| l.contains("error"))
.unwrap_or(text.lines().next().unwrap_or(""))
.to_owned();
if let Ok(dir) = std::env::var("VICTORY_EMIT_DUMP") {
if let Some(dir) = emit_dump_dir() {
let n = t
.failed
.get(&format!("validator: {first}"))
.map_or(0, |f| f.0);
if n < 3 {
let name = format!(
"{dir}/{}_{n}",
let stem = format!(
"{}_{n}",
first
.chars()
.filter(char::is_ascii_alphanumeric)
.take(40)
.collect::<String>()
);
let _ = std::fs::write(format!("{name}.dxil"), &shader.dxil);
let _ = std::fs::write(format!("{name}.txt"), format!("{}\n{text}", label()));
let _ = std::fs::write(dir.join(format!("{stem}.dxil")), &shader.dxil);
let _ = std::fs::write(
dir.join(format!("{stem}.txt")),
format!("{}\n{text}", label()),
);
}
}
t.fail(format!("validator: {first}"), label);
Expand Down
10 changes: 10 additions & 0 deletions crates/victory-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ mod tests {
};
assert!(cfg.cache_subdir("x").is_err());
}

#[test]
fn data_inside_repo_is_refused() {
let inside = Path::new(env!("CARGO_MANIFEST_DIR")).join("data");
let cfg = Config {
data_dir: inside,
..Default::default()
};
assert!(cfg.data_subdir("x").is_err());
}
}
Loading