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;
|
2024-02-12 19:55:14 +00:00
|
|
|
mod info;
|
2023-08-18 14:06:20 +00:00
|
|
|
mod prepare;
|
2024-04-05 15:18:55 +00:00
|
|
|
mod rust_tools;
|
2023-08-18 14:06:20 +00:00
|
|
|
mod rustc_info;
|
2023-10-24 15:15:18 +00:00
|
|
|
mod test;
|
2023-08-18 14:06:20 +00:00
|
|
|
mod utils;
|
|
|
|
|
2024-02-13 20:26:14 +00:00
|
|
|
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,
|
2023-10-24 15:15:18 +00:00
|
|
|
Test,
|
2024-02-12 19:55:14 +00:00
|
|
|
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,
|
2023-10-24 15:15:18 +00:00
|
|
|
Some("test") => Command::Test,
|
2024-02-12 19:55:14 +00:00
|
|
|
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 {
|
2024-04-05 15:18:55 +00:00
|
|
|
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(),
|
2023-10-24 15:15:18 +00:00
|
|
|
Command::Test => test::run(),
|
2024-02-12 19:55:14 +00:00
|
|
|
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
|
|
|
} {
|
2023-11-21 15:29:32 +00:00
|
|
|
eprintln!("Command failed to run: {e}");
|
2023-08-18 14:06:20 +00:00
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
}
|