rust/compiler/rustc_codegen_gcc/build_system/src/main.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.4 KiB
Rust
Raw Normal View History

2023-08-18 14:06:20 +00:00
use std::env;
use std::process;
mod build;
2023-09-26 14:09:51 +00:00
mod config;
2023-08-18 14:06:20 +00:00
mod prepare;
mod rustc_info;
mod test;
2023-08-18 14:06:20 +00:00
mod utils;
macro_rules! arg_error {
($($err:tt)*) => {{
eprintln!($($err)*);
2023-09-25 15:12:40 +00:00
eprintln!();
2023-08-18 14:06:20 +00:00
usage();
std::process::exit(1);
}};
}
fn usage() {
2023-09-26 14:09:51 +00:00
println!(
"\
2023-09-25 15:12:40 +00:00
Available commands for build_system:
prepare : Run prepare command
build : Run build command
test : Run test command
2023-09-26 14:09:51 +00:00
--help : Show this message"
);
2023-08-18 14:06:20 +00:00
}
pub enum Command {
Prepare,
Build,
Test,
2023-08-18 14:06:20 +00:00
}
fn main() {
if env::var("RUST_BACKTRACE").is_err() {
env::set_var("RUST_BACKTRACE", "1");
}
let command = match env::args().nth(1).as_deref() {
Some("prepare") => Command::Prepare,
Some("build") => Command::Build,
Some("test") => Command::Test,
2023-09-25 15:12:40 +00:00
Some("--help") => {
usage();
process::exit(0);
}
2023-08-18 14:06:20 +00:00
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
Some(command) => arg_error!("Unknown command {}", command),
None => {
usage();
process::exit(0);
}
};
if let Err(e) = match command {
Command::Prepare => prepare::run(),
Command::Build => build::run(),
Command::Test => test::run(),
2023-08-18 14:06:20 +00:00
} {
eprintln!("Command failed to run: {e:?}");
process::exit(1);
}
}