use crate::exception::BuildResult;
use crate::project::Project;
use parking_lot::RwLock;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::sync::Arc;
use crate::identifier::TaskId;
use crate::project::buildable::BuiltByContainer;
pub mod action;
mod any_task;
pub mod create_task;
mod executable;
pub mod flags;
pub mod initialize_task;
mod lazy_task;
pub mod task_container;
pub mod task_executor;
pub mod task_io;
mod task_ordering;
pub mod up_to_date;
pub mod work_handler;
use crate::project::error::ProjectResult;
use crate::task::flags::{OptionDeclarations, OptionsDecoder};
use crate::task::up_to_date::UpToDate;
pub use any_task::AnyTaskHandle;
use create_task::CreateTask;
pub use executable::{force_rerun, Executable};
use initialize_task::InitializeTask;
pub use lazy_task::*;
use task_io::TaskIO;
pub use task_ordering::*;
#[derive(Debug, Clone)]
pub enum TaskOutcome {
Executed,
Skipped,
UpToDate,
NoSource,
Failed,
}
pub trait Task: UpToDate + InitializeTask + CreateTask + TaskIO + Sized + Debug {
fn did_work(&self) -> bool {
true
}
fn task_action(_task: &mut Executable<Self>, _project: &Project) -> BuildResult;
}
pub trait HasTaskId {
fn task_id(&self) -> TaskId;
}
pub trait BuildableTask: HasTaskId {
fn built_by(&self) -> BuiltByContainer {
let mut output = BuiltByContainer::new();
for task_ordering in self.ordering() {
match task_ordering.ordering_kind() {
TaskOrderingKind::DependsOn => {
output.add(task_ordering.buildable().clone());
}
_ => {}
}
}
output
}
fn ordering(&self) -> Vec<TaskOrdering>;
}
pub trait ExecutableTask: HasTaskId + Send + Sync {
fn options_declarations(&self) -> Option<OptionDeclarations>;
fn try_set_from_decoder(&mut self, decoder: &OptionsDecoder) -> ProjectResult<()>;
fn execute(&mut self, project: &Project) -> BuildResult;
fn did_work(&self) -> bool;
fn task_up_to_date(&self) -> bool;
fn group(&self) -> String;
fn description(&self) -> String;
}
assert_obj_safe!(ExecutableTask);
pub trait FullTask: BuildableTask + ExecutableTask + Send + Sync {}
impl Debug for Box<dyn FullTask> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Task {}", self.task_id())
}
}
impl Display for Box<dyn FullTask> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Task {}", self.task_id())
}
}
impl HasTaskId for Box<dyn FullTask> {
fn task_id(&self) -> TaskId {
(**self).task_id()
}
}
impl ExecutableTask for Box<dyn FullTask> {
fn options_declarations(&self) -> Option<OptionDeclarations> {
(**self).options_declarations()
}
fn try_set_from_decoder(&mut self, decoder: &OptionsDecoder) -> ProjectResult<()> {
(**self).try_set_from_decoder(decoder)
}
fn execute(&mut self, project: &Project) -> BuildResult {
(**self).execute(project)
}
fn did_work(&self) -> bool {
(**self).did_work()
}
fn task_up_to_date(&self) -> bool {
(**self).task_up_to_date()
}
fn group(&self) -> String {
(**self).group()
}
fn description(&self) -> String {
(**self).description()
}
}
impl<E: ExecutableTask> HasTaskId for Arc<RwLock<E>> {
fn task_id(&self) -> TaskId {
self.read().task_id()
}
}
impl<E: ExecutableTask + Send + Sync> ExecutableTask for Arc<RwLock<E>> {
fn options_declarations(&self) -> Option<OptionDeclarations> {
self.read().options_declarations()
}
fn try_set_from_decoder(&mut self, decoder: &OptionsDecoder) -> ProjectResult<()> {
self.write().try_set_from_decoder(decoder)
}
fn execute(&mut self, project: &Project) -> BuildResult {
self.write().execute(project)
}
fn did_work(&self) -> bool {
self.read().did_work()
}
fn task_up_to_date(&self) -> bool {
self.read().task_up_to_date()
}
fn group(&self) -> String {
self.read().group()
}
fn description(&self) -> String {
self.read().description()
}
}
impl Debug for Box<dyn FullTask + Send + Sync> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Task {}", self.task_id())
}
}
impl Display for Box<dyn FullTask + Send + Sync> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Task {}", self.task_id())
}
}
impl<F: BuildableTask + ExecutableTask> FullTask for F {}
assert_obj_safe!(FullTask);