use std::path::Path;
#[derive(Debug, Clone, Copy, Default)]
pub struct MapOptions {
pub hash_reuse: bool,
pub no_semantic: bool,
}
impl MapOptions {
pub fn from_env() -> Self {
MapOptions {
hash_reuse: std::env::var("SCOUT_MTIME_REUSE").as_deref() != Ok("1"),
no_semantic: false,
}
}
}
pub(crate) fn compiler_facts_artifact_present(root: &Path) -> bool {
crate::graph::compiler_facts_json_path(root).exists()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_keeps_semantic_enrichment_on() {
assert!(!MapOptions::default().no_semantic);
assert!(!MapOptions::from_env().no_semantic);
}
#[test]
fn no_semantic_is_independently_settable() {
let opts = MapOptions {
hash_reuse: true,
no_semantic: true,
};
assert!(opts.hash_reuse);
assert!(opts.no_semantic);
}
#[test]
fn compiler_facts_artifact_present_checks_disk_only_never_parses() {
let n = std::sync::atomic::AtomicU64::new(0);
let dir = std::env::temp_dir().join(format!(
"scout-mapopts-test-{}-{}",
std::process::id(),
n.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
));
std::fs::create_dir_all(&dir).expect("create temp dir");
assert!(!compiler_facts_artifact_present(&dir));
let path = crate::graph::compiler_facts_json_path(&dir);
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent).expect("create artifact parent dir");
}
std::fs::write(&path, b"not json").expect("write artifact stub");
assert!(compiler_facts_artifact_present(&dir));
std::fs::remove_dir_all(&dir).ok();
}
}