use super::CompilerFamily;
pub(crate) const SOURCE_EXTENSIONS: &[&str] = &[
"c", "cc", "cpp", "cxx", "c++", "C", "m", "mm", "i", "ii", "cppm", "ixx",
];
pub(crate) const MODULE_EXTENSIONS: &[&str] = &["cppm", "ixx"];
#[must_use]
pub fn detect_family(compiler: &str) -> CompilerFamily {
let basename = compiler.rsplit(['/', '\\']).next().unwrap_or(compiler);
let name = match basename.rsplit_once('.') {
Some((stem, _)) => stem,
None => basename,
};
if name == "rustfmt" || name.starts_with("rustfmt-") {
CompilerFamily::Rustfmt
} else if name == "rustc"
|| name.starts_with("rustc-")
|| name == "clippy-driver"
|| name.starts_with("clippy-driver-")
{
CompilerFamily::Rustc
} else if is_clang_cl_name(name) {
CompilerFamily::Msvc
} else if name.contains("clang") || name == "emcc" || name == "em++" {
CompilerFamily::Clang
} else if name.eq_ignore_ascii_case("cl") {
CompilerFamily::Msvc
} else {
CompilerFamily::Gcc
}
}
pub(crate) fn is_clang_cl_name(name: &str) -> bool {
let lower = name.to_ascii_lowercase();
lower == "clang-cl" || lower.starts_with("clang-cl-")
}
pub(crate) fn is_source_file(path: &str) -> bool {
if let Some(ext) = std::path::Path::new(path)
.extension()
.and_then(|e| e.to_str())
{
SOURCE_EXTENSIONS.contains(&ext)
} else {
false
}
}