#[cfg(feature = "test-fixtures")]
mod fixture_staging {
use std::path::{Path, PathBuf};
const FORMATS: [&str; 3] = ["pdf", "rmd", "html"];
fn is_ragrig_state(name: &str) -> bool {
name.starts_with(".ragrig")
}
fn stage_fixture(src: &Path, dst: &Path) {
std::fs::create_dir_all(dst)
.unwrap_or_else(|e| panic!("ragrig build.rs: create {}: {e}", dst.display()));
for entry in std::fs::read_dir(src)
.unwrap_or_else(|e| panic!("ragrig build.rs: read {}: {e}", src.display()))
{
let entry = entry
.unwrap_or_else(|e| panic!("ragrig build.rs: entry in {}: {e}", src.display()));
let name = entry.file_name();
let name = name.to_string_lossy().into_owned();
if is_ragrig_state(&name) {
continue;
}
let from = entry.path();
let to = dst.join(&name);
let ty = entry
.file_type()
.unwrap_or_else(|e| panic!("ragrig build.rs: type of {}: {e}", from.display()));
if ty.is_dir() {
stage_fixture(&from, &to);
} else if ty.is_file() {
std::fs::copy(&from, &to).unwrap_or_else(|e| {
panic!(
"ragrig build.rs: copy {} -> {}: {e}",
from.display(),
to.display()
)
});
}
}
}
pub fn stage_fixtures() {
let out =
PathBuf::from(std::env::var_os("OUT_DIR").expect("ragrig build.rs: OUT_DIR not set"));
let root = Path::new("tests/fixtures/formats");
for fmt in FORMATS {
stage_fixture(&root.join(fmt), &out.join("fixtures").join(fmt));
}
}
}
fn main() {
println!("cargo:rerun-if-changed=tests/fixtures/formats");
#[cfg(feature = "lancedb")]
{
if std::env::var("PROTOC").is_err() {
let found = std::process::Command::new("protoc")
.arg("--version")
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if !found {
eprintln!(
"\n==================================================\n\
protoc not found in PATH.\n\n\
Install it:\n\
Linux: sudo apt-get install protobuf-compiler\n\
macOS: brew install protobuf\n\
Windows: https://github.com/protocolbuffers/protobuf/releases\n\n\
Or set PROTOC=/path/to/protoc\n\
==================================================\n"
);
std::process::exit(1);
}
}
}
#[cfg(feature = "test-fixtures")]
fixture_staging::stage_fixtures();
}