-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.rs
66 lines (54 loc) · 1.93 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
mod clean;
mod cli;
mod config;
mod domain;
mod engine;
use anyhow::{Context, Result};
use clean::clean_target_outputs;
use config::Config;
use engine::incremental::IncrementalRunner;
use engine::Engine;
use std::path::Path;
fn main() -> Result<()> {
let arg_matches = cli::get_app().get_matches();
stderrlog::new()
.module(module_path!())
.verbosity(arg_matches.occurrences_of(cli::arg::VERBOSITY) as usize + 2)
.init()
.unwrap();
if arg_matches.is_present(cli::arg::GENERATE_ZSH_COMPLETION) {
cli::write_zsh_completion(&mut std::io::stdout());
return Ok(());
}
let project_dir = Path::new(arg_matches.value_of(cli::arg::PROJECT_DIR).unwrap());
let config = Config::load(project_dir)?;
let all_target_names = config.get_target_names();
let arg_matches = cli::get_app()
.mut_arg(cli::arg::TARGETS, |arg| {
arg.possible_values(&all_target_names)
.required_unless(cli::arg::CLEAN)
})
.get_matches();
let requested_targets = arg_matches.values_of_lossy(cli::arg::TARGETS);
let targets = config.into_targets(project_dir, &requested_targets)?;
let checksum_dir = project_dir.join(".zinoma");
let incremental_runner = IncrementalRunner::new(&checksum_dir);
if arg_matches.is_present(cli::arg::CLEAN) {
incremental_runner.clean_checksums(&targets)?;
clean_target_outputs(&targets)?;
}
if requested_targets.is_some() {
let engine = Engine::new(targets, incremental_runner);
crossbeam::scope(|scope| {
if arg_matches.is_present(cli::arg::WATCH) {
engine.watch(scope).with_context(|| "Watch error")
} else {
engine.build(scope).with_context(|| "Build error")
}
})
.map_err(|_| {
anyhow::anyhow!("Unknown crossbeam parallelism failure (thread panicked)")
})??;
}
Ok(())
}