1
//!
2
//! xtask building block operations such as copy, remove, confirm, and more
3
//!
4
//!
5

            
6
#![forbid(unsafe_code)]
7

            
8
use std::env;
9
use std::error::Error;
10
use std::process::ExitCode;
11
use std::str::FromStr;
12

            
13
use benchmark::Rewriter;
14

            
15
mod benchmark;
16
mod coverage;
17
mod sanitizer;
18

            
19
fn main() -> Result<ExitCode, Box<dyn Error>> {
20
    let mut args = env::args();
21

            
22
    // Ignore the first argument (which should be xtask)
23
    args.next();
24

            
25
    // The name of the task
26
    let task = args.next();
27

            
28
    match task.as_deref() {
29
        Some("benchmark") => {
30
            if let Some(rewriter) = args.next() {
31
                // Use the upstream mcrl2
32
                if let Some(output_path) = args.next() {
33
                    benchmark::benchmark(output_path, Rewriter::from_str(&rewriter)?)?
34
                } else {
35
                    println!("Missing argument for output file");
36
                    return Ok(ExitCode::FAILURE);
37
                }
38
            } else {
39
                println!("Missing argument for rewriter");
40
                return Ok(ExitCode::FAILURE);
41
            }
42
        }
43
        Some("create-table") => {
44
            if let Some(input_path) = args.next() {
45
                benchmark::create_table(input_path)?;
46
            } else {
47
                println!("Missing argument for input file");
48
                return Ok(ExitCode::FAILURE);
49
            }
50
        }
51
        Some("coverage") => {
52
            // Take the other parameters for cargo.
53
            let other_arguments: Vec<String> = args.collect();
54
            coverage::coverage(other_arguments)?
55
        }
56
        Some("address-sanitizer") => {
57
            // Take the other parameters for cargo.
58
            let other_arguments: Vec<String> = args.collect();
59
            sanitizer::address_sanitizer(other_arguments)?
60
        }
61
        Some("thread-sanitizer") => {
62
            // Take the other parameters for cargo.
63
            let other_arguments: Vec<String> = args.collect();
64
            sanitizer::thread_sanitizer(other_arguments)?
65
        }
66
        Some(x) => {
67
            println!("Unknown task {x}");
68
            println!();
69
            print_help();
70
            return Ok(ExitCode::FAILURE);
71
        }
72
        _ => print_help(),
73
    }
74

            
75
    Ok(ExitCode::SUCCESS)
76
}
77

            
78
fn print_help() {
79
    println!("Available tasks: benchmark, coverage, address-sanitizer, thread-sanitizer");
80
}