rust/build_system/src/main.rs

90 lines
2.0 KiB
Rust
Raw Normal View History

2023-08-18 14:06:20 +00:00
use std::env;
use std::process;
mod build;
2023-12-20 13:58:43 +00:00
mod clean;
2024-02-26 17:12:12 +00:00
mod clone_gcc;
2023-09-26 14:09:51 +00:00
mod config;
mod info;
2023-08-18 14:06:20 +00:00
mod prepare;
mod rust_tools;
2023-08-18 14:06:20 +00:00
mod rustc_info;
mod test;
2023-08-18 14:06:20 +00:00
mod utils;
const BUILD_DIR: &str = "build";
2023-08-18 14:06:20 +00:00
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:
2024-02-26 17:12:12 +00: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 14:09:51 +00:00
);
2023-08-18 14:06:20 +00:00
}
pub enum Command {
2023-12-21 22:46:41 +00:00
Cargo,
2023-12-20 13:58:43 +00:00
Clean,
2024-02-26 17:12:12 +00:00
CloneGcc,
2023-08-18 14:06:20 +00:00
Prepare,
Build,
Test,
Info,
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() {
2023-12-21 22:46:41 +00:00
Some("cargo") => Command::Cargo,
2023-12-20 13:58:43 +00:00
Some("clean") => Command::Clean,
2023-08-18 14:06:20 +00:00
Some("prepare") => Command::Prepare,
Some("build") => Command::Build,
Some("test") => Command::Test,
Some("info") => Command::Info,
2024-02-26 17:12:12 +00:00
Some("clone-gcc") => Command::CloneGcc,
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::Cargo => rust_tools::run_cargo(),
2023-12-20 13:58:43 +00:00
Command::Clean => clean::run(),
2023-08-18 14:06:20 +00:00
Command::Prepare => prepare::run(),
Command::Build => build::run(),
Command::Test => test::run(),
Command::Info => info::run(),
2024-02-26 17:12:12 +00:00
Command::CloneGcc => clone_gcc::run(),
2023-08-18 14:06:20 +00:00
} {
eprintln!("Command failed to run: {e}");
2023-08-18 14:06:20 +00:00
process::exit(1);
}
}