use crate::graph::Product;
use crate::object_store::{ExplainAction, ObjectStore};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ProductAction {
Skip,
Restore,
Build,
}
pub(crate) trait BuildPolicy: Sync + Send {
fn classify(
&self,
product: &Product,
object_store: &ObjectStore,
input_checksum: &str,
dep_changed: bool,
force: bool,
) -> ProductAction;
fn explain(
&self,
product: &Product,
object_store: &ObjectStore,
input_checksum: &str,
force: bool,
) -> ExplainAction;
}
pub(crate) struct IncrementalPolicy;
impl BuildPolicy for IncrementalPolicy {
fn classify(
&self,
product: &Product,
object_store: &ObjectStore,
input_checksum: &str,
dep_changed: bool,
force: bool,
) -> ProductAction {
let desc_key = product.descriptor_key(input_checksum);
let needs_rebuild = object_store.needs_rebuild_descriptor(&desc_key, &product.outputs);
let can_restore = object_store.can_restore_descriptor(&desc_key);
if !force && !dep_changed && !needs_rebuild {
ProductAction::Skip
} else if !force && !dep_changed && can_restore {
ProductAction::Restore
} else {
ProductAction::Build
}
}
fn explain(
&self,
product: &Product,
object_store: &ObjectStore,
input_checksum: &str,
force: bool,
) -> ExplainAction {
let desc_key = product.descriptor_key(input_checksum);
object_store.explain_descriptor(&desc_key, &product.outputs, force)
}
}