From ab4d83bf345da8b561fe504a81e1edb8ab555530 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 16:25:55 +0200 Subject: [PATCH] Add initial version of validator This initial version just exports each model, failing if there's an error. Eventually, it should also validate the exported 3MF file. But the current version is already useful, and can replace the manually specified model export steps in the CI build. --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + tools/validator/Cargo.toml | 7 +++++++ tools/validator/src/main.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 tools/validator/Cargo.toml create mode 100644 tools/validator/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 660d0fb11..cfc8c07e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2789,6 +2789,13 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "validator" +version = "0.1.0" +dependencies = [ + "anyhow", +] + [[package]] name = "valuable" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1b41354cd..0802afc10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "models/star", "tools/release-operator", + "tools/validator", ] default-members = [ "crates/fj-app", diff --git a/tools/validator/Cargo.toml b/tools/validator/Cargo.toml new file mode 100644 index 000000000..cf6ae2fee --- /dev/null +++ b/tools/validator/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "validator" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.56" diff --git a/tools/validator/src/main.rs b/tools/validator/src/main.rs new file mode 100644 index 000000000..06cb4096a --- /dev/null +++ b/tools/validator/src/main.rs @@ -0,0 +1,27 @@ +use std::{fs, process::Command}; + +use anyhow::{anyhow, bail}; + +fn main() -> anyhow::Result<()> { + for model in fs::read_dir("models")? { + let model = model?; + let model = model.file_name().into_string().map_err(|err| { + anyhow!("Failed to convert directory name to `String`: {:?}", err) + })?; + + let export_file = format!("{model}.3mf"); + + let exit_status = Command::new("cargo") + .arg("run") + .arg("--") + .args(["--model", &model]) + .args(["--export", &export_file]) + .status()?; + + if !exit_status.success() { + bail!("Exporting model failed with error status: {}", exit_status); + } + } + + Ok(()) +}