specjam_codegen/
lib.rs

1//! Code generation scripts for embedding the jam test vectors into
2
3use anyhow::Result;
4pub use registry::Registry;
5use std::{path::Path, process::Command};
6
7mod registry;
8
9/// The repo of the jam test vectors
10pub const REPO: &str = "https://github.com/spacejamapp/jam-test-vectors.git";
11
12/// The scale of the test vectors
13#[cfg(not(feature = "full"))]
14pub const SCALE: &[&str] = &["tiny"];
15
16/// The scale of the test vectors
17#[cfg(feature = "full")]
18pub const SCALE: &[&str] = &["tiny", "full"];
19
20/// Run the code generator
21pub fn run(vectors: &Path, output: &Path) -> Result<()> {
22    Registry::new(vectors, output).run()
23}
24
25/// Download the jam test vectors
26pub fn download(target: &Path) -> Result<()> {
27    if target.exists() {
28        return Ok(());
29    }
30
31    Command::new("git")
32        .args([
33            "clone",
34            REPO,
35            target.to_str().expect("target is not a valid path"),
36            "--depth=1",
37        ])
38        .status()?;
39    Ok(())
40}
41
42/// Get the head hash of the test vectors
43pub fn head(target: &Path) -> Result<String> {
44    let hash = Command::new("git")
45        .args(["rev-parse", "HEAD"])
46        .current_dir(target)
47        .output()?
48        .stdout;
49    Ok(String::from_utf8(hash)?)
50}