use super::*;
pub(super) fn pch_source_header(path: &Path) -> Option<NormalizedPath> {
let ext = path.extension()?.to_str()?;
if ext != "pch" && ext != "gch" {
return None;
}
let header_name = path.file_stem()?;
let sibling = path.with_file_name(header_name);
if sibling.exists() {
return Some(sibling.into());
}
if let Some(parent) = path.parent() {
if let Some(dir_name) = parent.file_name() {
let relative = NormalizedPath::new(dir_name).join(header_name);
let mut search: NormalizedPath = parent.into();
for _ in 0..10 {
if let Some(up) = search.parent() {
let candidate = up.join(&relative);
if candidate.exists() {
return Some(candidate.into());
}
search = up.into();
} else {
break;
}
}
}
}
None
}
pub(super) fn resolve_pch_source(
path: &Path,
pch_map: &DashMap<NormalizedPath, NormalizedPath>,
) -> Option<NormalizedPath> {
if let Some(src) = pch_map.get(&NormalizedPath::new(path)) {
return Some(src.clone());
}
pch_source_header(path)
}