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.

90 lines
2 KiB
Rust
Raw Normal View History

2023-08-18 16:06:20 +02:00
use std::env;
use std::process;
mod build;
2023-12-21 23:46:41 +01:00
mod cargo;
2023-12-20 14:58:43 +01:00
mod clean;
2024-02-26 18:12:12 +01:00
mod clone_gcc;
2023-09-26 16:09:51 +02:00
mod config;
mod info;
2023-08-18 16:06:20 +02:00
mod prepare;
mod rustc_info;
mod test;
2023-08-18 16:06:20 +02:00
mod utils;
const BUILD_DIR: &str = "build";
2023-08-18 16:06:20 +02:00
macro_rules! arg_error {
($($err:tt)*) => {{
eprintln!($($err)*);
2023-09-25 17:12:40 +02:00
eprintln!();
2023-08-18 16:06:20 +02:00
usage();
std::process::exit(1);
}};
}
fn usage() {
2023-09-26 16:09:51 +02:00
println!(
"\
2023-09-25 17:12:40 +02:00
Available commands for build_system:
2024-02-26 18:12:12 +01:00
cargo : Run cargo command
clean : Run clean command
prepare : Run prepare command
build : Run build command
test : Run test command
info : Run info command
clone-gcc : Run clone-gcc command
--help : Show this message"
2023-09-26 16:09:51 +02:00
);
2023-08-18 16:06:20 +02:00
}
pub enum Command {
2023-12-21 23:46:41 +01:00
Cargo,
2023-12-20 14:58:43 +01:00
Clean,
2024-02-26 18:12:12 +01:00
CloneGcc,
2023-08-18 16:06:20 +02:00
Prepare,
Build,
Test,
Info,
2023-08-18 16:06:20 +02: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() {
2023-12-21 23:46:41 +01:00
Some("cargo") => Command::Cargo,
2023-12-20 14:58:43 +01:00
Some("clean") => Command::Clean,
2023-08-18 16:06:20 +02:00
Some("prepare") => Command::Prepare,
Some("build") => Command::Build,
Some("test") => Command::Test,
Some("info") => Command::Info,
2024-02-26 18:12:12 +01:00
Some("clone-gcc") => Command::CloneGcc,
2023-09-25 17:12:40 +02:00
Some("--help") => {
usage();
process::exit(0);
}
2023-08-18 16:06:20 +02: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 {
2023-12-21 23:46:41 +01:00
Command::Cargo => cargo::run(),
2023-12-20 14:58:43 +01:00
Command::Clean => clean::run(),
2023-08-18 16:06:20 +02:00
Command::Prepare => prepare::run(),
Command::Build => build::run(),
Command::Test => test::run(),
Command::Info => info::run(),
2024-02-26 18:12:12 +01:00
Command::CloneGcc => clone_gcc::run(),
2023-08-18 16:06:20 +02:00
} {
eprintln!("Command failed to run: {e}");
2023-08-18 16:06:20 +02:00
process::exit(1);
}
}