47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
fn collect_rs_files(dir: &Path, out: &mut Vec<PathBuf>) {
|
|
if let Ok(entries) = fs::read_dir(dir) {
|
|
for e in entries.flatten() {
|
|
let path = e.path();
|
|
if path.is_dir() {
|
|
collect_rs_files(&path, out);
|
|
} else if path.extension().and_then(|s| s.to_str()) == Some("rs") {
|
|
out.push(path);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn backend_must_not_import_pbs() {
|
|
let crate_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
let backend_dir = crate_root.join("src").join("backend");
|
|
if !backend_dir.exists() { return; }
|
|
|
|
let mut files = Vec::new();
|
|
collect_rs_files(&backend_dir, &mut files);
|
|
|
|
let mut offenders = Vec::new();
|
|
for f in files {
|
|
if let Ok(src) = fs::read_to_string(&f) {
|
|
if src.contains("frontends::pbs") || src.contains("crate::frontends::pbs") {
|
|
offenders.push(f);
|
|
}
|
|
}
|
|
}
|
|
|
|
if !offenders.is_empty() {
|
|
let list = offenders
|
|
.iter()
|
|
.map(|p| p.strip_prefix(&crate_root).unwrap_or(p).display().to_string())
|
|
.collect::<Vec<_>>()
|
|
.join("\n - ");
|
|
panic!(
|
|
"Backend must not import PBS modules (frontends::pbs). Offending files:\n - {}",
|
|
list
|
|
);
|
|
}
|
|
}
|