100 lines
3.4 KiB
Rust
100 lines
3.4 KiB
Rust
use std::env::{set_current_dir as cd, set_var};
|
|
|
|
mod cli;
|
|
mod db;
|
|
mod backend;
|
|
mod log;
|
|
mod task;
|
|
|
|
use log::Context;
|
|
|
|
fn main() -> Result<(), std::io::Error> {
|
|
let mut context = Context::new();
|
|
let (cmd, basedir) = cli::Cli::build();
|
|
context.insert("$i18n_basedir".to_string(), basedir.to_str().unwrap().to_string());
|
|
let basedir_str = basedir.to_str().unwrap().to_string();
|
|
|
|
set_var("GITBUILDDIR", &basedir);
|
|
|
|
let mut tasks = if cmd.tasks.is_empty() {
|
|
log::info("no_task", &context);
|
|
task::from_dir(&basedir, &context).expect("Could not load DB")
|
|
} else {
|
|
match task::from_dir_and_list(&basedir, cmd.tasks, &context) {
|
|
Ok(t) => t,
|
|
Err(task::MissingTask(t)) => {
|
|
// Temporarily override the global context
|
|
let mut context = context.clone();
|
|
context.insert("$i18n_arg".to_string(), t);
|
|
log::error("unknown_arg", &context);
|
|
std::process::exit(1);
|
|
}
|
|
|
|
}
|
|
};
|
|
|
|
// Reorder tasks alphanumerically
|
|
tasks.sort_unstable_by_key(|t| t.name.clone());
|
|
// Remove duplicates, in case a task was called along
|
|
// the corresponding source URL (so we'd be tempted to call the task twice)
|
|
tasks.dedup_by_key(|t| t.name.clone());
|
|
|
|
for t in &tasks {
|
|
t.debug("found_task");
|
|
}
|
|
|
|
let (config_folder, ignored_tasks) = task::config(&basedir);
|
|
set_var("FORGEBUILDCONF", &config_folder);
|
|
context.insert("$i18n_config".to_string(), config_folder.to_str().unwrap().to_string());
|
|
log::info("config", &context);
|
|
|
|
for task in &tasks {
|
|
task.debug("start_proc");
|
|
|
|
if ignored_tasks.contains(&task.name) {
|
|
// Skip task which has CONFIG/task.ignore
|
|
continue;
|
|
}
|
|
|
|
task.info("process");
|
|
|
|
// Maybe the task has a source we should clone?
|
|
if let Some(repo) = &task.repo {
|
|
let source_dir = format!("{}/.{}", basedir_str, &task.name);
|
|
if task.cloned == false {
|
|
task.info("clone");
|
|
if !repo.download() {
|
|
task.error("clone_failed");
|
|
// Skip further processing
|
|
continue;
|
|
}
|
|
|
|
// New repo just cloned. Check for submodule updates
|
|
cd(&source_dir).expect("Failed to change working dir");
|
|
if task.subupdates {
|
|
let _had_subupdates = repo.subupdate();
|
|
}
|
|
|
|
// Checkout specific branch?
|
|
// TODO: To avoid submodule inconsistencies between branches, we should directly clone a specific branch
|
|
task.checkout();
|
|
task.run();
|
|
} else {
|
|
// So the cloned repo is already here maybe update?
|
|
// Let's say there was an update and run
|
|
//println!("Task {} already exists, run i t only if updates", task.name);
|
|
cd(&source_dir).expect("Failed to change working dir");
|
|
task.checkout();
|
|
task.update_and_run(&cmd.force);
|
|
//task.run();
|
|
}
|
|
} else {
|
|
// No source, chaneg working dir to basedir
|
|
cd(&basedir).expect("Failed to change working dir");
|
|
//println!("Taks {} doesn't have a source, run it", task.name);
|
|
task.run_once();
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|