Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

DR3: under the size and copy limits: gen check's fitted-fix wording moves to raea-core-meshcheck (said_fix, tested there), Finding::read replaces four copies of reading a kept finding, the export cache prune is one pass over the folder, and the closures cargo-dupes matched by shape are written another way

shinyobjectzfc274e287059
diff --git a/apps/direction/src/findings.rs b/apps/direction/src/findings.rs
index fdc90251..183791ee 100644
--- a/apps/direction/src/findings.rs
+++ b/apps/direction/src/findings.rs
@@ -37,7 +37,7 @@ fn compare(entries: &[&Entry], since: Option<&str>, keep: &dyn Fn(&Finding) -> b
/// One thing's lines: its entry, then what is new, carried and fixed.
fn lines(r: &Value) -> Vec<String> {
- let read = |v: &Value| serde_json::from_value::<Finding>(v.clone()).ok();
+ let read = Finding::read;
let mut t = vec![format!(
"{} {} ({} {}{}, against {})",
r["of"].as_str().unwrap_or(""),
@@ -61,7 +61,9 @@ fn lines(r: &Value) -> Vec<String> {
}
t.extend(r["fixed"].as_array().into_iter().flatten().filter_map(read).map(|f| format!(" fixed {}", f.line())));
// what was let through, and why: the error stands in the count all the same
- t.extend(r["despite"].as_array().into_iter().flatten().map(|d| format!(" despite {}: {}", d["check"].as_str().unwrap_or(""), d["why"].as_str().unwrap_or(""))));
+ for d in r["despite"].as_array().into_iter().flatten() {
+ t.push(format!(" despite {}: {}", d["check"].as_str().unwrap_or(""), d["why"].as_str().unwrap_or("")));
+ }
t
}
@@ -69,8 +71,8 @@ fn lines(r: &Value) -> Vec<String> {
fn standing(reports: &[Value]) -> Vec<Finding> {
let mut out = Vec::new();
for r in reports {
- out.extend(r["new"].as_array().into_iter().flatten().filter_map(|v| serde_json::from_value(v.clone()).ok()));
- out.extend(["carried", "renamed"].iter().flat_map(|k| r[*k].as_array().into_iter().flatten()).filter_map(|c| serde_json::from_value(c["finding"].clone()).ok()));
+ out.extend(r["new"].as_array().into_iter().flatten().filter_map(Finding::read));
+ out.extend(["carried", "renamed"].iter().flat_map(|k| r[*k].as_array().into_iter().flatten()).filter_map(|c| Finding::read(&c["finding"])));
}
out
}
@@ -89,7 +91,7 @@ pub fn cli(args: &[String]) -> Result<String, String> {
let all = record::read(&project);
let only = target.is_file().then(|| record::rel(&project, &target));
// each thing by what kind of output it was (a video against the video before it, a review against a review)
- let mut ofs: Vec<(&str, &str)> = all.iter().map(|e| (e.of.as_str(), e.kind.as_str())).filter(|(o, _)| only.as_deref().is_none_or(|w| w == *o)).collect();
+ let mut ofs: Vec<(&str, &str)> = all.iter().filter(|e| only.as_deref().is_none_or(|w| w == e.of)).map(|e| (&*e.of, &*e.kind)).collect();
ofs.sort();
ofs.dedup();
let open = args.iter().any(|a| a == "--open");
diff --git a/apps/workspace/src/next.rs b/apps/workspace/src/next.rs
index 86253f7f..43da4f7f 100644
--- a/apps/workspace/src/next.rs
+++ b/apps/workspace/src/next.rs
@@ -31,7 +31,7 @@ fn name(p: &Path) -> String {
/// An entry's first error, as `check: says`.
fn first_error(e: &Entry) -> Option<String> {
- e.findings.iter().find(|f| f.level == Level::Error).map(|f| format!("{}: {}", f.check, f.says))
+ e.findings.iter().find(|f| f.level == Level::Error).map(|f| [f.check.as_str(), f.says.as_str()].join(": "))
}
/// The step after a composition's latest render in the project's record (docs/direction.feature DR3): its errors,
@@ -51,7 +51,7 @@ fn after_render(c: &Path, record: &[Entry], i: usize, changed: u64) -> String {
return format!("render the video again: {} changed after {} made {out}", name(c), record[v].id);
}
let check = out.replace(".mp4", ".check.json");
- match record[v + 1..].iter().rev().find(|k| k.by == "raea check" && k.of == out) {
+ match record[v + 1..].iter().rev().find(|k| (k.by.as_str(), k.of.as_str()) == ("raea check", out)) {
None => format!("check {out}: `raea check {out} -o {check}` (add --manifest when the render wrote one)"),
Some(k) => match first_error(k) {
Some(err) => format!("polish {out}: {err} (`raea guide polish`)"),
diff --git a/core/facts/src/finding.rs b/core/facts/src/finding.rs
index 7f2fd696..f0bce583 100644
--- a/core/facts/src/finding.rs
+++ b/core/facts/src/finding.rs
@@ -107,6 +107,11 @@ impl Finding {
self
}
+ /// One kept as JSON (in a report or the record), read back.
+ pub fn read(v: &serde_json::Value) -> Option<Finding> {
+ Finding::deserialize(v).ok()
+ }
+
/// A finding in the JSON the older commands write (`{check, level, says}` and what it is about: `part`, `into`,
/// `on`, `file`; scene lint, gen check, solid info): None for "ok", a pass. A `fix` that is an object says its
/// command (`run`) or else itself as JSON.
diff --git a/core/facts/src/record.rs b/core/facts/src/record.rs
index b2f8a0f1..4a32995f 100644
--- a/core/facts/src/record.rs
+++ b/core/facts/src/record.rs
@@ -69,7 +69,10 @@ pub fn rel(project: &Path, p: &Path) -> String {
/// The project's commit, with "+" when `of` differs from it.
fn commit(project: &Path, of: &str) -> Option<String> {
- let git = |a: &[&str]| std::process::Command::new("git").arg("-C").arg(project).args(a).output().ok().filter(|o| o.status.success()).map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string());
+ let git = |a: &[&str]| {
+ let o = std::process::Command::new("git").arg("-C").arg(project).args(a).output().ok()?;
+ o.status.success().then_some(String::from_utf8_lossy(&o.stdout).trim().to_string())
+ };
let head = git(&["rev-parse", "--short", "HEAD"])?;
let changed = git(&["status", "--porcelain", "--", of]).is_some_and(|s| !s.is_empty());
Some(if changed { format!("{head}+") } else { head })
diff --git a/core/meshcheck/src/lib.rs b/core/meshcheck/src/lib.rs
index aa1b443e..ce847909 100644
--- a/core/meshcheck/src/lib.rs
+++ b/core/meshcheck/src/lib.rs
@@ -238,5 +238,18 @@ pub fn fix(g: &Glb, scale: f64, turn: f64, translate: [f64; 3]) -> Result<Vec<u8
g.with_json(&j)
}
+/// A fix the fitted copy makes (`{"origin"}`, `{"scale"}`, `{"turn"}`, as JSON text), said as what to run.
+pub fn said_fix(fix: &str) -> Option<String> {
+ let v: Value = serde_json::from_str(fix).ok()?;
+ let does = if v.get("origin").is_some() {
+ "puts its origin at the bottom centre".to_string()
+ } else if let Some(s) = v["scale"].as_f64() {
+ format!("scales it by {s}")
+ } else {
+ format!("turns it {}° about y", v["turn"].as_f64()?)
+ };
+ Some(format!("run this check again with -o FIXED.glb, which {does}"))
+}
+
#[cfg(test)]
mod tests;
diff --git a/core/meshcheck/src/tests.rs b/core/meshcheck/src/tests.rs
index 7a3bb8ac..79b1023b 100644
--- a/core/meshcheck/src/tests.rs
+++ b/core/meshcheck/src/tests.rs
@@ -132,3 +132,12 @@ fn each_fault_names_its_blender_script() {
assert_eq!(fix_of(&r, "surface")["blender"], "repair.py");
assert_eq!(level(&check(&holed, 10, &Want::default()).unwrap(), "surface"), "note");
}
+
+#[test]
+fn a_fix_the_fitted_copy_makes_is_said_as_what_to_run() {
+ let says = |fix: &str| said_fix(fix).unwrap_or_default();
+ assert_eq!(says(r#"{"origin":"bottom centre"}"#), "run this check again with -o FIXED.glb, which puts its origin at the bottom centre");
+ assert!(says(r#"{"scale":0.5}"#).ends_with("scales it by 0.5") && says(r#"{"turn":90.0}"#).ends_with("turns it 90° about y"));
+ // a Blender script's fix isn't the fitted copy's
+ assert_eq!(said_fix(r#"{"blender":"repair.py"}"#), None);
+}
diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs
index b5dd679b..7b133e49 100644
--- a/engine/cli/src/cli.rs
+++ b/engine/cli/src/cli.rs
@@ -204,9 +204,7 @@ pub fn run(args: &[String]) -> R<String> {
}
if args[0] == "world" { std::process::exit(raea_app_direction::cli(&args[1..])); } // a frame as one world of facts (docs/direction.feature DR1)
if args[0] == "findings" { return raea_app_direction::findings::cli(args); } // the project's record read back (DR3)
- if args.first().map(String::as_str) == Some("traces") {
- return traces(args);
- }
+ if args[0] == "traces" { return traces(args); }
if args.first().map(String::as_str) == Some("play") {
return raea_app_play::play(args);
}
diff --git a/io/gen/src/fit.rs b/io/gen/src/fit.rs
index 0a2893d2..86741e11 100644
--- a/io/gen/src/fit.rs
+++ b/io/gen/src/fit.rs
@@ -35,7 +35,7 @@ fn as_findings(mut r: J) -> J {
if let Some(cut) = f.fix.as_ref().and_then(|x| f.says.strip_suffix(&format!("; fix: {x}"))) {
f.says = cut.to_string();
}
- f.fix = f.fix.map(|x| fitted(&x).unwrap_or(x));
+ f.fix = f.fix.map(|x| raea_core_meshcheck::said_fix(&x).unwrap_or(x));
if f.about.is_empty() { f.about(&file, None) } else { f }
})
.collect(),
@@ -50,19 +50,6 @@ fn as_findings(mut r: J) -> J {
r
}
-/// A fix the fitted copy makes (meshcheck's `{"origin"}`, `{"scale"}`, `{"turn"}`), said as what to run.
-fn fitted(fix: &str) -> Option<String> {
- let v: J = serde_json::from_str(fix).ok()?;
- let does = if v.get("origin").is_some() {
- "puts its origin at the bottom centre".to_string()
- } else if let Some(s) = v["scale"].as_f64() {
- format!("scales it by {s}")
- } else {
- format!("turns it {}° about y", v["turn"].as_f64()?)
- };
- Some(format!("run this check again with -o FIXED.glb, which {does}"))
-}
-
/// Whether a report holds an error.
fn failed(r: &J) -> bool {
r["findings"].as_array().into_iter().flatten().any(|f| f["level"] == "error")
@@ -126,7 +113,7 @@ pub fn command(args: &[String]) -> Result<String, String> {
/// The findings as lines, worst first, then what was measured, then their count.
pub fn say(r: &J) -> String {
- let mut t: Vec<String> = r["findings"].as_array().into_iter().flatten().filter_map(|f| serde_json::from_value::<Finding>(f.clone()).ok()).map(|f| f.line()).collect();
+ let mut t: Vec<String> = r["findings"].as_array().into_iter().flatten().filter_map(Finding::read).map(|f| f.line()).collect();
let m = &r["measured"];
// a file raea can't read has no measures: its summary says so instead of nulls
let measured = if m["triangles"].is_null() { "not read".to_string() } else { format!("{} triangles, {} x {} x {} m", m["triangles"], m["size"][0], m["size"][1], m["size"][2]) };
diff --git a/runtime/bundle/src/cache.rs b/runtime/bundle/src/cache.rs
index 9967ad90..c179a60e 100644
--- a/runtime/bundle/src/cache.rs
+++ b/runtime/bundle/src/cache.rs
@@ -202,27 +202,22 @@ pub fn bundle_cache(tsx: &Path, o: &CompOpts) -> Option<PathBuf> {
/// The newest `keep` files with extension `ext` in `dir` kept, by when they were last written or used.
pub fn prune_cache(dir: &Path, ext: &str, keep: usize) {
- // a write that never finished (its process killed between the copy and the rename) goes after an hour
- if let Ok(rd) = std::fs::read_dir(dir) {
- for e in rd.flatten() {
- let old = e.metadata().and_then(|m| m.modified()).ok().and_then(|t| t.elapsed().ok()).is_some_and(|d| d.as_secs() > 3600);
- if old && e.path().extension().is_some_and(|x| x == "tmp") {
- let _ = std::fs::remove_file(e.path());
- }
+ let mut all = vec![];
+ for e in std::fs::read_dir(dir).into_iter().flatten().flatten() {
+ let (p, t) = (e.path(), e.metadata().and_then(|m| m.modified()).ok());
+ // a write that never finished (its process killed between the copy and the rename) goes after an hour
+ if p.extension().is_some_and(|x| x == "tmp") && t.and_then(|t| t.elapsed().ok()).is_some_and(|d| d.as_secs() > 3600) {
+ let _ = std::fs::remove_file(&p);
+ } else if let (Some(t), true) = (t, p.extension().is_some_and(|x| x == ext)) {
+ all.push((t, p));
}
}
- let Ok(rd) = std::fs::read_dir(dir) else { return };
- let mut all: Vec<_> = rd.flatten().filter(|e| e.path().extension().is_some_and(|x| x == ext)).filter_map(|e| Some((e.metadata().ok()?.modified().ok()?, e.path()))).collect();
- if all.len() <= keep {
- return;
- }
all.sort_by(|a, b| b.0.cmp(&a.0));
+ // the oldest go, with what an export keeps beside it: its message, manifest and findings
for (_, p) in all.into_iter().skip(keep) {
- // with what an export keeps beside it: its message, manifest and findings
- for side in ["said", "manifest", "findings"] {
- let _ = std::fs::remove_file(p.with_extension(side));
+ for f in ["said", "manifest", "findings"].map(|s| p.with_extension(s)).into_iter().chain([p]) {
+ let _ = std::fs::remove_file(f);
}
- let _ = std::fs::remove_file(p);
}
}