SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Kernel rig export: operand records in a gzip file beside each entry
jyviko7e3824c0bc1c
diff --git a/Cargo.lock b/Cargo.lockindex ccec6b0152..efcd6f5dac 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5754,6 +5754,7 @@ checksum = "e450f9b2ed1dff33c94c12589a87338689467b9c4f5d8a5710bd09a847d2c8a7"name = "xtask"version = "0.40.0-rc.1"dependencies = [+ "flate2","proc-macro2","quick-xml","serde",diff --git a/xtask/Cargo.toml b/xtask/Cargo.tomlindex 452087caae..14455fd211 100644--- a/xtask/Cargo.toml+++ b/xtask/Cargo.toml@@ -6,6 +6,7 @@ license.workspace = truepublish = false[dependencies]+flate2 = "1.1"proc-macro2 = { workspace = true, features = ["span-locations"] }quick-xml = { workspace = true }serde = { workspace = true }diff --git a/xtask/src/kernel_corpus.rs b/xtask/src/kernel_corpus.rsindex fb366917a6..d3364bfb6f 100644--- a/xtask/src/kernel_corpus.rs+++ b/xtask/src/kernel_corpus.rs@@ -4,7 +4,9 @@//! the fix set, its expected values and the rig's result). This writes what that leaves out://! an entry for each case whose process left none (a hang or a crash, so no trace), each ladder//! case's golden, and `DIR/manifest.json`, the counts per area and every case that is not-//! expressible as kernel input, with its reasons.+//! expressible as kernel input, with its reasons. An entry's operand records go to+//! `<case>.bodies.json.gz` beside it (gzip, no timestamp, so a re-export of the same records is+//! the same bytes); the entry keeps what each body is and names that file.use std::collections::BTreeMap;use std::path::Path;@@ -43,6 +45,29 @@ fn write_json(path: &Path, v: &Value, pretty: bool) -> Result<(), String> {std::fs::write(path, text).map_err(|e| format!("{}: {e}", path.display()))}+/// Moves the records out of `entry`'s `bodies` into the gzip file `to`, `{"b<n>": record}`, and+/// names it in `records`. An entry without records (written before) is left as it is.+fn split_records(entry: &mut Value, to: &Path) -> Result<(), String> {+ use std::io::Write as _;+ let Some(bodies) = entry["bodies"].as_object_mut() else { return Ok(()) };+ let mut records = serde_json::Map::new();+ for (name, b) in bodies.iter_mut() {+ if let Some(r) = b.as_object_mut().and_then(|o| o.remove("record")) {+ records.insert(name.clone(), r);+ }+ }+ if records.is_empty() {+ return Ok(());+ }+ let text = serde_json::to_vec(&Value::Object(records)).map_err(|e| e.to_string())?;+ let mut gz = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::best());+ gz.write_all(&text).map_err(|e| e.to_string())?;+ let bytes = gz.finish().map_err(|e| e.to_string())?;+ std::fs::write(to, bytes).map_err(|e| format!("{}: {e}", to.display()))?;+ entry["records"] = json!(to.file_name().map(|n| n.to_string_lossy().to_string()));+ Ok(())+}+/// What `git args` prints in this checkout.fn git(args: &[&str]) -> String {std::process::Command::new("git")@@ -95,7 +120,8 @@ pub(crate) fn manifest(dir: &Path, results: &[Value], golden: Option<&Value>) ->if let Some(e) = r.get("export_error") {entry["export_error"] = e.clone();}- write_json(&file, &entry, false)?;+ split_records(&mut entry, &dir.join(area).join(format!("{id}.bodies.json.gz")))?;+ write_json(&file, &entry, true)?;}// Every entry in the corpus, this run's or an earlier one's.