build.rs/src/main.rs

68 lines
2.3 KiB
Rust
Raw Normal View History

2020-04-30 16:53:49 +00:00
use std::env;
use std::collections::HashMap;
2020-05-01 10:48:22 +00:00
use structopt::StructOpt;
2020-06-01 14:56:24 +00:00
// For UNIX extended metadata
2020-04-30 16:53:49 +00:00
mod log;
2020-04-30 20:11:06 +00:00
mod db;
2020-04-30 23:45:48 +00:00
mod dvcs;
2020-05-01 10:48:22 +00:00
mod cli;
2020-06-01 14:56:24 +00:00
mod task;
2020-04-30 16:53:49 +00:00
2020-06-01 14:56:24 +00:00
fn main() -> Result<(), std::io::Error> {
2020-05-01 10:48:22 +00:00
let cmd = cli::Cli::from_args();
let base_dir: String = cmd.basedir().to_str().unwrap().into();
2020-05-01 10:48:22 +00:00
2020-11-25 17:49:02 +00:00
std::env::set_var("GITBUILDDIR", &base_dir);
2020-05-01 11:19:33 +00:00
let tasks = if cmd.tasks.is_empty() {
2020-06-10 11:04:35 +00:00
task::from_dir(&base_dir).expect("Could not load DB")
2020-05-01 11:19:33 +00:00
} else {
2020-06-10 11:04:35 +00:00
task::from_dir_and_list(&base_dir, cmd.tasks).expect("Could not load given tasks")
2020-05-01 11:19:33 +00:00
};
let (config_folder, ignored_tasks) = task::config(&std::path::Path::new(&base_dir));
2020-11-25 17:49:02 +00:00
std::env::set_var("GITBUILDCONF", &config_folder);
2020-06-10 11:04:35 +00:00
2020-06-01 14:56:24 +00:00
for (task_name, task) in tasks.iter() {
if ignored_tasks.contains(&task_name) {
// Skip task which has CONFIG/task.ignore
continue;
}
println!("TASK: {:?}", task_name);
2020-04-30 23:45:48 +00:00
let mut context = HashMap::new();
2020-06-01 14:56:24 +00:00
context.insert("$i18n_task", task_name.as_str());
2020-04-30 23:45:48 +00:00
log::debug("found_task", Some(&context));
// Maybe the task has a source we should clone?
if let Some(source) = &task.source {
let source_dir = format!("{}/.{}", base_dir, task_name.as_str());
if task.cloned == false {
if !task.dvcs.clone(source, &source_dir) {
2020-04-30 23:45:48 +00:00
context.insert("$i18n_source", &source);
log::error("clone_failed", Some(&context));
// Skip further processing
2020-05-01 10:48:22 +00:00
continue
2020-04-30 23:45:48 +00:00
}
2020-07-01 15:38:27 +00:00
// New repo just cloned
// TODO: submodule and submodule updates
println!("Downloaded source for {}", task_name);
std::env::set_current_dir(&source_dir);
task.run();
2020-04-30 23:45:48 +00:00
}
// So the cloned repo is already here maybe update?
// Let's say there was an update and run
println!("Task {} already exists, run it", task_name);
std::env::set_current_dir(&source_dir);
task.run();
} else {
// No source, chaneg working dir to basedir
std::env::set_current_dir(&base_dir);
println!("Taks {} doesn't have a source, run it", task_name);
task.run_once();
2020-04-30 23:45:48 +00:00
}
}
2020-06-01 14:56:24 +00:00
Ok(())
2020-04-30 16:53:49 +00:00
}