use anyhow::{Context as _, Result};
use std::path::PathBuf;
use crate::cli::pipeline;
pub(crate) fn report_deferred_formatting(crate_name: &str, deferred: &[crate::e2e::format::DeferredFormatting]) {
crate::e2e::format::warn_deferred_for_crate(crate_name, deferred);
}
pub(crate) fn snippet_validation_needs_build_artifacts(validation_level: Option<&str>) -> bool {
matches!(
validation_level.map(str::to_ascii_lowercase).as_deref(),
Some("typecheck" | "compile" | "run")
)
}
pub(crate) fn warn_if_snippet_validation_needs_build(config: &crate::core::config::ResolvedCrateConfig) {
let Some(level) = config
.docs
.as_ref()
.and_then(|docs| docs.snippets.as_ref())
.and_then(|snippets| snippets.validation_level.as_deref())
else {
return;
};
if !snippet_validation_needs_build_artifacts(Some(level)) {
return;
}
tracing::warn!(
"[{}] docs.snippets.validation_level = \"{level}\" checks snippets against built language \
artifacts, but `alef all` does not build them -- run `alef build` first. If those artifacts \
are missing or stale, snippet validation fails with per-snippet toolchain errors whose real \
cause is the missing build, not the snippet.",
config.name
);
}
pub(crate) fn refused_snippet_dir_paths(
refused_paths: &std::collections::BTreeSet<PathBuf>,
config: &crate::core::config::ResolvedCrateConfig,
base_dir: &std::path::Path,
) -> Vec<PathBuf> {
let Some(snippet_cfg) = config.docs.as_ref().and_then(|docs| docs.snippets.as_ref()) else {
return Vec::new();
};
let snippet_dirs: Vec<PathBuf> = snippet_cfg
.dirs
.iter()
.chain(&snippet_cfg.inline_dirs)
.map(|dir| base_dir.join(dir))
.collect();
if snippet_dirs.is_empty() {
return Vec::new();
}
let excluded: Vec<PathBuf> = snippet_cfg.exclude.iter().map(|dir| base_dir.join(dir)).collect();
refused_paths
.iter()
.filter(|path| snippet_dirs.iter().any(|dir| path.starts_with(dir)))
.filter(|path| !excluded.iter().any(|prefix| path.starts_with(prefix)))
.cloned()
.collect()
}
pub(crate) fn sync_registry_versions_before_all(
config_path: &std::path::Path,
configs: &[&crate::core::config::ResolvedCrateConfig],
) -> Result<bool> {
let mut versions = std::collections::BTreeSet::new();
for config in configs {
let version = config.resolved_version().with_context(|| {
format!(
"could not resolve version for crate `{}` from {}",
config.name, config.version_from
)
})?;
versions.insert(version);
}
anyhow::ensure!(
versions.len() <= 1,
"alef all cannot synchronize one registry config from multiple crate versions: {}",
versions.iter().cloned().collect::<Vec<_>>().join(", ")
);
let Some(version) = versions.into_iter().next() else {
return Ok(false);
};
pipeline::sync_registry_package_versions(config_path, &version)
}
pub(crate) fn create_once_overwrite(clean: bool, clobber_create_once_seeds: bool) -> bool {
let _ = clean;
clobber_create_once_seeds
}